|
| 1 | +# README for Swaddle |
| 2 | + |
| 3 | +**note** |
| 4 | +**right now this has only been tested with firefox, not sure how well it will work with chrome based browsers at this time** |
| 5 | +## Overview |
| 6 | + |
| 7 | +The main function of this project is to keep swayWM from going into an idle state when watching Youtube videos. This Rust project includes a D-Bus Runner (`DBusRunner`) and an Idle Application (`IdleApp`). It is designed to interface with D-Bus for message handling, particularly for managing media playback statuses, and to execute commands based on these statuses. |
| 8 | + |
| 9 | +### DBusRunner |
| 10 | + |
| 11 | +`DBusRunner` is responsible for creating a D-Bus session and setting up message match rules for listening to specific D-Bus signals. It plays a critical role in responding to changes in media playback status. |
| 12 | + |
| 13 | +### IdleApp |
| 14 | + |
| 15 | +`IdleApp` utilizes `DBusRunner` to monitor playback status and controls system behavior (like inhibiting system idle actions) based on the playback state. It represents the core logic of the application, managing state and triggering commands as necessary. |
| 16 | + |
| 17 | +## Features |
| 18 | + |
| 19 | +- **D-Bus Interaction:** Listen to D-Bus signals and react to changes in media playback status. |
| 20 | +- **Command Execution:** Based on the playback status, execute system commands, specifically using `systemd-inhibit` to control system idle behavior. |
| 21 | +- **Concurrency and Synchronization:** Manage shared state and handle concurrency using Rust's `Arc` and `Mutex`. |
| 22 | + |
| 23 | +## Dependencies |
| 24 | + |
| 25 | +- `dbus`: For interfacing with the D-Bus. |
| 26 | +- `std`: Standard library, particularly for error handling, synchronization primitives, and process management. |
| 27 | + |
| 28 | +## Setup and Running |
| 29 | + |
| 30 | +1. Ensure Rust and Cargo are installed. |
| 31 | +2. Clone the repository. |
| 32 | +3. Run the application using Cargo: |
| 33 | + |
| 34 | + ```bash |
| 35 | + cargo run |
| 36 | + ``` |
| 37 | + |
| 38 | +## Testing |
| 39 | + |
| 40 | +The project includes unit tests for both `DBusRunner` and `IdleApp`. To run these tests, use: |
| 41 | + |
| 42 | +```bash |
| 43 | +cargo test |
| 44 | +``` |
| 45 | + |
| 46 | +### DBusRunner Tests |
| 47 | + |
| 48 | +- **Initialization Test:** Ensures that a new `DBusRunner` instance is correctly initialized. |
| 49 | +- **Add Match Test:** Tests the ability to add a match rule to the D-Bus connection. |
| 50 | + |
| 51 | +### IdleApp Tests |
| 52 | + |
| 53 | +- **Initialization Test:** Confirms that `IdleApp` initializes correctly with the given inhibit duration. |
| 54 | + |
| 55 | +### CommandCaller Tests |
| 56 | + |
| 57 | +- **Mock Implementation:** A mock implementation of `CommandCaller` is provided for testing command execution. |
| 58 | + |
| 59 | +## Architecture |
| 60 | + |
| 61 | +- **Traits (`DBusInterface`, `CommandCaller`):** Define the contract for D-Bus interactions and command execution. |
| 62 | +- **Structs (`DBusRunner`, `IdleApp`):** Implement the application logic, managing D-Bus sessions, and reacting to playback status. |
| 63 | + |
| 64 | +## Error Handling |
| 65 | + |
| 66 | +Errors are managed using Rust's standard `Result` and `Error` types, ensuring robust and clear error handling throughout the application. |
| 67 | + |
| 68 | +## Future Enhancements |
| 69 | + |
| 70 | +- Extend the command execution capabilities based on additional playback statuses or other D-Bus signals. |
| 71 | +- Integrate with more complex system behaviors or external applications. |
| 72 | +- Improve error handling and logging for better diagnostics and maintenance. |
| 73 | +- Add more unit tests and integration tests |
| 74 | +- Chrome testing / support |
| 75 | +- Make a service / add to AUR |
| 76 | + |
| 77 | +--- |
0 commit comments