From 89a967106d60dfd09516938e60bb0a5312d2e2df Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 7 Jul 2024 16:59:54 -0700 Subject: [PATCH] Create importFeedsIfNeeded shared AppDelegate method. --- Mac/AppDelegate.swift | 15 +++------------ Shared/AppDelegate+Shared.swift | 22 ++++++++++++++++++++++ iOS/AppDelegate.swift | 16 ++++++---------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 0cf5fdab1..00cae5fed 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -160,22 +160,13 @@ import Sparkle #endif AppDefaults.shared.registerDefaults() - let isFirstRun = AppDefaults.shared.isFirstRun - if isFirstRun { + if AppDefaults.shared.isFirstRun { os_log(.debug, "Is first run.") } FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage - let localAccount = AccountManager.shared.defaultAccount - - if isFirstRun && !AccountManager.shared.anyAccountHasAtLeastOneFeed() { - // Import feeds. Either old NNW 3 feeds or the default feeds. - if !NNW3ImportController.importSubscriptionsIfFileExists(account: localAccount) { - DefaultFeedsImporter.importDefaultFeeds(account: localAccount) - } - } - + importFeedsIfNeeded() updateSortMenuItems() updateGroupByFeedMenuItem() @@ -184,7 +175,7 @@ import Sparkle mainWindowController.restoreStateFromUserDefaults() } - if isFirstRun { + if AppDefaults.shared.isFirstRun { mainWindowController?.window?.center() } diff --git a/Shared/AppDelegate+Shared.swift b/Shared/AppDelegate+Shared.swift index b309bc654..626ff7f2e 100644 --- a/Shared/AppDelegate+Shared.swift +++ b/Shared/AppDelegate+Shared.swift @@ -9,6 +9,7 @@ import Foundation import Images import ParserObjC +import Account extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate { @@ -40,6 +41,27 @@ extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate { queueUpdateDockBadge() #elseif os(iOS) UNUserNotificationCenter.current().setBadgeCount(unreadCount) +#endif + } + + func importFeedsIfNeeded() { + + guard AppDefaults.shared.isFirstRun else { + return + } + guard !AccountManager.shared.anyAccountHasAtLeastOneFeed() else { + return + } + + let localAccount = AccountManager.shared.defaultAccount + +#if os(macOS) + // Import feeds. Either old NNW 3 feeds or the default feeds. + if !NNW3ImportController.importSubscriptionsIfFileExists(account: localAccount) { + DefaultFeedsImporter.importDefaultFeeds(account: localAccount) + } +#elseif os(iOS) + DefaultFeedsImporter.importDefaultFeeds(account: localAccount) #endif } } diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index b0e3521c1..943f21e1e 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -64,20 +64,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + AppDefaults.registerDefaults() + if AppDefaults.shared.isFirstRun { + os_log(.debug, "Is first run.") + } - let isFirstRun = AppDefaults.shared.isFirstRun - if isFirstRun { - os_log("Is first run.", log: log, type: .info) - } - - if isFirstRun && !AccountManager.shared.anyAccountHasAtLeastOneFeed() { - let localAccount = AccountManager.shared.defaultAccount - DefaultFeedsImporter.importDefaultFeeds(account: localAccount) - } - FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage + importFeedsIfNeeded() + registerBackgroundTasks() CacheCleaner.purgeIfNecessary() initializeDownloaders()