Revert "Potential fix for #3200"
This commit is contained in:
parent
c82678644c
commit
5b00484792
|
@ -30,14 +30,12 @@ public final class WidgetDataEncoder {
|
||||||
|
|
||||||
@available(iOS 14, *)
|
@available(iOS 14, *)
|
||||||
func encodeWidgetData() throws {
|
func encodeWidgetData() throws {
|
||||||
|
|
||||||
os_log(.debug, log: log, "Starting encoding widget data.")
|
os_log(.debug, log: log, "Starting encoding widget data.")
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
do {
|
do {
|
||||||
let unreadArticles = Array(try AccountManager.shared.fetchArticles(.unread(self.fetchLimit))).sortedByDate(.orderedDescending)
|
let unreadArticles = Array(try AccountManager.shared.fetchArticles(.unread(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
let starredArticles = Array(try AccountManager.shared.fetchArticles(.starred(self.fetchLimit))).sortedByDate(.orderedDescending)
|
let starredArticles = Array(try AccountManager.shared.fetchArticles(.starred(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
let todayArticles = Array(try AccountManager.shared.fetchArticles(.today(self.fetchLimit))).sortedByDate(.orderedDescending)
|
let todayArticles = Array(try AccountManager.shared.fetchArticles(.today(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
|
|
||||||
var unread = [LatestArticle]()
|
var unread = [LatestArticle]()
|
||||||
var today = [LatestArticle]()
|
var today = [LatestArticle]()
|
||||||
|
@ -82,7 +80,15 @@ public final class WidgetDataEncoder {
|
||||||
lastUpdateTime: Date())
|
lastUpdateTime: Date())
|
||||||
|
|
||||||
|
|
||||||
let encodedData = try JSONEncoder().encode(latestData)
|
DispatchQueue.global().async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
|
||||||
|
self.backgroundTaskID = UIApplication.shared.beginBackgroundTask (withName: "com.ranchero.NetNewsWire.Encode") {
|
||||||
|
UIApplication.shared.endBackgroundTask(self.backgroundTaskID!)
|
||||||
|
self.backgroundTaskID = .invalid
|
||||||
|
}
|
||||||
|
let encodedData = try? JSONEncoder().encode(latestData)
|
||||||
|
|
||||||
os_log(.debug, log: self.log, "Finished encoding widget data.")
|
os_log(.debug, log: self.log, "Finished encoding widget data.")
|
||||||
|
|
||||||
if self.fileExists() {
|
if self.fileExists() {
|
||||||
|
@ -92,9 +98,13 @@ public final class WidgetDataEncoder {
|
||||||
if FileManager.default.createFile(atPath: self.dataURL!.path, contents: encodedData, attributes: nil) {
|
if FileManager.default.createFile(atPath: self.dataURL!.path, contents: encodedData, attributes: nil) {
|
||||||
os_log(.debug, log: self.log, "Wrote widget data to container.")
|
os_log(.debug, log: self.log, "Wrote widget data to container.")
|
||||||
WidgetCenter.shared.reloadAllTimelines()
|
WidgetCenter.shared.reloadAllTimelines()
|
||||||
|
UIApplication.shared.endBackgroundTask(self.backgroundTaskID!)
|
||||||
|
self.backgroundTaskID = .invalid
|
||||||
|
} else {
|
||||||
|
UIApplication.shared.endBackgroundTask(self.backgroundTaskID!)
|
||||||
|
self.backgroundTaskID = .invalid
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
print(error.localizedDescription)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue