From d9c39a6964763dfeea89f93b67fa33a5ccbf7c92 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Mon, 30 Nov 2020 10:08:23 +0800 Subject: [PATCH] timeline refresh can now be controlled --- Shared/Widget/WidgetDataEncoder.swift | 7 +++++-- iOS/AppDelegate.swift | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Shared/Widget/WidgetDataEncoder.swift b/Shared/Widget/WidgetDataEncoder.swift index f9ace53c9..79fd87d80 100644 --- a/Shared/Widget/WidgetDataEncoder.swift +++ b/Shared/Widget/WidgetDataEncoder.swift @@ -18,7 +18,7 @@ struct WidgetDataEncoder { 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.") do { // Unread Articles @@ -32,6 +32,7 @@ struct WidgetDataEncoder { feedIcon: article.iconImage()?.image.dataRepresentation(), pubDate: article.datePublished!.description) unread.append(latestArticle) + if unread.count == 7 { break } } @@ -82,7 +83,9 @@ struct WidgetDataEncoder { } if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) { os_log(.debug, log: log, "Wrote widget data to container.") - WidgetCenter.shared.reloadAllTimelines() + if refreshTimeline == true { + WidgetCenter.shared.reloadAllTimelines() + } } } catch { os_log(.error, "%@", error.localizedDescription) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 72d25d8de..0716113cf 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -116,7 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD #endif if #available(iOS 14, *) { - WidgetDataEncoder.encodeWidgetData() + WidgetDataEncoder.encodeWidgetData(refreshTimeline: false) }