Merge pull request #717 from kiwix/699-double-clicking-a-zim-opens-multiple-windows

699 double clicking a zim opens multiple windows
This commit is contained in:
Kelson 2024-03-31 09:16:38 +02:00 committed by GitHub
commit 13d18dd0f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -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 {

View File

@ -79,7 +79,9 @@ struct OpenFileHandler: ViewModifier {
openedZimFileIDs.forEach { fileID in
guard let url = ZimFileService.shared.getMainPageURL(zimFileID: fileID) else { return }
#if os(macOS)
NSWorkspace.shared.open(url)
if .command == context {
NotificationCenter.openURL(url, inNewTab: true)
}
#elseif os(iOS)
NotificationCenter.openURL(url, inNewTab: true)
#endif