mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2026-06-22 04:11:37 +10:00
feat: Add "NO_TRAY_ICON" env option
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
+36
-21
@@ -330,23 +330,25 @@ pub fn run() {
|
|||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
TrayIconBuilder::new()
|
run_on_tray(|| {
|
||||||
.icon(app.default_window_icon().unwrap().clone())
|
TrayIconBuilder::new()
|
||||||
.menu(&menu)
|
.icon(app.default_window_icon().unwrap().clone())
|
||||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
.menu(&menu)
|
||||||
"open" => {
|
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||||
app.webview_windows().get("main").unwrap().show().unwrap();
|
"open" => {
|
||||||
}
|
app.webview_windows().get("main").unwrap().show().unwrap();
|
||||||
"quit" => {
|
}
|
||||||
cleanup_and_exit(app, &app.state());
|
"quit" => {
|
||||||
}
|
cleanup_and_exit(app, &app.state());
|
||||||
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
warn!("menu event not handled: {:?}", event.id);
|
warn!("menu event not handled: {:?}", event.id);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build(app)
|
.build(app)
|
||||||
.expect("error while setting up tray menu");
|
.expect("error while setting up tray menu");
|
||||||
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut db_handle = borrow_db_mut_checked();
|
let mut db_handle = borrow_db_mut_checked();
|
||||||
@@ -393,8 +395,10 @@ pub fn run() {
|
|||||||
})
|
})
|
||||||
.on_window_event(|window, event| {
|
.on_window_event(|window, event| {
|
||||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||||
window.hide().unwrap();
|
run_on_tray(|| {
|
||||||
api.prevent_close();
|
window.hide().unwrap();
|
||||||
|
api.prevent_close();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
@@ -402,9 +406,20 @@ pub fn run() {
|
|||||||
|
|
||||||
app.run(|_app_handle, event| {
|
app.run(|_app_handle, event| {
|
||||||
if let RunEvent::ExitRequested { code, api, .. } = event {
|
if let RunEvent::ExitRequested { code, api, .. } = event {
|
||||||
if code.is_none() {
|
run_on_tray(|| {
|
||||||
api.prevent_exit();
|
if code.is_none() {
|
||||||
}
|
api.prevent_exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_on_tray<T: FnOnce() -> ()>(f: T) {
|
||||||
|
if match std::env::var("NO_TRAY_ICON") {
|
||||||
|
Ok(s) => s.to_lowercase() != "true",
|
||||||
|
Err(_) => true,
|
||||||
|
} {
|
||||||
|
(f)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user