feat: Added Minimize to System Tray While Monitor Is Running. Closes #6.

This commit is contained in:
2026-10-09 11:16:32 -04:00
parent cf2cc9f8ed
commit 8f8e77242b
6 changed files with 260 additions and 191 deletions
+61 -1
View File
@@ -3,6 +3,10 @@ mod models;
mod net;
mod scanner;
use tauri::Manager;
use tauri::menu::{Menu, MenuItem};
use tauri::tray::TrayIconBuilder;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tracing_subscriber::fmt()
@@ -13,8 +17,64 @@ pub fn run() {
.init();
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}))
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_notification::init())
.setup(|app| {
let show = MenuItem::with_id(app, "show", "Show Argus", true, None::<&str>)?;
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show, &quit])?;
let _tray = TrayIconBuilder::new()
.icon(app.default_window_icon().unwrap().clone())
.tooltip("Argus - Network Scanner")
.menu(&menu)
.show_menu_on_left_click(false)
.on_menu_event(|app, event| match event.id.as_ref() {
"show" => {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
"quit" => {
app.exit(0);
}
_ => {}
})
.on_tray_icon_event(|tray, event| {
if let tauri::tray::TrayIconEvent::DoubleClick { .. } = event {
if let Some(window) = tray.app_handle().get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app)?;
// Hide to tray when monitor is running
let app_handle = app.handle().clone();
if let Some(window) = app.get_webview_window("main") {
window.on_window_event(move |event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
if commands::monitor::is_monitor_running() {
api.prevent_close();
if let Some(win) = app_handle.get_webview_window("main") {
let _ = win.hide();
}
}
}
});
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::scan::start_scan,
commands::scan::stop_scan,
@@ -37,4 +97,4 @@ pub fn run() {
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}