Confirm power and logout actions in centered system modals
This commit is contained in:
1 parent
4ca3a59cb7
commit
d8a23748c8
14 files changed
+673
-49
No files matched your search
@@ -254,13 +254,17 @@ pub fn available(program: &str) -> bool {
|
||||
}
|
||||
|
||||
fn run(program: &str, args: &[&str]) -> Result<String, String> {
|
||||
run_with_timeout(program, args, "2s")
|
||||
}
|
||||
|
||||
fn run_with_timeout(program: &str, args: &[&str], timeout: &str) -> Result<String, String> {
|
||||
if !available(program) {
|
||||
return Err(format!("{program} is not installed"));
|
||||
}
|
||||
|
||||
// Coreutils timeout bounds disconnected D-Bus services, too. Never invoke a shell.
|
||||
let output = Command::new("timeout")
|
||||
.args(["--kill-after=1s", "2s", program])
|
||||
.args(["--kill-after=1s", timeout, program])
|
||||
.args(args)
|
||||
.env("LC_ALL", "C")
|
||||
.stdin(Stdio::null())
|
||||
@@ -519,6 +523,16 @@ fn notifications(bus: &mut StatusBus) -> Option<Notifications> {
|
||||
Some(Notifications { count, dnd })
|
||||
}
|
||||
|
||||
pub(super) fn execute_power(action: Action) -> Result<(), String> {
|
||||
let action = match action {
|
||||
Action::Poweroff => "poweroff",
|
||||
Action::Reboot => "reboot",
|
||||
Action::Suspend => "suspend",
|
||||
_ => return Err("Invalid power action".to_owned()),
|
||||
};
|
||||
run_with_timeout("systemctl", &[action], "120s").map(|_| ())
|
||||
}
|
||||
|
||||
fn execute(action: &Action, settings: Option<&[String]>) -> Result<(), String> {
|
||||
match action {
|
||||
Action::Wifi(on) => run("nmcli", &["radio", "wifi", if *on { "on" } else { "off" }]),
|
||||
|
||||
Reference in new issue
Block a user