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
No known key found for this signature in database
GPG Key ID: 79BD673276AE83CE
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
}

View File

@ -12,6 +12,7 @@ import RSWeb
import Account
import BackgroundTasks
import os.log
import WidgetKit
var appDelegate: AppDelegate!
@ -115,6 +116,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
syncTimer!.update()
#endif
return true
}
@ -133,11 +135,51 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
shuttingDown = true
}
func refreshWidgetData() {
do {
let articles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished! > $1.datePublished! })
var latest = [LatestArticle]()
for article in articles {
let latestArticle = LatestArticle(feedTitle: article.sortableWebFeedID,
articleTitle: article.title,
articleSummary: article.summary,
feedIcon: article.iconImage()?.image.dataRepresentation(),
pubDate: article.datePublished!.description)
latest.append(latestArticle)
if latest.count == 5 { break }
}
print(latest.map({ $0.pubDate }))
let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
currentTodayCount: SmartFeedsController.shared.todayFeed.unreadCount,
latestArticles: latest,
lastUpdateTime: Date())
print(latestData)
let encodedData = try JSONEncoder().encode(latestData)
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!)
}
try encodedData.write(to: dataURL!)
print(dataURL!.path)
WidgetCenter.shared.reloadAllTimelines()
} catch {
os_log(.error, log: self.log, "%@", error.localizedDescription)
}
}
// MARK: Notifications
@objc func unreadCountDidChange(_ note: Notification) {
if note.object is AccountManager {
unreadCount = AccountManager.shared.unreadCount
refreshWidgetData()
}
}
@ -373,6 +415,7 @@ private extension AppDelegate {
}
AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) { [unowned self] in
if !AccountManager.shared.isSuspended {
self.refreshWidgetData()
self.suspendApplication()
os_log("Account refresh operation completed.", log: self.log, type: .info)
task.setTaskCompleted(success: true)

View File

@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Widget</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>

View File

@ -0,0 +1,76 @@
//
// LatestWidget.swift
// Widget
//
// Created by Stuart Breckenridge on 10/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import WidgetKit
import SwiftUI
struct Provider: TimelineProvider {
public typealias Entry = SimpleEntry
public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
let entry = SimpleEntry(date: entryDate)
entries.append(entry)
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry {
public let date: Date
}
struct PlaceholderView : View {
var body: some View {
Text("Placeholder View")
}
}
struct WidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
Text(entry.date, style: .time)
}
}
@main
struct LatestWidget: Widget {
private let kind: String = "Widget"
public var body: some WidgetConfiguration {
StaticConfiguration(kind: kind,
provider: Provider(),
placeholder: PlaceholderView()) { entry in
WidgetEntryView(entry: entry)
}
.configurationDisplayName("NetNewsWire Now")
.description("This is NetNewsWire.")
.supportedFamilies([.systemSmall, .systemMedium])
}
}
struct Widget_Previews: PreviewProvider {
static var previews: some View {
WidgetEntryView(entry: SimpleEntry(date: Date()))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}

View File

@ -28,6 +28,13 @@
17D5F17124B0BC6700375168 /* SidebarToolbarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */; };
17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */; };
17D5F19524B0C1DD00375168 /* SidebarToolbarModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */; };
17EEA7F524B8926700AAD8BF /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17EEA7F424B8926700AAD8BF /* WidgetKit.framework */; };
17EEA7F724B8926700AAD8BF /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17EEA7F624B8926700AAD8BF /* SwiftUI.framework */; };
17EEA7FA24B8926700AAD8BF /* LatestWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EEA7F924B8926700AAD8BF /* LatestWidget.swift */; };
17EEA7FC24B8926700AAD8BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17EEA7FB24B8926700AAD8BF /* Assets.xcassets */; };
17EEA80024B8926800AAD8BF /* WidgetExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 17EEA7F324B8926700AAD8BF /* WidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
17EEA80624B8996100AAD8BF /* WidgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EEA80524B8996100AAD8BF /* WidgetData.swift */; };
17EEA80724B8996100AAD8BF /* WidgetData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EEA80524B8996100AAD8BF /* WidgetData.swift */; };
3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; };
3B826DCB2385C84800FC1ADB /* AccountsFeedWrangler.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */; };
3B826DCC2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */; };
@ -1090,6 +1097,13 @@
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
17EEA7FE24B8926800AAD8BF /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 849C64581ED37A5D003D8FC0 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 17EEA7F224B8926700AAD8BF;
remoteInfo = WidgetExtension;
};
5102FD7A244008A700534F17 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5102FD72244008A700534F17 /* Secrets.xcodeproj */;
@ -1597,6 +1611,17 @@
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
17EEA80424B8926800AAD8BF /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
17EEA80024B8926800AAD8BF /* WidgetExtension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
513C5CF1232571C2003D4054 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
@ -1792,6 +1817,13 @@
17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineLayoutView.swift; sourceTree = "<group>"; };
17D232A724AFF10A0005F075 /* AddWebFeedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedModel.swift; sourceTree = "<group>"; };
17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModel.swift; sourceTree = "<group>"; };
17EEA7F324B8926700AAD8BF /* WidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
17EEA7F424B8926700AAD8BF /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
17EEA7F624B8926700AAD8BF /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
17EEA7F924B8926700AAD8BF /* LatestWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatestWidget.swift; sourceTree = "<group>"; };
17EEA7FB24B8926700AAD8BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
17EEA7FD24B8926700AAD8BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
17EEA80524B8996100AAD8BF /* WidgetData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetData.swift; sourceTree = "<group>"; };
3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerAccountViewController.swift; sourceTree = "<group>"; };
3B826DB02385C84800FC1ADB /* AccountsFeedWrangler.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsFeedWrangler.xib; sourceTree = "<group>"; };
3B826DCA2385C84800FC1ADB /* AccountsFeedWranglerWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsFeedWranglerWindowController.swift; sourceTree = "<group>"; };
@ -2322,6 +2354,15 @@
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
17EEA7F024B8926700AAD8BF /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
17EEA7F724B8926700AAD8BF /* SwiftUI.framework in Frameworks */,
17EEA7F524B8926700AAD8BF /* WidgetKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
51314634235A7BBE00387FDC /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@ -2531,6 +2572,24 @@
path = Add;
sourceTree = "<group>";
};
17EEA7F824B8926700AAD8BF /* Widget */ = {
isa = PBXGroup;
children = (
17EEA7F924B8926700AAD8BF /* LatestWidget.swift */,
17EEA7FB24B8926700AAD8BF /* Assets.xcassets */,
17EEA7FD24B8926700AAD8BF /* Info.plist */,
);
path = Widget;
sourceTree = "<group>";
};
17EEA80824B8998900AAD8BF /* Widget Data */ = {
isa = PBXGroup;
children = (
17EEA80524B8996100AAD8BF /* WidgetData.swift */,
);
path = "Widget Data";
sourceTree = "<group>";
};
510289CE2451BA1E00426DDF /* Twitter */ = {
isa = PBXGroup;
children = (
@ -2902,6 +2961,7 @@
5177476424B3BDAE00EB0F74 /* AttributedStringView.swift */,
5177470B24B2FF2C00EB0F74 /* Article */,
172199EB24AB228E00A31D04 /* Settings */,
17EEA7F824B8926700AAD8BF /* Widget */,
);
path = iOS;
sourceTree = "<group>";
@ -2938,6 +2998,7 @@
51E499FB24A9135A00B667CB /* Sidebar */,
514E6C0424AD2B0400AC6F6E /* SwiftUI Extensions */,
51919FCB24AB855000541E64 /* Timeline */,
17EEA80824B8998900AAD8BF /* Widget Data */,
);
path = Shared;
sourceTree = "<group>";
@ -3106,6 +3167,8 @@
51E4DAEC2425F6940091EB5B /* CloudKit.framework */,
51E4989624A8065700B667CB /* CloudKit.framework */,
51C452B32265141B00C03939 /* WebKit.framework */,
17EEA7F424B8926700AAD8BF /* WidgetKit.framework */,
17EEA7F624B8926700AAD8BF /* SwiftUI.framework */,
);
name = Frameworks;
sourceTree = "<group>";
@ -3509,6 +3572,7 @@
65ED409D235DEF770081F399 /* Subscribe to Feed.appex */,
51C0513D24A77DF800194D5E /* NetNewsWire.app */,
51C0514424A77DF800194D5E /* NetNewsWire.app */,
17EEA7F324B8926700AAD8BF /* WidgetExtension.appex */,
);
name = Products;
sourceTree = "<group>";
@ -3903,6 +3967,23 @@
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
17EEA7F224B8926700AAD8BF /* WidgetExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 17EEA80124B8926800AAD8BF /* Build configuration list for PBXNativeTarget "WidgetExtension" */;
buildPhases = (
17EEA7EF24B8926700AAD8BF /* Sources */,
17EEA7F024B8926700AAD8BF /* Frameworks */,
17EEA7F124B8926700AAD8BF /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = WidgetExtension;
productName = WidgetExtension;
productReference = 17EEA7F324B8926700AAD8BF /* WidgetExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
51314636235A7BBE00387FDC /* NetNewsWire iOS Intents Extension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 5131463F235A7BBE00387FDC /* Build configuration list for PBXNativeTarget "NetNewsWire iOS Intents Extension" */;
@ -3963,10 +4044,12 @@
51C0513A24A77DF800194D5E /* Frameworks */,
51C0513B24A77DF800194D5E /* Resources */,
51E4989524A8061400B667CB /* Embed Frameworks */,
17EEA80424B8926800AAD8BF /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
17EEA7FF24B8926800AAD8BF /* PBXTargetDependency */,
);
name = "Multiplatform iOS";
productName = iOS;
@ -4145,48 +4228,52 @@
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Ranchero Software";
TargetAttributes = {
17EEA7F224B8926700AAD8BF = {
CreatedOnToolsVersion = 12.0;
ProvisioningStyle = Automatic;
};
51314636235A7BBE00387FDC = {
CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
LastSwiftMigration = 1120;
ProvisioningStyle = Automatic;
};
513C5CE5232571C2003D4054 = {
CreatedOnToolsVersion = 11.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
518B2ED12351B3DD00400001 = {
CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
TestTargetID = 840D617B2029031C009BC708;
};
51C0513C24A77DF800194D5E = {
CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
51C0514324A77DF800194D5E = {
CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
6581C73220CED60000F4AD34 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
65ED3FA2235DEF6C0081F399 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
65ED4090235DEF770081F399 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
840D617B2029031C009BC708 = {
CreatedOnToolsVersion = 9.3;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
@ -4196,7 +4283,7 @@
};
849C645F1ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.HardenedRuntime = {
@ -4206,7 +4293,7 @@
};
849C64701ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
TestTargetID = 849C645F1ED37A5D003D8FC0;
};
@ -4287,6 +4374,7 @@
518B2ED12351B3DD00400001 /* NetNewsWire-iOSTests */,
51C0513C24A77DF800194D5E /* Multiplatform iOS */,
51C0514324A77DF800194D5E /* Multiplatform macOS */,
17EEA7F224B8926700AAD8BF /* WidgetExtension */,
);
};
/* End PBXProject section */
@ -4603,6 +4691,14 @@
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */
17EEA7F124B8926700AAD8BF /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17EEA7FC24B8926700AAD8BF /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
51314635235A7BBE00387FDC /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
@ -4938,6 +5034,15 @@
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
17EEA7EF24B8926700AAD8BF /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17EEA7FA24B8926700AAD8BF /* LatestWidget.swift in Sources */,
17EEA80724B8996100AAD8BF /* WidgetData.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
51314633235A7BBE00387FDC /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@ -4995,6 +5100,7 @@
51E4996A24A8762D00B667CB /* ExtractedArticle.swift in Sources */,
51919FF124AB864A00541E64 /* TimelineModel.swift in Sources */,
51E498F124A8085D00B667CB /* StarredFeedDelegate.swift in Sources */,
17EEA80624B8996100AAD8BF /* WidgetData.swift in Sources */,
51E498FF24A808BB00B667CB /* SingleFaviconDownloader.swift in Sources */,
51E4997224A8784300B667CB /* DefaultFeedsImporter.swift in Sources */,
514E6C0924AD39AD00AC6F6E /* ArticleIconImageLoader.swift in Sources */,
@ -5793,6 +5899,11 @@
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
17EEA7FF24B8926800AAD8BF /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 17EEA7F224B8926700AAD8BF /* WidgetExtension */;
targetProxy = 17EEA7FE24B8926800AAD8BF /* PBXContainerItemProxy */;
};
5131463D235A7BBE00387FDC /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 51314636235A7BBE00387FDC /* NetNewsWire iOS Intents Extension */;
@ -6052,6 +6163,141 @@
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
17EEA80224B8926800AAD8BF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Multiplatform/iOS/Widget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.stuartbreckenridge.NetNewsWire.iOS.Widget;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
17EEA80324B8926800AAD8BF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = Multiplatform/iOS/Widget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.stuartbreckenridge.NetNewsWire.iOS.Widget;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
51314640235A7BBE00387FDC /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 51314617235A797400387FDC /* NetNewsWire_iOSintentextension_target.xcconfig */;
@ -6098,6 +6344,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 51C0519724A7808F00194D5E /* NetNewsWire_multiplatform_iOSapp_target.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
};
name = Debug;
};
@ -6105,6 +6352,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 51C0519724A7808F00194D5E /* NetNewsWire_multiplatform_iOSapp_target.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
};
name = Release;
};
@ -6229,6 +6477,15 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
17EEA80124B8926800AAD8BF /* Build configuration list for PBXNativeTarget "WidgetExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
17EEA80224B8926800AAD8BF /* Debug */,
17EEA80324B8926800AAD8BF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
5131463F235A7BBE00387FDC /* Build configuration list for PBXNativeTarget "NetNewsWire iOS Intents Extension" */ = {
isa = XCConfigurationList;
buildConfigurations = (

44
Technotes/Widget.md Normal file
View File

@ -0,0 +1,44 @@
# Widget
## Supported Widget Styles
The NetNewsWire iOS widget supports the `systemSmall` and `systemMedium` styles.
The `systemSmall` style displays the current Today and Unread counts; `systemMedium` displays the latest two articles along with current
Today and Unread count.
## Passing Data from the App to the Widget
Data is made available to the widget by encoding JSON data and saving it to a file in a directory available to app extensions.
```
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
}
```
## When is JSON Data Saved?
1. On `unreadCountDidChange`
2. After a background refresh
3. When the app enters the background
After JSON data is saved, Widget timelines are reloaded.