add basic error handling to sdu power
This commit is contained in:
parent
5c40ab7fb9
commit
416ee4b5d3
2 changed files with 10 additions and 7 deletions
|
|
@ -17,7 +17,7 @@ use xdg::BaseDirectories;
|
|||
|
||||
use crate::{
|
||||
config::LockConf,
|
||||
lib::{DirectoryType, SDUError, sway_ipc::get_sway_connection},
|
||||
lib::{DirectoryType, SDUError, run_sway_command, sway_ipc::get_sway_connection},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
@ -133,12 +133,7 @@ pub fn lock_screen(lock_config: LockConf, force_bg_render: bool) -> Result<(), S
|
|||
}
|
||||
debug!("{}", gtklock_command);
|
||||
|
||||
match sway_connection.run_command(gtklock_command) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(SDUError {
|
||||
message: "Could not lock screen!".to_owned(),
|
||||
}),
|
||||
}
|
||||
run_sway_command(&mut sway_connection, gtklock_command)
|
||||
}
|
||||
None => Err(SDUError {
|
||||
message: "Wallpaper path is not set!".to_owned(),
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ pub fn power_fn(
|
|||
power_command_arg: &Option<PowerCommand>,
|
||||
lock_config: LockConf,
|
||||
) -> Result<(), SDUError> {
|
||||
debug!("running power function");
|
||||
match power_command_arg {
|
||||
Some(power_command) => {
|
||||
debug!("Some power command exists!");
|
||||
let action_prompt = match power_command {
|
||||
PowerCommand::Shutdown => vec!["shut down", "poweroff.target"],
|
||||
PowerCommand::Reboot => vec!["restart", "reboot.target"],
|
||||
|
|
@ -24,6 +26,7 @@ pub fn power_fn(
|
|||
PowerCommand::Logout => vec!["log out"],
|
||||
};
|
||||
let action = action_prompt.first().unwrap_or(&"not found");
|
||||
|
||||
if let Ok(dialog::Choice::Yes) =
|
||||
dialog::Question::new(format!("Are you sure you would like to {}?", action))
|
||||
.title(format!("Confirm {}...", action))
|
||||
|
|
@ -66,10 +69,15 @@ pub fn power_fn(
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(SDUError {
|
||||
message: "unapproved (or dialog backend is not available)".to_string(),
|
||||
});
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
None => {
|
||||
debug!("No power command exists!");
|
||||
println!("⏻ Shutdown\n Reboot\n Suspend\n Lock\n Logout");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue