Only send statuses on quit and have a 2 second timeout. Fixes #2726
This commit is contained in:
parent
de93658fc2
commit
6b0bdf8ca0
|
@ -431,6 +431,17 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
delegate.refreshAll(for: self, completion: completion)
|
delegate.refreshAll(for: self, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func sendArticleStatus(completion: ((Result<Void, Error>) -> Void)? = nil) {
|
||||||
|
delegate.sendArticleStatus(for: self) { result in
|
||||||
|
switch result {
|
||||||
|
case .success:
|
||||||
|
completion?(.success(()))
|
||||||
|
case .failure(let error):
|
||||||
|
completion?(.failure(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func syncArticleStatus(completion: ((Result<Void, Error>) -> Void)? = nil) {
|
public func syncArticleStatus(completion: ((Result<Void, Error>) -> Void)? = nil) {
|
||||||
delegate.sendArticleStatus(for: self) { [unowned self] result in
|
delegate.sendArticleStatus(for: self) { [unowned self] result in
|
||||||
switch result {
|
switch result {
|
||||||
|
|
|
@ -293,6 +293,21 @@ public final class AccountManager: UnreadCountProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func sendArticleStatusAll(completion: (() -> Void)? = nil) {
|
||||||
|
let group = DispatchGroup()
|
||||||
|
|
||||||
|
activeAccounts.forEach {
|
||||||
|
group.enter()
|
||||||
|
$0.sendArticleStatus() { _ in
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group.notify(queue: DispatchQueue.global(qos: .background)) {
|
||||||
|
completion?()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func syncArticleStatusAll(completion: (() -> Void)? = nil) {
|
public func syncArticleStatusAll(completion: (() -> Void)? = nil) {
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
|
|
||||||
|
|
|
@ -313,11 +313,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
|
||||||
shuttingDown = true
|
shuttingDown = true
|
||||||
saveState()
|
saveState()
|
||||||
|
|
||||||
AccountManager.shared.syncArticleStatusAll() {
|
AccountManager.shared.sendArticleStatusAll() {
|
||||||
self.isShutDownSyncDone = true
|
self.isShutDownSyncDone = true
|
||||||
}
|
}
|
||||||
|
|
||||||
while !isShutDownSyncDone && RunLoop.current.run(mode: .default, before: .distantFuture) { }
|
let timeout = Date().addingTimeInterval(2)
|
||||||
|
while !isShutDownSyncDone && RunLoop.current.run(mode: .default, before: .distantFuture) && timeout > Date() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Notifications
|
// MARK: Notifications
|
||||||
|
|
Loading…
Reference in New Issue