Skip to content

Commit

Permalink
✨ 主窗口退出时子窗口自动关闭
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Sep 23, 2023
1 parent e72c4da commit c05d359
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit c05d359

Please sign in to comment.