timeline refresh can now be controlled

This commit is contained in:
Stuart Breckenridge 2020-11-30 10:08:23 +08:00
parent f51e1b511e
commit d9c39a6964
No known key found for this signature in database
GPG Key ID: 1F11FD62007DC331
2 changed files with 6 additions and 3 deletions

View File

@ -18,7 +18,7 @@ struct WidgetDataEncoder {
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application") private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
static func encodeWidgetData() { static func encodeWidgetData(refreshTimeline: Bool = true) {
os_log(.debug, log: log, "Starting encoding widget data.") os_log(.debug, log: log, "Starting encoding widget data.")
do { do {
// Unread Articles // Unread Articles
@ -32,6 +32,7 @@ struct WidgetDataEncoder {
feedIcon: article.iconImage()?.image.dataRepresentation(), feedIcon: article.iconImage()?.image.dataRepresentation(),
pubDate: article.datePublished!.description) pubDate: article.datePublished!.description)
unread.append(latestArticle) unread.append(latestArticle)
if unread.count == 7 { break } if unread.count == 7 { break }
} }
@ -82,7 +83,9 @@ struct WidgetDataEncoder {
} }
if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) { if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) {
os_log(.debug, log: log, "Wrote widget data to container.") os_log(.debug, log: log, "Wrote widget data to container.")
WidgetCenter.shared.reloadAllTimelines() if refreshTimeline == true {
WidgetCenter.shared.reloadAllTimelines()
}
} }
} catch { } catch {
os_log(.error, "%@", error.localizedDescription) os_log(.error, "%@", error.localizedDescription)

View File

@ -116,7 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
#endif #endif
if #available(iOS 14, *) { if #available(iOS 14, *) {
WidgetDataEncoder.encodeWidgetData() WidgetDataEncoder.encodeWidgetData(refreshTimeline: false)
} }