mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 08:42:51 +00:00
Suspend feed refreshing when Mac is asleep.
This commit is contained in:
1 parent
98b05ca283
commit
09ce634d4e
2 files changed
+31
-2
No files matched your search
+12
-2
@@ -116,6 +116,7 @@ let appName = "NetNewsWire"
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(inspectableObjectsDidChange(_:)), name: .InspectableObjectsDidChange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(importDownloadedTheme(_:)), name: .didEndDownloadingTheme, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeImportError(_:)), name: .didFailToImportThemeWithError, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(willSleepNotification(_:)), name: NSWorkspace.willSleepNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(didWakeNotification(_:)), name: NSWorkspace.didWakeNotification, object: nil)
|
||||
}
|
||||
|
||||
@@ -381,9 +382,18 @@ let appName = "NetNewsWire"
|
||||
updateDockBadge()
|
||||
}
|
||||
|
||||
@objc func willSleepNotification(_ note: Notification) {
|
||||
// Pause feed refreshing while the Mac is asleep. Article status syncing is
|
||||
// left running on purpose.
|
||||
Task { @MainActor in
|
||||
refreshTimer?.suspend()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func didWakeNotification(_ note: Notification) {
|
||||
MainActor.assumeIsolated {
|
||||
fireOldTimers()
|
||||
Task { @MainActor in
|
||||
refreshTimer?.resume()
|
||||
ArticleStatusSyncTimer.shared.fireOldTimer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import Account
|
||||
private var internalTimer: Timer?
|
||||
private var lastTimedRefresh: Date?
|
||||
private let launchTime = Date()
|
||||
private var suspendedFireDate: Date?
|
||||
|
||||
func fireOldTimer() {
|
||||
if let timer = internalTimer {
|
||||
@@ -37,6 +38,24 @@ import Account
|
||||
internalTimer = nil
|
||||
}
|
||||
|
||||
func suspend() {
|
||||
suspendedFireDate = internalTimer?.fireDate
|
||||
invalidate()
|
||||
}
|
||||
|
||||
func resume() {
|
||||
guard !shuttingDown else {
|
||||
return
|
||||
}
|
||||
let dueDate = suspendedFireDate
|
||||
suspendedFireDate = nil
|
||||
if let dueDate, dueDate < Date() {
|
||||
timedRefresh(nil)
|
||||
} else {
|
||||
update()
|
||||
}
|
||||
}
|
||||
|
||||
func update() {
|
||||
guard !shuttingDown else {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user