mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Create ArticleStatusSyncTimer.shared.
This commit is contained in:
@@ -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 {
|
||||
// It’s possible there’s 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]? {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user