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:
7 files changed
+143
-132
No files matched your search
+11
-6
@@ -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"),
|
||||
|
||||
Reference in new issue
Block a user