143 lines
5.0 KiB
Rust
143 lines
5.0 KiB
Rust
mod commands;
|
|
mod models;
|
|
mod net;
|
|
mod scanner;
|
|
|
|
use tauri::menu::{Menu, MenuItem};
|
|
use tauri::tray::TrayIconBuilder;
|
|
use tauri::Manager;
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
#[cfg(target_os = "windows")]
|
|
fn register_aumid() {
|
|
let app_id = "io.argus.app";
|
|
let key_path = format!("HKCU\\Software\\Classes\\AppUserModelId\\{}", app_id);
|
|
|
|
// Check if already registered
|
|
let check = std::process::Command::new("reg")
|
|
.args(["query", &key_path])
|
|
.output();
|
|
|
|
if let Ok(o) = check {
|
|
if o.status.success() {
|
|
tracing::debug!("AUMID already registered");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Not registered, create it
|
|
let output = std::process::Command::new("reg")
|
|
.args([
|
|
"add",
|
|
&key_path,
|
|
"/v", "DisplayName",
|
|
"/t", "REG_SZ",
|
|
"/d", "Argus",
|
|
"/f",
|
|
])
|
|
.output();
|
|
|
|
match output {
|
|
Ok(o) if o.status.success() => {
|
|
tracing::debug!("AUMID registered successfully");
|
|
}
|
|
Ok(o) => {
|
|
tracing::warn!("AUMID registration failed: {}", String::from_utf8_lossy(&o.stderr));
|
|
}
|
|
Err(e) => {
|
|
tracing::warn!("Failed to run reg command: {}", e);
|
|
}
|
|
}
|
|
}
|
|
pub fn run() {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "argus=debug".into()),
|
|
)
|
|
.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])?;
|
|
#[cfg(target_os = "windows")]
|
|
std::thread::spawn(|| register_aumid());
|
|
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,
|
|
commands::export::export_csv,
|
|
commands::actions::launch_url,
|
|
commands::traceroute::run_traceroute,
|
|
commands::nmap::run_nmap,
|
|
commands::nmap::stop_nmap,
|
|
commands::monitor::monitor_add_hosts,
|
|
commands::monitor::monitor_remove_host,
|
|
commands::monitor::monitor_clear,
|
|
commands::monitor::monitor_get_entries,
|
|
commands::monitor::monitor_start,
|
|
commands::monitor::monitor_stop,
|
|
commands::updater::check_for_update,
|
|
commands::actions::check_privileges,
|
|
commands::changelog::get_changelog,
|
|
commands::monitor::monitor_update_label,
|
|
commands::monitor::monitor_resolve_host
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|