Removes print statements and reorgs code
This commit is contained in:
parent
1cc5f3cc30
commit
9991b3760e
@ -179,7 +179,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
if note.object is AccountManager {
|
||||
unreadCount = AccountManager.shared.unreadCount
|
||||
WidgetDataEncoder.encodeWidgetData()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,16 +12,12 @@ struct WidgetDataDecoder {
|
||||
|
||||
static func decodeWidgetData() throws -> WidgetData {
|
||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
print(appGroup)
|
||||
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||
let dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
||||
print("decoder path: \(dataURL!.path)")
|
||||
|
||||
if FileManager.default.fileExists(atPath: dataURL!.path) {
|
||||
let decodedWidgetData = try JSONDecoder().decode(WidgetData.self, from: Data(contentsOf: dataURL!))
|
||||
return decodedWidgetData
|
||||
} else {
|
||||
print("No data at location")
|
||||
return WidgetData(currentUnreadCount: 0, currentTodayCount: 0, latestArticles: [], lastUpdateTime: Date())
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import os.log
|
||||
struct WidgetDataEncoder {
|
||||
|
||||
static func encodeWidgetData() {
|
||||
os_log(.info, "Starting Widget data refresh")
|
||||
os_log(.info, "Starting widget data encoding")
|
||||
do {
|
||||
let articles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished! > $1.datePublished! })
|
||||
var latest = [LatestArticle]()
|
||||
@ -34,17 +34,15 @@ struct WidgetDataEncoder {
|
||||
|
||||
let encodedData = try JSONEncoder().encode(latestData)
|
||||
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||
print(appGroup)
|
||||
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
|
||||
let dataURL = containerURL?.appendingPathComponent("widget-data.json")
|
||||
print("Encoder path: \(dataURL!.path)")
|
||||
if FileManager.default.fileExists(atPath: dataURL!.path) {
|
||||
try FileManager.default.removeItem(at: dataURL!)
|
||||
}
|
||||
try encodedData.write(to: dataURL!)
|
||||
|
||||
WidgetCenter.shared.reloadAllTimelines()
|
||||
os_log(.info, "Finished data refresh")
|
||||
os_log(.info, "Finished encoding widget data")
|
||||
} catch {
|
||||
os_log(.error, "%@", error.localizedDescription)
|
||||
}
|
@ -2974,6 +2974,7 @@
|
||||
5177470B24B2FF2C00EB0F74 /* Article */,
|
||||
172199EB24AB228E00A31D04 /* Settings */,
|
||||
17EEA7F824B8926700AAD8BF /* Widget */,
|
||||
17EEA80824B8998900AAD8BF /* Widget Data */,
|
||||
);
|
||||
path = iOS;
|
||||
sourceTree = "<group>";
|
||||
@ -3010,7 +3011,6 @@
|
||||
51E499FB24A9135A00B667CB /* Sidebar */,
|
||||
514E6C0424AD2B0400AC6F6E /* SwiftUI Extensions */,
|
||||
51919FCB24AB855000541E64 /* Timeline */,
|
||||
17EEA80824B8998900AAD8BF /* Widget Data */,
|
||||
);
|
||||
path = Shared;
|
||||
sourceTree = "<group>";
|
||||
|
Loading…
x
Reference in New Issue
Block a user