-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsystem_integration.rs
More file actions
42 lines (37 loc) · 1.26 KB
/
system_integration.rs
File metadata and controls
42 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::platform::SystemIntegration;
use std::process::Command;
pub struct MacosSystemIntegration;
impl SystemIntegration for MacosSystemIntegration {
fn show_dialog(message: &str, title: &str) -> Result<(), Box<dyn std::error::Error>> {
Command::new("osascript")
.arg("-e")
.arg(&format!(
r#"display dialog "{}" with title "{}" buttons {{"OK"}} default button "OK""#,
message.replace("\\", "\\\\").replace("\"", "\\\""),
title.replace("\\", "\\\\").replace("\"", "\\\"")
))
.spawn()?;
Ok(())
}
fn open_system_monitor() -> Result<(), Box<dyn std::error::Error>> {
Command::new("open")
.arg("-a")
.arg("Activity Monitor")
.spawn()?;
Ok(())
}
fn get_local_hour() -> u32 {
let output = Command::new("date")
.arg("+%H")
.output()
.unwrap_or_else(|_| std::process::Output {
status: std::process::ExitStatus::default(),
stdout: b"0".to_vec(),
stderr: Vec::new(),
});
String::from_utf8_lossy(&output.stdout)
.trim()
.parse()
.unwrap_or(0)
}
}