+2
-1
src-tauri/capabilities/default.json
+2
-1
src-tauri/capabilities/default.json
+25
-4
src-tauri/src/lib.rs
+25
-4
src-tauri/src/lib.rs
···
1
-
use tauri::{Emitter, Manager};
1
+
use tauri::{
2
+
tray::{MouseButton, MouseButtonState, TrayIconEvent},
3
+
Emitter, Manager,
4
+
};
2
5
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
3
6
use tauri_plugin_deep_link::DeepLinkExt;
4
7
5
8
mod background;
6
9
mod tray;
7
10
use background::{start_background_scheduler, stop_background_scheduler};
8
-
use tray::{create_system_tray};
11
+
use tray::create_system_tray;
9
12
10
13
#[tauri::command]
11
14
fn greet(name: &str) -> String {
···
50
53
app.emit("perform-backup", ()).unwrap();
51
54
}
52
55
_ => {
53
-
println!("menu item {:?} not handled", event.id);
56
+
println!("menu item {:?} not handled", event.id);
54
57
}
55
-
})
58
+
})
59
+
.on_tray_icon_event(|tray, event| match event {
60
+
TrayIconEvent::Click {
61
+
button: MouseButton::Left,
62
+
button_state: MouseButtonState::Up,
63
+
..
64
+
} => {
65
+
println!("left click pressed and released");
66
+
// in this example, let's show and focus the main window when the tray is clicked
67
+
let app = tray.app_handle();
68
+
if let Some(window) = app.get_webview_window("main") {
69
+
let _ = window.show();
70
+
let _ = window.set_focus();
71
+
}
72
+
}
73
+
_ => {
74
+
println!("unhandled event {event:?}");
75
+
}
76
+
})
56
77
.setup(|app| {
57
78
#[cfg(any(windows, target_os = "linux"))]
58
79
{
+4
-7
src-tauri/src/tray.rs
+4
-7
src-tauri/src/tray.rs
···
9
9
let hide_i = MenuItem::with_id(app, "hide", "Hide", true, None::<&str>)?;
10
10
let backup_now_i = MenuItem::with_id(app, "backup_now", "Backup Now", true, None::<&str>)?;
11
11
12
-
let menu = Menu::with_items(app, &[
13
-
&quit_i,
14
-
&show_i,
15
-
&hide_i,
16
-
&backup_now_i,
17
-
])?;
12
+
let menu = Menu::with_items(app, &[&quit_i, &show_i, &backup_now_i])?;
18
13
19
14
TrayIconBuilder::new()
20
15
.menu(&menu)
21
-
.menu_on_left_click(true)
16
+
.show_menu_on_left_click(false)
22
17
.icon(app.default_window_icon().unwrap().clone())
18
+
.title("ATBackup")
19
+
.tooltip("ATBackup")
23
20
.build(app)
24
21
}
-4
src-tauri/tauri.conf.json
-4
src-tauri/tauri.conf.json
+2
-2
src/App.tsx
+2
-2
src/App.tsx
···
172
172
return (
173
173
<main className="bg-background dark min-h-screen flex flex-col">
174
174
<div className="titlebar" data-tauri-drag-region>
175
-
<div className="controls">
175
+
<div className="controls pr-[4px]">
176
176
<Button
177
177
variant="ghost"
178
178
id="titlebar-minimize"
···
210
210
id="titlebar-close"
211
211
title="close"
212
212
onClick={() => {
213
-
appWindow.close();
213
+
appWindow.hide();
214
214
}}
215
215
>
216
216
<svg
-6
src/routes/Home.tsx
-6
src/routes/Home.tsx
···
321
321
{getRelativeTime(new Date(backup.timestamp))} (
322
322
{new Date(backup.timestamp).toLocaleString()})
323
323
</span>
324
-
<span>•</span>
325
-
<span>{formatBytes(backup.stats?.fileSize || 0)}</span>
326
-
<span>•</span>
327
-
<span className="font-semibold text-white/90">
328
-
{backup.stats?.collections.length || 0} collections
329
-
</span>
330
324
</div>
331
325
</div>
332
326
<div