mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 17:29:23 +00:00
🚑️ Fixes widget crash and alignment issues
This commit is contained in:
9 files changed
+52
-57
No files matched your search
@@ -9,9 +9,10 @@
|
||||
import Foundation
|
||||
|
||||
struct WidgetData: Codable {
|
||||
let currentUnreadCount: Int
|
||||
let currentTodayCount: Int
|
||||
let currentStarredCount: Int
|
||||
let totalUnreadCount: Int
|
||||
let totalTodayCount: Int
|
||||
let totalTodayUnreadCount: Int
|
||||
let totalStarredCount: Int
|
||||
let unreadArticles: [LatestArticle]
|
||||
let starredArticles: [LatestArticle]
|
||||
let todayArticles: [LatestArticle]
|
||||
|
||||
@@ -18,7 +18,7 @@ struct WidgetDataDecoder {
|
||||
let decodedWidgetData = try JSONDecoder().decode(WidgetData.self, from: Data(contentsOf: dataURL!))
|
||||
return decodedWidgetData
|
||||
} else {
|
||||
return WidgetData(currentUnreadCount: 0, currentTodayCount: 0, currentStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date())
|
||||
return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ struct WidgetDataDecoder {
|
||||
let decoded = try JSONDecoder().decode(WidgetData.self, from: data)
|
||||
return decoded
|
||||
} catch {
|
||||
return WidgetData(currentUnreadCount: 0, currentTodayCount: 0, currentStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date())
|
||||
return WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ import Account
|
||||
Self.logger.debug("WidgetDataEncoder: Reloading Unread widget")
|
||||
}
|
||||
|
||||
if existingData.todayArticles != newData.todayArticles {
|
||||
if existingData.todayArticles != newData.todayArticles || existingData.totalTodayUnreadCount != newData.totalTodayUnreadCount {
|
||||
WidgetCenter.shared.reloadTimelines(ofKind: "com.ranchero.NetNewsWire.TodayWidget")
|
||||
shouldRefreshSummary = true
|
||||
Self.logger.debug("WidgetDataEncoder: Reloading Today widget")
|
||||
@@ -126,15 +126,20 @@ import Account
|
||||
let starredArticles = sortedLatestArticles(fetchedStarredArticles)
|
||||
|
||||
let fetchedTodayArticles = try AccountManager.shared.fetchArticles(.today(fetchLimit))
|
||||
let fetchedTodayTotal = try AccountManager.shared.fetchArticles(.today())
|
||||
let fetchedTodayTotalCount = fetchedTodayTotal.count
|
||||
let fetchedTodayUnreadCount = fetchedTodayTotal.filter({ $0.status.read == false }).count
|
||||
let todayArticles = sortedLatestArticles(fetchedTodayArticles)
|
||||
|
||||
let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
|
||||
currentTodayCount: todayArticles.count,
|
||||
currentStarredCount: (try? AccountManager.shared.fetchCountForStarredArticles()) ?? 0,
|
||||
let latestData = WidgetData(totalUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
|
||||
totalTodayCount: fetchedTodayTotalCount,
|
||||
totalTodayUnreadCount: fetchedTodayUnreadCount,
|
||||
totalStarredCount: (try? AccountManager.shared.fetchCountForStarredArticles()) ?? 0,
|
||||
unreadArticles: unreadArticles,
|
||||
starredArticles: starredArticles,
|
||||
todayArticles: todayArticles,
|
||||
lastUpdateTime: Date.now)
|
||||
|
||||
return latestData
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ struct Provider: TimelineProvider {
|
||||
let widgetData = try WidgetDataDecoder.decodeWidgetData()
|
||||
entry = WidgetTimelineEntry(date: date, widgetData: widgetData)
|
||||
} catch {
|
||||
entry = WidgetTimelineEntry(date: date, widgetData: WidgetData(currentUnreadCount: 0, currentTodayCount: 0, currentStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date.now))
|
||||
entry = WidgetTimelineEntry(date: date, widgetData: WidgetData(totalUnreadCount: 0, totalTodayCount: 0, totalTodayUnreadCount: 0, totalStarredCount: 0, unreadArticles: [], starredArticles: [], todayArticles: [], lastUpdateTime: Date.now))
|
||||
}
|
||||
|
||||
let fallback = Calendar.current.date(byAdding: .minute, value: 30, to: Date.now)!
|
||||
|
||||
@@ -19,39 +19,42 @@ struct LockScreenSummaryWidgetView: View {
|
||||
unreadImage
|
||||
Text("label.text.unread", comment: "Unread")
|
||||
Spacer()
|
||||
Text(verbatim: entry.widgetData.currentUnreadCount.formatted())
|
||||
Text(verbatim: entry.widgetData.totalUnreadCount.formatted())
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
HStack(alignment: .center) {
|
||||
todayImage
|
||||
Text("label.text.today", comment: "Today")
|
||||
Spacer()
|
||||
Text(verbatim: entry.widgetData.currentTodayCount.formatted())
|
||||
Text(verbatim: entry.widgetData.totalTodayCount.formatted())
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
HStack(alignment: .center) {
|
||||
starredImage
|
||||
Text("label.text.starred", comment: "Starred")
|
||||
Spacer()
|
||||
Text(verbatim: entry.widgetData.currentStarredCount.formatted())
|
||||
Text(verbatim: entry.widgetData.totalStarredCount.formatted())
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
}
|
||||
.font(.caption)
|
||||
.font(.subheadline)
|
||||
}
|
||||
|
||||
var starredImage: some View {
|
||||
Image(systemName: "star.fill")
|
||||
.resizable()
|
||||
.frame(width: 14, height: 14)
|
||||
}
|
||||
|
||||
var unreadImage: some View {
|
||||
Image(systemName: "largecircle.fill.circle")
|
||||
.resizable()
|
||||
.frame(width: 14, height: 14)
|
||||
}
|
||||
|
||||
var todayImage: some View {
|
||||
Image(systemName: "sun.max.fill")
|
||||
.resizable()
|
||||
.frame(width: 14, height: 14)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ struct StarredWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
|
||||
var body: some View {
|
||||
if entry.widgetData.currentStarredCount == 0 {
|
||||
if entry.widgetData.starredArticles.count == 0 {
|
||||
inboxZero
|
||||
.widgetURL(WidgetDeepLink.starred.url)
|
||||
} else {
|
||||
@@ -33,8 +33,8 @@ struct StarredWidgetView: View {
|
||||
.layoutPriority(1)
|
||||
Spacer()
|
||||
.layoutPriority(0)
|
||||
if entry.widgetData.currentStarredCount - maxCount() > 0 {
|
||||
Text(verbatim: entry.widgetData.currentStarredCount.formatted())
|
||||
if entry.widgetData.totalStarredCount - maxCount() > 0 {
|
||||
Text(verbatim: entry.widgetData.totalStarredCount.formatted())
|
||||
.font(.caption2)
|
||||
.bold()
|
||||
.foregroundColor(.secondary)
|
||||
@@ -47,14 +47,8 @@ struct StarredWidgetView: View {
|
||||
Divider()
|
||||
if entry.widgetData.starredArticles.count > 0 {
|
||||
ForEach(0..<maxCount(), id: \.self, content: { i in
|
||||
if i != 0 {
|
||||
Divider()
|
||||
ArticleItemView(article: entry.widgetData.starredArticles[i],
|
||||
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
|
||||
} else {
|
||||
ArticleItemView(article: entry.widgetData.starredArticles[i],
|
||||
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
|
||||
}
|
||||
ArticleItemView(article: entry.widgetData.starredArticles[i],
|
||||
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
|
||||
})
|
||||
}
|
||||
Spacer()
|
||||
@@ -78,9 +72,9 @@ struct StarredWidgetView: View {
|
||||
}
|
||||
|
||||
if family == .systemLarge {
|
||||
return entry.widgetData.currentStarredCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.currentStarredCount
|
||||
return entry.widgetData.totalStarredCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.totalStarredCount
|
||||
}
|
||||
return entry.widgetData.currentStarredCount >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.currentStarredCount
|
||||
return entry.widgetData.totalStarredCount >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.totalStarredCount
|
||||
}
|
||||
|
||||
var inboxZero: some View {
|
||||
|
||||
@@ -17,7 +17,7 @@ struct TodayWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
|
||||
var body: some View {
|
||||
if entry.widgetData.currentTodayCount == 0 {
|
||||
if entry.widgetData.totalTodayCount == 0 {
|
||||
inboxZero
|
||||
.widgetURL(WidgetDeepLink.today.url)
|
||||
} else {
|
||||
@@ -34,8 +34,8 @@ struct TodayWidgetView: View {
|
||||
.layoutPriority(1)
|
||||
Spacer()
|
||||
.layoutPriority(0)
|
||||
if entry.widgetData.currentTodayCount > 0 {
|
||||
Text(verbatim: entry.widgetData.currentTodayCount.formatted())
|
||||
if entry.widgetData.totalTodayCount > 0 {
|
||||
Text(verbatim: entry.widgetData.totalTodayUnreadCount > 0 ? "\(entry.widgetData.totalTodayCount.formatted()), \(entry.widgetData.totalTodayUnreadCount.formatted()) unread" : entry.widgetData.totalTodayCount.formatted())
|
||||
.font(.caption2)
|
||||
.bold()
|
||||
.foregroundColor(.secondary)
|
||||
@@ -48,14 +48,8 @@ struct TodayWidgetView: View {
|
||||
Divider()
|
||||
if entry.widgetData.todayArticles.count > 0 {
|
||||
ForEach(0..<maxCount(), id: \.self, content: { i in
|
||||
if i != 0 {
|
||||
Divider()
|
||||
ArticleItemView(article: entry.widgetData.todayArticles[i],
|
||||
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
|
||||
} else {
|
||||
ArticleItemView(article: entry.widgetData.todayArticles[i],
|
||||
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
|
||||
}
|
||||
ArticleItemView(article: entry.widgetData.todayArticles[i],
|
||||
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
|
||||
})
|
||||
}
|
||||
Spacer()
|
||||
@@ -79,9 +73,9 @@ struct TodayWidgetView: View {
|
||||
}
|
||||
|
||||
if family == .systemLarge {
|
||||
return entry.widgetData.currentTodayCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.currentTodayCount
|
||||
return entry.widgetData.totalTodayCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.totalTodayCount
|
||||
}
|
||||
return entry.widgetData.todayArticles.count >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.currentTodayCount
|
||||
return entry.widgetData.totalTodayCount >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.totalTodayCount
|
||||
}
|
||||
|
||||
var inboxZero: some View {
|
||||
|
||||
@@ -16,7 +16,7 @@ struct UnreadWidgetView: View {
|
||||
var entry: Provider.Entry
|
||||
|
||||
var body: some View {
|
||||
if entry.widgetData.currentUnreadCount == 0 {
|
||||
if entry.widgetData.totalUnreadCount == 0 {
|
||||
inboxZero
|
||||
.widgetURL(WidgetDeepLink.unread.url)
|
||||
} else {
|
||||
@@ -33,8 +33,8 @@ struct UnreadWidgetView: View {
|
||||
.layoutPriority(1)
|
||||
Spacer()
|
||||
.layoutPriority(0)
|
||||
if entry.widgetData.currentUnreadCount - maxCount() > 0 {
|
||||
Text(verbatim: entry.widgetData.currentUnreadCount.formatted())
|
||||
if entry.widgetData.totalUnreadCount - maxCount() > 0 {
|
||||
Text(verbatim: entry.widgetData.totalUnreadCount.formatted())
|
||||
.font(.caption2)
|
||||
.bold()
|
||||
.foregroundColor(.secondary)
|
||||
@@ -47,14 +47,8 @@ struct UnreadWidgetView: View {
|
||||
Divider()
|
||||
if entry.widgetData.unreadArticles.count > 0 {
|
||||
ForEach(0..<maxCount(), id: \.self, content: { i in
|
||||
if i != 0 {
|
||||
Divider()
|
||||
ArticleItemView(article: entry.widgetData.unreadArticles[i],
|
||||
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
|
||||
} else {
|
||||
ArticleItemView(article: entry.widgetData.unreadArticles[i],
|
||||
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
|
||||
}
|
||||
ArticleItemView(article: entry.widgetData.unreadArticles[i],
|
||||
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
|
||||
})
|
||||
}
|
||||
Spacer()
|
||||
@@ -77,9 +71,9 @@ struct UnreadWidgetView: View {
|
||||
}
|
||||
|
||||
if family == .systemLarge {
|
||||
return entry.widgetData.currentUnreadCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.currentUnreadCount
|
||||
return entry.widgetData.totalUnreadCount >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.totalUnreadCount
|
||||
}
|
||||
return entry.widgetData.currentUnreadCount >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.currentUnreadCount
|
||||
return entry.widgetData.totalUnreadCount >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.totalUnreadCount
|
||||
}
|
||||
|
||||
var inboxZero: some View {
|
||||
|
||||
@@ -18,10 +18,11 @@ struct UnreadWidget: Widget {
|
||||
|
||||
return StaticConfiguration(kind: kind, provider: Provider(), content: { entry in
|
||||
UnreadWidgetView(entry: entry)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.containerBackground(for: .widget) {
|
||||
Color.clear
|
||||
}
|
||||
.clipped()
|
||||
})
|
||||
.configurationDisplayName(Text("label.text.unread", comment: "Unread"))
|
||||
.description(Text("label.text.unread-widget-description", comment: "A description of the Unread widget."))
|
||||
@@ -36,10 +37,11 @@ struct TodayWidget: Widget {
|
||||
|
||||
return StaticConfiguration(kind: kind, provider: Provider(), content: { entry in
|
||||
TodayWidgetView(entry: entry)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.containerBackground(for: .widget) {
|
||||
Color.clear
|
||||
}
|
||||
.clipped()
|
||||
})
|
||||
.configurationDisplayName(Text("label.text.today", comment: "Today"))
|
||||
.description(Text("label.text.today-widget-description", comment: "A description of the Today widget."))
|
||||
@@ -54,10 +56,11 @@ struct StarredWidget: Widget {
|
||||
|
||||
return StaticConfiguration(kind: kind, provider: Provider(), content: { entry in
|
||||
StarredWidgetView(entry: entry)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.containerBackground(for: .widget) {
|
||||
Color.clear
|
||||
}
|
||||
.clipped()
|
||||
})
|
||||
.configurationDisplayName(Text("label.text.starred", comment: "Starred"))
|
||||
.description(Text("label.text.starred-widget-description", comment: "A description of the Starred widget."))
|
||||
@@ -72,10 +75,11 @@ struct LockScreenSummaryWidget: Widget {
|
||||
|
||||
return StaticConfiguration(kind: kind, provider: Provider(), content: { entry in
|
||||
LockScreenSummaryWidgetView(entry: entry)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.containerBackground(for: .widget) {
|
||||
Color.clear
|
||||
}
|
||||
.clipped()
|
||||
})
|
||||
.configurationDisplayName(Text("label.text.lock-screen-summary", comment: "Summary"))
|
||||
.description(Text("label.text.lock-screen-summary-description", comment: "A description of the Lock Screen Summary widget."))
|
||||
|
||||
Reference in new issue
Block a user