power-profile-watcher
power-profile-watcher is a small Rust daemon that watches UPower for AC/battery changes and updates power-profiles-daemon automatically:
- AC power:
performance - Battery power:
power-saver
It does an initial sync on startup and then only changes profiles when the power source changes. Manual profile changes still work normally until the next plug/unplug event.
Requirements
This program requires these services to be present and running:
org.freedesktop.UPowernet.hadess.PowerProfiles
On this machine, those are provided by:
upowerpower-profiles-daemon
You can verify availability with:
Build
From the project directory:
The compiled binary will be:
target/release/power-profile-watcher
Install Binary
Build the binary in this repository:
Or install it into your Cargo bin directory:
The service installer command uses the path of the currently running executable, so it works both when you run the binary from target/release/ and when you run the cargo install copy from ~/.cargo/bin/.
Run Manually
You can test it directly before creating a service:
You should see log lines when it starts and when it changes profiles.
Stop it with Ctrl+C.
If you installed it with cargo install --path ., run power-profile-watcher instead.
Install As A systemd User Service
Use the built-in installer command:
If you installed it with cargo install --path ., run:
This writes ~/.config/systemd/user/power-profile-watcher.service, reloads the user manager, and runs systemctl --user enable --now power-profile-watcher.service.
The generated unit sets Environment=RUST_LOG=info, so it emits normal log output by default.
Verify
Check service status:
Watch service logs:
Check the current active profile:
Then test the actual behavior:
- Plug in AC power and confirm the profile becomes
performance. - Unplug AC power and confirm the profile becomes
power-saver. - Manually change the profile in GNOME and confirm it stays changed until the next AC state transition.
Update After Code Changes
After modifying the program:
Uninstall
Remove the user service with the built-in command:
If you installed it with cargo install --path ., run:
This disables the service, removes ~/.config/systemd/user/power-profile-watcher.service, and reloads the user manager.
Notes
- This program is not GNOME-specific. It works anywhere
UPowerandpower-profiles-daemonare available. - It uses direct D-Bus calls instead of spawning
powerprofilesctl. - It is event-driven. It does not poll.