Versão 0.5.0: bancos SQLite, saúde do disco, notificações, retomada, mapa GPS, inglês
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4bb2397e3b
commit
bbcb42ae6e
27 files changed
+2681
-41
No files matched your search
@@ -0,0 +1,74 @@
|
||||
//! Notificações do sistema (varredura concluída, disco desconectado...), usando os
|
||||
//! comandos nativos de cada sistema, sem dependências extras.
|
||||
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
/// Envia uma notificação sem bloquear. Falhas são ignoradas (é só um aviso).
|
||||
pub fn send(title: &str, body: &str) {
|
||||
let (title, body) = (title.to_string(), body.to_string());
|
||||
std::thread::spawn(move || {
|
||||
if let Some(mut c) = command(&title, &body) {
|
||||
if let Ok(mut child) = c
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn command(title: &str, body: &str) -> Option<Command> {
|
||||
// Como root, notifica na sessão do usuário real.
|
||||
let mut c = if let Some(u) = crate::owner::invoking_user() {
|
||||
let mut c = Command::new("runuser");
|
||||
c.args(["-u", &u.name, "--", "env"]);
|
||||
for k in ["DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY"] {
|
||||
if let Ok(v) = std::env::var(k) {
|
||||
c.arg(format!("{k}={v}"));
|
||||
}
|
||||
}
|
||||
c.arg(format!("XDG_RUNTIME_DIR=/run/user/{}", u.uid));
|
||||
c.arg(format!(
|
||||
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/{}/bus",
|
||||
u.uid
|
||||
));
|
||||
c.arg("notify-send");
|
||||
c
|
||||
} else {
|
||||
Command::new("notify-send")
|
||||
};
|
||||
c.args(["-a", "Guará", "-i", "drive-harddisk", title, body]);
|
||||
Some(c)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn command(title: &str, body: &str) -> Option<Command> {
|
||||
let esc = |s: &str| s.replace('\\', "\\\\").replace('"', "\\\"");
|
||||
let mut c = Command::new("osascript");
|
||||
c.args([
|
||||
"-e",
|
||||
&format!(
|
||||
"display notification \"{}\" with title \"{}\"",
|
||||
esc(body),
|
||||
esc(title)
|
||||
),
|
||||
]);
|
||||
Some(c)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn command(title: &str, body: &str) -> Option<Command> {
|
||||
let esc = |s: &str| s.replace('\'', "''");
|
||||
let script = format!(
|
||||
"Add-Type -AssemblyName System.Windows.Forms; Add-Type -AssemblyName System.Drawing; $n = New-Object System.Windows.Forms.NotifyIcon; $n.Icon = [System.Drawing.SystemIcons]::Information; $n.Visible = $true; $n.ShowBalloonTip(6000, '{}', '{}', [System.Windows.Forms.ToolTipIcon]::None); Start-Sleep -Seconds 7; $n.Dispose()",
|
||||
esc(title),
|
||||
esc(body)
|
||||
);
|
||||
let mut c = Command::new("powershell");
|
||||
c.args(["-NoProfile", "-WindowStyle", "Hidden", "-Command", &script]);
|
||||
Some(c)
|
||||
}
|
||||
Reference in new issue
Block a user