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:
Or install the published crate from crates.io:
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.
Logging
The daemon logs at info by default.
You can adjust verbosity from the CLI:
-venablesdebug-vvenablestrace-qreduces logging towarn-qqreduces logging toerror
If RUST_LOG is set, it takes precedence over the CLI verbosity flags.
Install As A systemd User Service
Use the built-in installer command:
If you installed it with cargo install --path ., run:
This stops power-profile-watcher.service first if it is active, 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
Use the built-in verification command:
If you installed it with cargo install --path ., run:
This checks that:
~/.config/systemd/user/power-profile-watcher.serviceexists- the
ExecStartbinary referenced by the installed service exists - the service is enabled and active in the user systemd manager
Normal daemon startup separately verifies that UPower and power-profiles-daemon are reachable over D-Bus before it begins watching for power-source changes.
Watch service logs:
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:
Running install-service multiple times is safe. If the service is active, it stops it first, rewrites the unit file, reloads the user systemd manager, and runs systemctl --user enable --now power-profile-watcher.service again so the updated binary starts immediately. If you run it from a different binary path, it updates ExecStart to point at that binary.
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.