Blog

tauri で system tray アプリなどで、ウィンドウを閉じたら終了されてしまうとき

https://tauri.app/v1/guides/features/system-tray/

tauri で system tray app を作っていて、設定画面を作った。設定画面を閉じたらアプリが終了する怪現象が発生した。

SystemTray周りのドキュメントを読んだら、普通に解決策が書いてあった。

tauri::Builder::default()
  .build(tauri::generate_context!())
  .expect("error while building tauri application")
  .run(|_app_handle, event| match event {
    tauri::RunEvent::ExitRequested { api, .. } => {
      api.prevent_exit();
    }
    _ => {}
  });