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 #endif
AppDefaults.shared.registerDefaults() AppDefaults.shared.registerDefaults()
let isFirstRun = AppDefaults.shared.isFirstRun if AppDefaults.shared.isFirstRun {
if isFirstRun {
os_log(.debug, "Is first run.") os_log(.debug, "Is first run.")
} }
FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage
let localAccount = AccountManager.shared.defaultAccount importFeedsIfNeeded()
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)
}
}
updateSortMenuItems() updateSortMenuItems()
updateGroupByFeedMenuItem() updateGroupByFeedMenuItem()
@ -184,7 +175,7 @@ import Sparkle
mainWindowController.restoreStateFromUserDefaults() mainWindowController.restoreStateFromUserDefaults()
} }
if isFirstRun { if AppDefaults.shared.isFirstRun {
mainWindowController?.window?.center() mainWindowController?.window?.center()
} }

View File

@ -9,6 +9,7 @@
import Foundation import Foundation
import Images import Images
import ParserObjC import ParserObjC
import Account
extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate { extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate {
@ -40,6 +41,27 @@ extension AppDelegate: FaviconDownloaderDelegate, FeedIconDownloaderDelegate {
queueUpdateDockBadge() queueUpdateDockBadge()
#elseif os(iOS) #elseif os(iOS)
UNUserNotificationCenter.current().setBadgeCount(unreadCount) 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 #endif
} }
} }

View File

@ -64,20 +64,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
} }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppDefaults.registerDefaults() AppDefaults.registerDefaults()
if AppDefaults.shared.isFirstRun {
let isFirstRun = AppDefaults.shared.isFirstRun os_log(.debug, "Is first run.")
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 FaviconGenerator.faviconTemplateImage = AppAssets.faviconTemplateImage
importFeedsIfNeeded()
registerBackgroundTasks() registerBackgroundTasks()
CacheCleaner.purgeIfNecessary() CacheCleaner.purgeIfNecessary()
initializeDownloaders() initializeDownloaders()