diff --git a/Cargo.lock b/Cargo.lock index 1f116f737..a0bcb6ede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2744,30 +2744,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" -[[package]] -name = "libappindicator" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2d3cb96d092b4824cb306c9e544c856a4cb6210c1081945187f7f1924b47e8" -dependencies = [ - "glib", - "gtk", - "gtk-sys", - "libappindicator-sys", - "log", -] - -[[package]] -name = "libappindicator-sys" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1b3b6681973cea8cc3bce7391e6d7d5502720b80a581c9a95c9cbaf592826aa" -dependencies = [ - "gtk-sys", - "libloading", - "once_cell", -] - [[package]] name = "libc" version = "0.2.153" @@ -2788,16 +2764,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - [[package]] name = "libm" version = "0.2.7" @@ -5374,7 +5340,6 @@ dependencies = [ "core-foundation", "core-graphics", "crossbeam-channel", - "dirs-next", "dispatch", "gdk", "gdk-pixbuf", @@ -5389,7 +5354,6 @@ dependencies = [ "instant", "jni", "lazy_static", - "libappindicator", "libc", "log", "ndk", diff --git a/gitbutler-app/Cargo.toml b/gitbutler-app/Cargo.toml index a0f7baa70..8bc08d09b 100644 --- a/gitbutler-app/Cargo.toml +++ b/gitbutler-app/Cargo.toml @@ -65,7 +65,7 @@ similar = { version = "2.4.0", features = ["unicode"] } slug = "0.1.5" ssh-key = { version = "0.6.4", features = [ "alloc", "ed25519" ] } ssh2 = { version = "0.9.4", features = ["vendored-openssl"] } -tauri = { version = "1.5.4", features = ["dialog-open", "fs-read-file", "path-all", "process-relaunch", "protocol-asset", "shell-open", "system-tray", "window-maximize", "window-start-dragging", "window-unmaximize"] } +tauri = { version = "1.5.4", features = ["dialog-open", "fs-read-file", "path-all", "process-relaunch", "protocol-asset", "shell-open", "window-maximize", "window-start-dragging", "window-unmaximize"] } tauri-plugin-context-menu = { git = "https://github.com/c2r0b/tauri-plugin-context-menu", branch = "main" } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } diff --git a/gitbutler-app/src/bin.rs b/gitbutler-app/src/bin.rs index fbcb9603c..073fa8f7b 100644 --- a/gitbutler-app/src/bin.rs +++ b/gitbutler-app/src/bin.rs @@ -20,43 +20,8 @@ fn main() { .unwrap() .block_on(async { tauri::async_runtime::set(tokio::runtime::Handle::current()); - let app_title = tauri_context.package_info().name.clone(); - - let quit = tauri::CustomMenuItem::new("quit".to_string(), "Quit"); - let hide = - tauri::CustomMenuItem::new("toggle".to_string(), format!("Hide {}", app_title)); - let tray_menu = tauri::SystemTrayMenu::new().add_item(hide).add_item(quit); - let tray = tauri::SystemTray::new().with_menu(tray_menu); tauri::Builder::default() - .system_tray(tray) - .on_system_tray_event(|app_handle, event| { - if let tauri::SystemTrayEvent::MenuItemClick { id, .. } = event { - let app_title = app_handle.package_info().name.clone(); - let item_handle = app_handle.tray_handle().get_item(&id); - match id.as_str() { - "quit" => { - tracing::info!("Quitting app"); - app_handle.exit(0); - } - "toggle" => { - if let Some(window) = get_window(app_handle) { - if window.is_visible().unwrap() { - hide_window(app_handle).expect("Failed to hide window"); - } else { - show_window(app_handle).expect("Failed to show window"); - } - } else { - create_window(app_handle).expect("Failed to create window"); - item_handle - .set_title(format!("Hide {}", app_title)) - .unwrap(); - } - } - _ => {} - } - } - }) .on_window_event(|event| { if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() { hide_window(&event.window().app_handle()).expect("Failed to hide window"); @@ -226,32 +191,15 @@ fn main() { .on_menu_event(|event|menu::handle_event(&event)) .build(tauri_context) .expect("Failed to build tauri app") - .run(|app_handle, event| match event { - tauri::RunEvent::WindowEvent { - event: tauri::WindowEvent::Focused(is_focused), - .. - } => { - if is_focused { - set_toggle_menu_hide(app_handle) - .expect("Failed to set toggle menu hide"); - } else { - set_toggle_menu_show(app_handle) - .expect("Failed to set toggle menu show"); - } - } - tauri::RunEvent::ExitRequested { api, .. } => { + .run(|app_handle, event| { + if let tauri::RunEvent::ExitRequested { api, .. } = event { hide_window(app_handle).expect("Failed to hide window"); api.prevent_exit(); } - _ => {} }); }); } -fn get_window(handle: &tauri::AppHandle) -> Option { - handle.get_window("main") -} - #[cfg(not(target_os = "macos"))] fn create_window(handle: &tauri::AppHandle) -> tauri::Result { let app_title = handle.package_info().name.clone(); @@ -283,39 +231,7 @@ fn create_window(handle: &tauri::AppHandle) -> tauri::Result { Ok(window) } -fn set_toggle_menu_hide(handle: &tauri::AppHandle) -> tauri::Result<()> { - handle - .tray_handle() - .get_item("toggle") - .set_title(format!("Hide {}", handle.package_info().name)) -} - -fn show_window(handle: &tauri::AppHandle) -> tauri::Result<()> { - set_toggle_menu_hide(handle)?; - - #[cfg(target_os = "macos")] - handle.show()?; - - if let Some(window) = get_window(handle) { - window.set_focus()?; - - #[cfg(not(target_os = "macos"))] - window.show()?; - } - - Ok(()) -} - -fn set_toggle_menu_show(handle: &tauri::AppHandle) -> tauri::Result<()> { - handle - .tray_handle() - .get_item("toggle") - .set_title(format!("Show {}", handle.package_info().name)) -} - fn hide_window(handle: &tauri::AppHandle) -> tauri::Result<()> { - set_toggle_menu_show(handle)?; - #[cfg(target_os = "macos")] handle.hide()?; @@ -326,3 +242,8 @@ fn hide_window(handle: &tauri::AppHandle) -> tauri::Result<()> { Ok(()) } + +#[cfg(not(target_os = "macos"))] +fn get_window(handle: &tauri::AppHandle) -> Option { + handle.get_window("main") +} diff --git a/gitbutler-app/tauri.conf.json b/gitbutler-app/tauri.conf.json index 18f8b6e3c..f080b35b8 100644 --- a/gitbutler-app/tauri.conf.json +++ b/gitbutler-app/tauri.conf.json @@ -59,10 +59,6 @@ "script-src": "'self' https://eu.posthog.com", "style-src": "'self' 'unsafe-inline'" } - }, - "systemTray": { - "iconPath": "icons/tray.png", - "iconAsTemplate": true } } }