Undo system tray and single instance (#312)
* Revert5872ab9* Undo095b8fc
This commit is contained in:
@@ -3,10 +3,8 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use tauri::Manager;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod menu;
|
||||
mod tray;
|
||||
|
||||
fn main() {
|
||||
let builder = tauri::Builder::default();
|
||||
@@ -14,38 +12,7 @@ fn main() {
|
||||
#[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);
|
||||
|
||||
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!())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(run_event_handler)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user