Skip to content

Commit

Permalink
rewriting swaddle (#3)
Browse files Browse the repository at this point in the history
* rewriting swaddle

* add some zombie checking
  • Loading branch information
ATTron authored Feb 19, 2025
1 parent 0489d55 commit 4903823
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 250 deletions.
67 changes: 37 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default: run_debug

# runs the build release process
build_release:
cargo build --release

# builds a debug version of swaddle
build_debug:
cargo build

# runs swaddle w trace via `cargo run`
run_debug:
RUST_LOG=trace cargo run

# run the release version of swaddle
run_release: build_release
RUST_LOG=info ./target/release/swaddle

# cleans up build artifacts
clean:
cargo clean
93 changes: 35 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,71 @@
# README for Swaddle
# Swaddle

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

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

## Installation

Swaddle can be installed from the AUR:

```sh
yay -S swaddle
paru -S swaddle
```

## Post-Install

To integrate swaddle with Sway/Hyprland, add the following line to your Sway/Hypr configuration:
`exec_always --no-startup-id /usr/local/bin/swaddle &`
Then reload your configuration or restart Sway/Hyprland.

## Overview
### Building from source

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.
* Clone the repo and execute

### DBusRunner

`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.

### IdleApp

`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.

## Features

- **D-Bus Interaction:** Listen to D-Bus signals and react to changes in media playback status.
- **Command Execution:** Based on the playback status, execute system commands, specifically using `systemd-inhibit` to control system idle behavior.
- **Concurrency and Synchronization:** Manage shared state and handle concurrency using Rust's `Arc` and `Mutex`.
```sh
cargo build --release
```

## Dependencies
* You can move the binary into your `$PATH` or run directly

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

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

1. Ensure Rust and Cargo are installed.
2. Clone the repository.
3. Run the application using Cargo:
```sh
RUST_LOG=debug ./target/release/swaddle
```

```bash
cargo run
```
## Post-Install

## Testing
To integrate swaddle with Sway/Hyprland, add the following line to your Sway/Hypr configuration:

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

```bash
cargo test
```conf
# Swaddle configuration
exec_always --no-startup-id /usr/local/bin/swaddle &
```

### DBusRunner Tests
* Hyprland:

- **Initialization Test:** Ensures that a new `DBusRunner` instance is correctly initialized.
- **Add Match Test:** Tests the ability to add a match rule to the D-Bus connection.

### IdleApp Tests

- **Initialization Test:** Confirms that `IdleApp` initializes correctly with the given inhibit duration.
```conf
# Swaddle configuration
exec = /usr/local/bin/swaddle &
```

### CommandCaller Tests
Then reload your configuration or restart Sway/Hyprland.

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

## Architecture
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.

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

## Error Handling
## Dependencies

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

## Future Enhancements

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

---
Loading

0 comments on commit 4903823

Please sign in to comment.