Initial widget work

• Latest data is saved out to JSON at various points.
• Technote on widget usage.
• Widget target added.
This commit is contained in:
Stuart Breckenridge
2020-07-10 23:10:12 +08:00
parent 94f956b41f
commit a45ba35b24
11 changed files with 632 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ struct MainApp: App {
#endif
#if os(iOS)
@UIApplicationDelegateAdaptor(AppDelegate.self) private var delegate
@Environment(\.scenePhase) private var scenePhase
#endif
@StateObject private var defaults = AppDefaults.shared
@@ -86,6 +87,11 @@ struct MainApp: App {
SceneNavigationView()
.environmentObject(defaults)
.modifier(PreferredColorSchemeModifier(preferredColorScheme: defaults.userInterfaceColorPalette))
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
print("didEnterBackgroundNotification")
appDelegate.refreshWidgetData()
}
}
.commands {
CommandGroup(after: .newItem, addition: {
@@ -131,6 +137,18 @@ struct MainApp: App {
.keyboardShortcut(.rightArrow, modifiers: [.command])
})
}
.onChange(of: scenePhase, perform: { newPhase in
switch newPhase {
case .active:
print("active")
case .inactive:
print("inactive")
case .background:
print("background")
@unknown default:
print("unknown")
}
})
#endif
}
}

View File

@@ -0,0 +1,28 @@
//
// WidgetData.swift
// NetNewsWire
//
// Created by Stuart Breckenridge on 10/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import Foundation
struct WidgetData: Codable {
let currentUnreadCount: Int
let currentTodayCount: Int
let latestArticles: [LatestArticle]
let lastUpdateTime: Date
}
struct LatestArticle: Codable {
let feedTitle: String
let articleTitle: String?
let articleSummary: String?
let feedIcon: Data? // Base64 encoded image data
let pubDate: String
}