mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
feat(core): allow listening to event loop events & prevent window close (#2131)
This commit is contained in:
committed by
GitHub
parent
d69b1cf6d7
commit
8157a68af1
@@ -16,7 +16,8 @@ mod menu;
|
||||
|
||||
use serde::Serialize;
|
||||
use tauri::{
|
||||
CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, WindowBuilder, WindowUrl,
|
||||
CustomMenuItem, Event, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, WindowBuilder,
|
||||
WindowUrl,
|
||||
};
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -98,6 +99,13 @@ fn main() {
|
||||
cmd::perform_request,
|
||||
menu_toggle,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(|app_handle, e| {
|
||||
if let Event::CloseRequested { label, api, .. } = e {
|
||||
api.prevent_close();
|
||||
let window = app_handle.get_window(&label).unwrap();
|
||||
window.emit("close-requested", ()).unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user