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::{
|
use crate::{
|
||||||
config::LockConf,
|
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)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
@ -133,12 +133,7 @@ pub fn lock_screen(lock_config: LockConf, force_bg_render: bool) -> Result<(), S
|
||||||
}
|
}
|
||||||
debug!("{}", gtklock_command);
|
debug!("{}", gtklock_command);
|
||||||
|
|
||||||
match sway_connection.run_command(gtklock_command) {
|
run_sway_command(&mut sway_connection, gtklock_command)
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err(SDUError {
|
|
||||||
message: "Could not lock screen!".to_owned(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => Err(SDUError {
|
None => Err(SDUError {
|
||||||
message: "Wallpaper path is not set!".to_owned(),
|
message: "Wallpaper path is not set!".to_owned(),
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,10 @@ pub fn power_fn(
|
||||||
power_command_arg: &Option<PowerCommand>,
|
power_command_arg: &Option<PowerCommand>,
|
||||||
lock_config: LockConf,
|
lock_config: LockConf,
|
||||||
) -> Result<(), SDUError> {
|
) -> Result<(), SDUError> {
|
||||||
|
debug!("running power function");
|
||||||
match power_command_arg {
|
match power_command_arg {
|
||||||
Some(power_command) => {
|
Some(power_command) => {
|
||||||
|
debug!("Some power command exists!");
|
||||||
let action_prompt = match power_command {
|
let action_prompt = match power_command {
|
||||||
PowerCommand::Shutdown => vec!["shut down", "poweroff.target"],
|
PowerCommand::Shutdown => vec!["shut down", "poweroff.target"],
|
||||||
PowerCommand::Reboot => vec!["restart", "reboot.target"],
|
PowerCommand::Reboot => vec!["restart", "reboot.target"],
|
||||||
|
|
@ -24,6 +26,7 @@ pub fn power_fn(
|
||||||
PowerCommand::Logout => vec!["log out"],
|
PowerCommand::Logout => vec!["log out"],
|
||||||
};
|
};
|
||||||
let action = action_prompt.first().unwrap_or(&"not found");
|
let action = action_prompt.first().unwrap_or(&"not found");
|
||||||
|
|
||||||
if let Ok(dialog::Choice::Yes) =
|
if let Ok(dialog::Choice::Yes) =
|
||||||
dialog::Question::new(format!("Are you sure you would like to {}?", action))
|
dialog::Question::new(format!("Are you sure you would like to {}?", action))
|
||||||
.title(format!("Confirm {}...", 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
debug!("No power command exists!");
|
||||||
println!("⏻ Shutdown\n Reboot\n Suspend\n Lock\n Logout");
|
println!("⏻ Shutdown\n Reboot\n Suspend\n Lock\n Logout");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue