Skip to content

Commit

Permalink
Clean-up MacOS window closing behaviour code (spacedriveapp#2124)
Browse files Browse the repository at this point in the history
* fix: delete dead/unused file

* refactor: add the window event handler with the rest of them

* refactor: formatting
  • Loading branch information
brxken128 committed Feb 26, 2024
1 parent aa0b4ab commit 2832803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 57 deletions.
44 changes: 0 additions & 44 deletions apps/desktop/src-tauri/src/clear_localstorage.rs

This file was deleted.

25 changes: 12 additions & 13 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use tauri_specta::{collect_events, ts, Event};
use tokio::time::sleep;
use tracing::error;

mod clear_localstorage;
mod file;
mod menu;
mod tauri_plugins;
Expand Down Expand Up @@ -208,18 +207,6 @@ async fn main() -> tauri::Result<()> {
.plugin(sd_server_plugin(node.clone()).await.unwrap()) // TODO: Handle `unwrap`
.manage(node.clone());

// macOS expected behavior is for the app to not exit when the main window is closed.
// Instead, the window is hidden and the dock icon remains so that on user click it should show the window again.
#[cfg(target_os = "macos")]
let app = app.on_window_event(|event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event.event() {
if event.window().label() == "main" {
AppHandle::hide(&event.window().app_handle()).expect("Window should hide on macOS");
api.prevent_close();
}
}
});

let specta_builder = {
let specta_builder = ts::builder()
.events(collect_events![DragAndDropEvent])
Expand Down Expand Up @@ -316,6 +303,18 @@ async fn main() -> tauri::Result<()> {
})
.on_menu_event(menu::handle_menu_event)
.on_window_event(move |event| match event.event() {
// macOS expected behavior is for the app to not exit when the main window is closed.
// Instead, the window is hidden and the dock icon remains so that on user click it should show the window again.
#[cfg(target_os = "macos")]
WindowEvent::CloseRequested { api, .. } => {
// TODO: make this multi-window compatible in the future
event
.window()
.app_handle()
.hide()
.expect("Window should hide on macOS");
api.prevent_close();
}
WindowEvent::FileDrop(drop) => {
let window = event.window();
let mut file_drop_status = file_drop_status
Expand Down

0 comments on commit 2832803

Please sign in to comment.