From 24ad7588e618192d930f4e5a8ff48d76deb07f8d Mon Sep 17 00:00:00 2001 From: Jason Morley Date: Sat, 17 Jul 2021 12:30:32 -0700 Subject: [PATCH] fix: Updates would not be displayed without restarting the app (#136) Two `BookmarksManager` instances were being initialized at app startup; one was being used for display, and the other was processing the updates, meaning that the UI was never notified of the updates. --- core/BookmarksCore/Common/BookmarksManager.swift | 3 +-- macos/Bookmarks/BookmarksApp.swift | 12 ------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/core/BookmarksCore/Common/BookmarksManager.swift b/core/BookmarksCore/Common/BookmarksManager.swift index e935045f..e760612a 100644 --- a/core/BookmarksCore/Common/BookmarksManager.swift +++ b/core/BookmarksCore/Common/BookmarksManager.swift @@ -50,13 +50,12 @@ public class BookmarksManager { thumbnailManager = ThumbnailManager(imageCache: imageCache, downloadManager: downloadManager) updater = Updater(store: store, token: settings.pinboardApiKey) - #if targetEnvironment(macCatalyst) + #if os(macOS) let notificationCenter = NotificationCenter.default notificationCenter.addObserver(self, selector: #selector(nsApplicationDidBecomeActive), name: NSNotification.Name("NSApplicationDidBecomeActiveNotification"), object: nil) #endif - } @objc diff --git a/macos/Bookmarks/BookmarksApp.swift b/macos/Bookmarks/BookmarksApp.swift index 7a3c1ede..4ed4479d 100644 --- a/macos/Bookmarks/BookmarksApp.swift +++ b/macos/Bookmarks/BookmarksApp.swift @@ -23,29 +23,17 @@ import SwiftUI import BookmarksCore -class AppDelegate: NSObject, NSApplicationDelegate { - - var manager = BookmarksManager() - - func applicationDidBecomeActive(_ notification: Notification) { - manager.updater.start() - } -} - @main struct BookmarksApp: App { - @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @Environment(\.manager) var manager: BookmarksManager var body: some Scene { WindowGroup { ContentView(store: manager.store) - .environment(\.manager, appDelegate.manager) } SwiftUI.Settings { SettingsView() - .environment(\.manager, appDelegate.manager) } } }