Files
cinny-desktop/src-tauri/src/main.rs
T

52 lines
1.5 KiB
Rust
Raw Normal View History

2022-04-29 19:52:14 +05:30
#![cfg_attr(
2023-10-21 05:34:32 -05:00
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
2022-04-29 19:52:14 +05:30
)]
2024-06-12 14:44:43 +02:00
use tauri::Manager;
2022-05-16 16:30:01 +05:30
#[cfg(target_os = "macos")]
mod menu;
2023-10-21 05:34:32 -05:00
mod tray;
2022-05-16 16:30:01 +05:30
2022-04-29 19:52:14 +05:30
fn main() {
2023-10-21 05:34:32 -05:00
let builder = tauri::Builder::default();
#[cfg(target_os = "macos")]
let builder = builder.menu(menu::menu());
let builder = builder
.system_tray(tray::system_tray())
.on_system_tray_event(tray::system_tray_handler);
2022-05-16 16:30:01 +05:30
2023-10-21 05:34:32 -05:00
builder
2024-06-12 14:44:43 +02:00
.plugin(tauri_plugin_single_instance::init(|app, _, _| {
let tray_handle = match app.tray_handle_by_id(crate::tray::TRAY_LABEL) {
Some(h) => h,
None => return,
};
let window = app.get_window("main").unwrap();
if !window.is_visible().unwrap() || window.is_minimized().unwrap() {
window.unminimize().unwrap();
window.show().unwrap();
window.set_focus().unwrap();
tray_handle
.get_item("toggle")
.set_title("Hide Cinny")
.unwrap();
}
}))
2023-10-21 05:34:32 -05:00
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(run_event_handler)
}
2022-05-16 16:30:01 +05:30
2023-10-21 05:34:32 -05:00
fn run_event_handler<R: tauri::Runtime>(app: &tauri::AppHandle<R>, event: tauri::RunEvent) {
match event {
tauri::RunEvent::WindowEvent { label, event, .. } => {
tray::window_event_handler(app, &label, &event);
}
_ => {}
}
}