Write widget data when article status changes happen. Fixes #3567

This commit is contained in:
Maurice Parker
2022-07-28 17:15:36 -05:00
parent 7683a96de0
commit 141ed4f915
3 changed files with 37 additions and 25 deletions

View File

@@ -45,6 +45,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var webFeedIconDownloader: WebFeedIconDownloader!
var extensionContainersFile: ExtensionContainersFile!
var extensionFeedAddRequestFile: ExtensionFeedAddRequestFile!
var widgetDataEncoder: WidgetDataEncoder!
var unreadCount = 0 {
didSet {
@@ -114,6 +115,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
extensionContainersFile = ExtensionContainersFile()
extensionFeedAddRequestFile = ExtensionFeedAddRequestFile()
widgetDataEncoder = WidgetDataEncoder()
syncTimer = ArticleStatusSyncTimer()
#if DEBUG
@@ -172,6 +175,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
func prepareAccountsForBackground() {
extensionFeedAddRequestFile.suspend()
widgetDataEncoder.encodeIfNecessary()
syncTimer?.invalidate()
scheduleBackgroundFeedRefresh()
syncArticleStatus()
@@ -398,9 +402,6 @@ private extension AppDelegate {
}
AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) { [unowned self] in
if !AccountManager.shared.isSuspended {
if #available(iOS 14, *) {
try? WidgetDataEncoder.shared.encodeWidgetData()
}
self.suspendApplication()
os_log("Account refresh operation completed.", log: self.log, type: .info)
task.setTaskCompleted(success: true)
@@ -445,9 +446,6 @@ private extension AppDelegate {
self.prepareAccountsForBackground()
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
if #available(iOS 14, *) {
try? WidgetDataEncoder.shared.encodeWidgetData()
}
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
@@ -474,9 +472,6 @@ private extension AppDelegate {
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
if #available(iOS 14, *) {
try? WidgetDataEncoder.shared.encodeWidgetData()
}
self?.prepareAccountsForBackground()
self?.suspendApplication()
}

View File

@@ -66,9 +66,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
func sceneDidEnterBackground(_ scene: UIScene) {
if #available(iOS 14, *) {
try? WidgetDataEncoder.shared.encodeWidgetData()
}
ArticleStringFormatter.emptyCaches()
appDelegate.prepareAccountsForBackground()
}