diff --git a/App/App_macOS.swift b/App/App_macOS.swift index 7b047ece6..a9e9fd0aa 100644 --- a/App/App_macOS.swift +++ b/App/App_macOS.swift @@ -108,7 +108,6 @@ struct RootView: View { private let openURL = NotificationCenter.default.publisher(for: .openURL) private let appTerminates = NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification) private let tabCloses = NotificationCenter.default.publisher(for: NSWindow.willCloseNotification) - private let browserClearModel = BrowserClearViewModel() /// Close other tabs then the ones received private let keepOnlyTabs = NotificationCenter.default.publisher(for: .keepOnlyTabs) diff --git a/ViewModel/BrowserClearViewModel.swift b/ViewModel/BrowserClearViewModel.swift deleted file mode 100644 index 8949c0de9..000000000 --- a/ViewModel/BrowserClearViewModel.swift +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of Kiwix for iOS & macOS. -// -// Kiwix is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// any later version. -// -// Kiwix is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Kiwix; If not, see https://www.gnu.org/licenses/. - -import Foundation -import Combine - -protocol BrowserViewModelClearable { - @MainActor var zimFileId: UUID? { get } - @MainActor func clear() async -} - -#if os(macOS) -/// macOS only! When unlinking / deleting the ZIM file, -/// and .closeZIM was dispatched via NotificationCenter -/// instructs the BrowserViewModel to clear -/// -@MainActor -struct BrowserClearViewModel { - - /// - Parameters: - /// - ids: set of ZIM file ids that are still in use - /// - forBrowser: BrowserViewModel instance - func recievedClearZimFile(notification: Notification, forBrowser browser: BrowserViewModelClearable) { - guard let zimIdToClose = notification.userInfo?["zimId"] as? UUID, - browser.zimFileId == zimIdToClose else { return } - // Using Task to avoid: - // Publishing changes from within view updates is not allowed... - Task { @MainActor in - await browser.clear() - } - } -} -#endif diff --git a/ViewModel/BrowserViewModel.swift b/ViewModel/BrowserViewModel.swift index 76e3b674d..88996b392 100644 --- a/ViewModel/BrowserViewModel.swift +++ b/ViewModel/BrowserViewModel.swift @@ -23,7 +23,7 @@ import CoreKiwix // swiftlint:disable file_length // swiftlint:disable:next type_body_length -final class BrowserViewModel: NSObject, ObservableObject, BrowserViewModelClearable, +final class BrowserViewModel: NSObject, ObservableObject, WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate, NSFetchedResultsControllerDelegate {