mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +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, *)
|
@available(iOS 14, *)
|
||||||
struct WidgetDataEncoder {
|
struct WidgetDataEncoder {
|
||||||
|
|
||||||
static let taskIdentifier = "com.ranchero.NetNewsWire.WidgetEncode"
|
|
||||||
|
|
||||||
static func encodeWidgetData() {
|
static func encodeWidgetData() {
|
||||||
os_log(.info, "Starting widget data encoding")
|
os_log(.debug, "Starting encoding widget data.")
|
||||||
do {
|
do {
|
||||||
// Unread Articles
|
// Unread Articles
|
||||||
let unreadArticles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished ?? .distantPast > $1.datePublished ?? .distantPast })
|
let unreadArticles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished ?? .distantPast > $1.datePublished ?? .distantPast })
|
||||||
@ -72,15 +70,18 @@ struct WidgetDataEncoder {
|
|||||||
lastUpdateTime: Date())
|
lastUpdateTime: Date())
|
||||||
|
|
||||||
let encodedData = try JSONEncoder().encode(latestData)
|
let encodedData = try JSONEncoder().encode(latestData)
|
||||||
|
os_log(.debug, "Finished encoding widget data.")
|
||||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||||
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||||
let dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
let dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
||||||
if FileManager.default.fileExists(atPath: dataURL!.path) {
|
if FileManager.default.fileExists(atPath: dataURL!.path) {
|
||||||
try FileManager.default.removeItem(at: dataURL!)
|
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 {
|
} catch {
|
||||||
os_log(.error, "%@", error.localizedDescription)
|
os_log(.error, "%@", error.localizedDescription)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user