Create importFeedsIfNeeded shared AppDelegate method.

This commit is contained in:
Brent Simmons 2024-07-07 16:59:54 -07:00
parent 44a9a52705
commit 89a967106d
3 changed files with 31 additions and 22 deletions

View File

@ -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()
}

View File

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

View File

@ -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()