mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-25 04:48:16 -04:00
Fix App closing when the last window is closed
This commit is contained in:
parent
e0746fee4b
commit
dc4993ff6e
@ -13,8 +13,15 @@ import Defaults
|
||||
import CoreKiwix
|
||||
|
||||
#if os(macOS)
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
@MainActor func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct Kiwix: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
@StateObject private var libraryRefreshViewModel = LibraryViewModel()
|
||||
private let notificationCenterDelegate = NotificationCenterDelegate()
|
||||
|
||||
@ -171,12 +178,6 @@ struct RootView: View {
|
||||
navigation.currentItem = .reading
|
||||
browser.load(url: url)
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification), perform: { output in
|
||||
guard let window = output.object as? NSWindow else { return }
|
||||
if window.isKeyWindow && window.isMainWindow { // if this is the very last window, close the app
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
})
|
||||
.onReceive(appTerminates) { _ in
|
||||
browser.persistAllTabIdsFromWindows()
|
||||
}.task {
|
||||
|
Loading…
x
Reference in New Issue
Block a user