chore: remove tray menu

This commit is contained in:
Kiril Videlov 2024-02-19 21:41:49 +01:00
parent 1de6683f3b
commit fdac245acd
4 changed files with 8 additions and 127 deletions

36
Cargo.lock generated
View File

@ -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",

View File

@ -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" }

View File

@ -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<tauri::Window> {
handle.get_window("main")
}
#[cfg(not(target_os = "macos"))]
fn create_window(handle: &tauri::AppHandle) -> tauri::Result<tauri::Window> {
let app_title = handle.package_info().name.clone();
@ -283,39 +231,7 @@ fn create_window(handle: &tauri::AppHandle) -> tauri::Result<tauri::Window> {
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<tauri::Window> {
handle.get_window("main")
}

View File

@ -59,10 +59,6 @@
"script-src": "'self' https://eu.posthog.com",
"style-src": "'self' 'unsafe-inline'"
}
},
"systemTray": {
"iconPath": "icons/tray.png",
"iconAsTemplate": true
}
}
}