refactor(src/commands): Refactor battery and touchpad command execution

Refactored command flow to separate daemon invocation, added status handling, and improved error handling.

- New Features: Added `execute_local` helper and `BatteryCommands::Status` handling.
- Enhancements: Simplified daemon checks, removed redundant condition, improved readability and error messages.
- Bug Fixes: Fixed missed daemon return path for status command and ensured proper touchpad inhibition logic.
This commit is contained in:
sankalp committed 2026-03-23 16:16:25 +05:45
1 parent 319ca54300
commit 0dc00ec5c9
7 files changed
+143 -132

No files matched your search

+11 -6
View File
@@ -15,11 +15,6 @@ trait Lapctl {
}
fn try_call_daemon(command: &CoolingCommands) -> bool {
if std::env::var("LAPCTL_DAEMON_INTERNAL").is_ok() {
debug!("Internal daemon call detected. Skipping D-Bus self-call.");
return false;
}
let rt = match tokio::runtime::Runtime::new() {
Ok(rt) => rt,
Err(_) => return false,
@@ -102,11 +97,21 @@ fn set_asus_throttle_policy(mode: &str) -> bool {
}
pub fn execute(command: &CoolingCommands) {
let desc = match command {
CoolingCommands::Performance => "Performance",
CoolingCommands::Balanced => "Balanced",
CoolingCommands::Quiet => "Quiet",
};
println!("Setting thermal/cooling profile to {}", desc);
if try_call_daemon(command) {
println!("Request handled by lapctld daemon.");
return;
}
execute_local(command);
}
pub fn execute_local(command: &CoolingCommands) {
let (ideapad_mode, asus_mode, desc) = match command {
CoolingCommands::Performance => ("1", "1", "Performance"),
CoolingCommands::Balanced => ("0", "0", "Balanced"),