主窗口退出时子窗口自动关闭

This commit is contained in:
BTMuli
2023-09-23 21:31:31 +08:00
parent e72c4dab7f
commit c05d359db4

View File

@@ -29,6 +29,24 @@ async fn register_deep_link(app_handle: tauri::AppHandle) {
fn main() {
tauri_plugin_deep_link::prepare("teyvatguide");
tauri::Builder::default()
.on_window_event(|event| {
match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
api.prevent_close();
let window = event.window().clone();
if window.label() == "TeyvatGuide" {
// 子窗口 label 的数组
const SUB_WINDOW_LABELS: [&str; 2] = ["Sub_window", "Dev_JSON"];
for label in SUB_WINDOW_LABELS.iter() {
let sub = window.get_window(label).unwrap();
sub.close().unwrap();
}
}
window.close().unwrap();
},
_ => {}
}
})
.plugin(tauri_plugin_sql::Builder::default().build())
.invoke_handler(tauri::generate_handler![register_deep_link])
.setup(|_app| {