mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
28
Multiplatform/Shared/Widget Data/WidgetData.swift
Normal file
28
Multiplatform/Shared/Widget Data/WidgetData.swift
Normal 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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user