Skip to content

Commit 90bece6

Browse files
author
Anthony Templeton
committed
first commit
0 parents  commit 90bece6

File tree

7 files changed

+417
-0
lines changed

7 files changed

+417
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

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

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "swaddle"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
dbus = "0.9.7"

PKGBUILD

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
pkgname=swaddle
2+
pkgver=0.1.0
3+
pkgrel=1
4+
pkgdesc="Swayidle inhibitor when watching content or listening to audio"
5+
arch=('x86_64')
6+
license=('GPL')
7+
depends=('dbus' 'openssl')
8+
makedepends=('cargo' 'rust')
9+
source=("$pkgname-$pkgver.tar.gz::https://github.com/attron/$pkgname/archive/$pkgver.tar.gz"
10+
"$pkgname.service")
11+
sha256sums=('SKIP'
12+
'SKIP')
13+
14+
15+
build() {
16+
cd "$srcdir/$pkgname-$pkgver"
17+
cargo build --release --locked
18+
}
19+
20+
package() {
21+
cd "$srcdir/$pkgname-$pkgver"
22+
install -Dm755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
23+
install -Dm644 "$srcdir/$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service"
24+
}
25+
26+
post_install() {
27+
systemctl daemon-reload
28+
}
29+
30+
post_upgrade() {
31+
post_install
32+
}

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)