mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-23 23:51:06 +01:00
WidgetDataEncoder
Removed unused taskIdentifier Added more logging Switched to FileManager for writing data files
This commit is contained in:
parent
65073d7346
commit
92c3cd52aa
@ -16,10 +16,8 @@ import Articles
|
||||
@available(iOS 14, *)
|
||||
struct WidgetDataEncoder {
|
||||
|
||||
static let taskIdentifier = "com.ranchero.NetNewsWire.WidgetEncode"
|
||||
|
||||
static func encodeWidgetData() {
|
||||
os_log(.info, "Starting widget data encoding")
|
||||
os_log(.debug, "Starting encoding widget data.")
|
||||
do {
|
||||
// Unread Articles
|
||||
let unreadArticles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished ?? .distantPast > $1.datePublished ?? .distantPast })
|
||||
@ -72,15 +70,18 @@ struct WidgetDataEncoder {
|
||||
lastUpdateTime: Date())
|
||||
|
||||
let encodedData = try JSONEncoder().encode(latestData)
|
||||
os_log(.debug, "Finished encoding widget data.")
|
||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||
let dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
||||
if FileManager.default.fileExists(atPath: dataURL!.path) {
|
||||
try FileManager.default.removeItem(at: dataURL!)
|
||||
os_log(.debug, "Removed widget data from container.")
|
||||
}
|
||||
if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) {
|
||||
os_log(.debug, "Wrote widget data to container.")
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
}
|
||||
try encodedData.write(to: dataURL!)
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
os_log(.info, "Finished encoding widget data")
|
||||
} catch {
|
||||
os_log(.error, "%@", error.localizedDescription)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user