Add single-instance tauri plugin (#261)
Co-authored-by: lukas <lukas.walter@aceart.de>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use tauri::Manager;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod menu;
|
||||
mod tray;
|
||||
@@ -17,6 +19,23 @@ fn main() {
|
||||
.on_system_tray_event(tray::system_tray_handler);
|
||||
|
||||
builder
|
||||
.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();
|
||||
}
|
||||
}))
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(run_event_handler)
|
||||
|
||||
Reference in New Issue
Block a user