Create ArticleStatusSyncTimer.shared.

This commit is contained in:
Brent Simmons
2025-02-01 20:03:01 -08:00
parent 3bd8ce573f
commit 69e52dd90a
3 changed files with 19 additions and 24 deletions

View File

@@ -34,13 +34,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
var syncTimer: ArticleStatusSyncTimer?
var lastRefreshInterval = AppDefaults.refreshInterval
var shuttingDown = false {
private var shuttingDown = false {
didSet {
if shuttingDown {
refreshTimer?.shuttingDown = shuttingDown
refreshTimer?.invalidate()
syncTimer?.shuttingDown = shuttingDown
syncTimer?.invalidate()
ArticleStatusSyncTimer.shared.stop()
}
}
}
@@ -201,7 +200,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
extensionFeedAddRequestFile = ExtensionFeedAddRequestFile()
refreshTimer = AccountRefreshTimer()
syncTimer = ArticleStatusSyncTimer()
_ = ArticleStatusSyncTimer.shared
UNUserNotificationCenter.current().requestAuthorization(options: [.badge]) { (_, _) in }
@@ -218,15 +217,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
#if DEBUG
refreshTimer!.update()
syncTimer!.update()
ArticleStatusSyncTimer.shared.update()
#else
if AppDefaults.suppressSyncOnLaunch {
refreshTimer!.update()
syncTimer!.update()
ArticleStatusSyncTimer.shared.update()
} else {
DispatchQueue.main.async {
self.refreshTimer!.timedRefresh(nil)
self.syncTimer!.timedRefresh(nil)
ArticleStatusSyncTimer.shared.timedRefresh(nil)
}
}
#endif
@@ -704,7 +703,7 @@ internal extension AppDelegate {
// Its possible theres a refresh timer set to go off in the past.
// In that case, refresh now and update the timer.
refreshTimer?.fireOldTimer()
syncTimer?.fireOldTimer()
ArticleStatusSyncTimer.shared.fireOldTimer()
}
func objectsForInspector() -> [Any]? {

View File

@@ -11,6 +11,8 @@ import Account
final class ArticleStatusSyncTimer {
static let shared = ArticleStatusSyncTimer()
private static let intervalSeconds = Double(120)
var shuttingDown = false
@@ -27,6 +29,11 @@ final class ArticleStatusSyncTimer {
}
}
func stop() {
shuttingDown = true
invalidate()
}
func invalidate() {
guard let timer = internalTimer else {
return

View File

@@ -23,17 +23,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
private var coordinator: SceneCoordinator?
var syncTimer: ArticleStatusSyncTimer?
private var shuttingDown = false {
didSet {
if shuttingDown {
syncTimer?.shuttingDown = shuttingDown
syncTimer?.invalidate()
}
}
}
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
var userNotificationManager: UserNotificationManager!
@@ -106,10 +95,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
widgetDataEncoder = WidgetDataEncoder()
syncTimer = ArticleStatusSyncTimer()
_ = ArticleStatusSyncTimer.shared
#if DEBUG
syncTimer!.update()
ArticleStatusSyncTimer.shared.update()
#endif
// Create window.
@@ -156,7 +145,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
}
func applicationWillTerminate(_ application: UIApplication) {
shuttingDown = true
ArticleStatusSyncTimer.shared.stop()
}
func applicationDidEnterBackground(_ application: UIApplication) {
@@ -199,7 +188,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
func prepareAccountsForBackground() {
extensionFeedAddRequestFile.suspend()
syncTimer?.invalidate()
ArticleStatusSyncTimer.shared.invalidate()
scheduleBackgroundFeedRefresh()
syncArticleStatus()
widgetDataEncoder.encode()
@@ -208,7 +197,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC
func prepareAccountsForForeground() {
extensionFeedAddRequestFile.resume()
syncTimer?.update()
ArticleStatusSyncTimer.shared.update()
if let lastRefresh = AppDefaults.lastRefresh {
if Date() > lastRefresh.addingTimeInterval(15 * 60) {