Skip to content

Commit 4903823

Browse files
authored
rewriting swaddle (#3)
* rewriting swaddle * add some zombie checking
1 parent 0489d55 commit 4903823

File tree

4 files changed

+248
-250
lines changed

4 files changed

+248
-250
lines changed

Cargo.lock

Lines changed: 37 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Justfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
default: run_debug
2+
3+
# runs the build release process
4+
build_release:
5+
cargo build --release
6+
7+
# builds a debug version of swaddle
8+
build_debug:
9+
cargo build
10+
11+
# runs swaddle w trace via `cargo run`
12+
run_debug:
13+
RUST_LOG=trace cargo run
14+
15+
# run the release version of swaddle
16+
run_release: build_release
17+
RUST_LOG=info ./target/release/swaddle
18+
19+
# cleans up build artifacts
20+
clean:
21+
cargo clean

README.md

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,71 @@
1-
# README for Swaddle
1+
# Swaddle
22

33
Swayidle inhibitor that automatically detects audio / video and will prevent your system from sleeping. No manual intervention needed!
44

55
**note**
6-
**right now this has only been tested with firefox, not sure how well it will work with chrome based browsers at this time**
6+
**right now this has only been tested with zen (firefox) and brave(chrome)**
77

88
## Installation
99

1010
Swaddle can be installed from the AUR:
1111

1212
```sh
13-
yay -S swaddle
13+
paru -S swaddle
1414
```
1515

16-
## Post-Install
17-
18-
To integrate swaddle with Sway/Hyprland, add the following line to your Sway/Hypr configuration:
19-
`exec_always --no-startup-id /usr/local/bin/swaddle &`
20-
Then reload your configuration or restart Sway/Hyprland.
21-
22-
## Overview
16+
### Building from source
2317

24-
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.
18+
* Clone the repo and execute
2519

26-
### DBusRunner
27-
28-
`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.
29-
30-
### IdleApp
31-
32-
`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.
33-
34-
## Features
35-
36-
- **D-Bus Interaction:** Listen to D-Bus signals and react to changes in media playback status.
37-
- **Command Execution:** Based on the playback status, execute system commands, specifically using `systemd-inhibit` to control system idle behavior.
38-
- **Concurrency and Synchronization:** Manage shared state and handle concurrency using Rust's `Arc` and `Mutex`.
20+
```sh
21+
cargo build --release
22+
```
3923

40-
## Dependencies
24+
* You can move the binary into your `$PATH` or run directly
4125

42-
- `dbus`: For interfacing with the D-Bus.
43-
- `std`: Standard library, particularly for error handling, synchronization primitives, and process management.
26+
#### Debugging
4427

45-
## Setup and Running
28+
To get some debugging logging from swaddle you can set the log level to debug and execute
4629

47-
1. Ensure Rust and Cargo are installed.
48-
2. Clone the repository.
49-
3. Run the application using Cargo:
30+
```sh
31+
RUST_LOG=debug ./target/release/swaddle
32+
```
5033

51-
```bash
52-
cargo run
53-
```
34+
## Post-Install
5435

55-
## Testing
36+
To integrate swaddle with Sway/Hyprland, add the following line to your Sway/Hypr configuration:
5637

57-
The project includes unit tests for both `DBusRunner` and `IdleApp`. To run these tests, use:
38+
* Sway:
5839

59-
```bash
60-
cargo test
40+
```conf
41+
# Swaddle configuration
42+
exec_always --no-startup-id /usr/local/bin/swaddle &
6143
```
6244

63-
### DBusRunner Tests
45+
* Hyprland:
6446

65-
- **Initialization Test:** Ensures that a new `DBusRunner` instance is correctly initialized.
66-
- **Add Match Test:** Tests the ability to add a match rule to the D-Bus connection.
67-
68-
### IdleApp Tests
69-
70-
- **Initialization Test:** Confirms that `IdleApp` initializes correctly with the given inhibit duration.
47+
```conf
48+
# Swaddle configuration
49+
exec = /usr/local/bin/swaddle &
50+
```
7151

72-
### CommandCaller Tests
52+
Then reload your configuration or restart Sway/Hyprland.
7353

74-
- **Mock Implementation:** A mock implementation of `CommandCaller` is provided for testing command execution.
54+
## Overview
7555

76-
## Architecture
56+
The main function of this project is to keep any sway based WM from going into an idle state when consuming media. Swaddle will monitor the dbus running daemon and based on values it sees in `Playback Status` will correctly cause idling or inhibition.
7757

78-
- **Traits (`DBusInterface`, `CommandCaller`):** Define the contract for D-Bus interactions and command execution.
79-
- **Structs (`DBusRunner`, `IdleApp`):** Implement the application logic, managing D-Bus sessions, and reacting to playback status.
8058

81-
## Error Handling
59+
## Dependencies
8260

83-
Errors are managed using Rust's standard `Result` and `Error` types, ensuring robust and clear error handling throughout the application.
61+
* `dbus`: For interfacing with the D-Bus.
62+
* `env_logger`: For better log handling
8463

8564
## Future Enhancements
8665

87-
- Extend the command execution capabilities based on additional playback statuses or other D-Bus signals.
88-
- Integrate with more complex system behaviors or external applications.
89-
- Improve error handling and logging for better diagnostics and maintenance.
90-
- Add more unit tests and integration tests
91-
- Chrome testing / support
92-
- Make a service / add to AUR
66+
* Extend the command execution capabilities based on additional playback statuses or other D-Bus signals.
67+
* Integrate with more complex system behaviors or external applications.
68+
* Improve error handling and logging for better diagnostics and maintenance.
69+
* Add unit tests and integration tests
9370

9471
---

0 commit comments

Comments
 (0)