mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 20:23:25 +01:00
[AltWidget] Fixes crash when featured app is expired
This commit is contained in:
@@ -113,6 +113,8 @@ struct Provider: IntentTimelineProvider
|
|||||||
let currentDate = Calendar.current.startOfDay(for: Date())
|
let currentDate = Calendar.current.startOfDay(for: Date())
|
||||||
let numberOfDays = snapshot.expirationDate.numberOfCalendarDays(since: currentDate)
|
let numberOfDays = snapshot.expirationDate.numberOfCalendarDays(since: currentDate)
|
||||||
|
|
||||||
|
if numberOfDays >= 0
|
||||||
|
{
|
||||||
for dayOffset in 0 ..< min(numberOfDays, 7)
|
for dayOffset in 0 ..< min(numberOfDays, 7)
|
||||||
{
|
{
|
||||||
guard let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate) else { continue }
|
guard let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate) else { continue }
|
||||||
@@ -122,6 +124,12 @@ struct Provider: IntentTimelineProvider
|
|||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let entry = AppEntry(date: Date(), app: snapshot)
|
||||||
|
entries.append(entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let timeline = Timeline(entries: entries, policy: .atEnd)
|
let timeline = Timeline(entries: entries, policy: .atEnd)
|
||||||
completion(timeline)
|
completion(timeline)
|
||||||
|
|||||||
@@ -45,12 +45,21 @@ struct WidgetView : View
|
|||||||
}
|
}
|
||||||
|
|
||||||
HStack(alignment: .bottom) {
|
HStack(alignment: .bottom) {
|
||||||
|
let expirationText: Text = {
|
||||||
|
switch daysRemaining
|
||||||
|
{
|
||||||
|
case ..<0: return Text("Expired")
|
||||||
|
case 1: return Text("1 day")
|
||||||
|
default: return Text("\(daysRemaining) days")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
(
|
(
|
||||||
Text("Expires in\n")
|
Text("Expires in\n")
|
||||||
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
||||||
.foregroundColor(Color.white.opacity(0.45)) +
|
.foregroundColor(Color.white.opacity(0.45)) +
|
||||||
|
|
||||||
Text(daysRemaining == 1 ? "1 day" : "\(daysRemaining) days")
|
expirationText
|
||||||
.font(.system(size: 15, weight: .semibold, design: .rounded))
|
.font(.system(size: 15, weight: .semibold, design: .rounded))
|
||||||
.foregroundColor(.white)
|
.foregroundColor(.white)
|
||||||
)
|
)
|
||||||
@@ -60,13 +69,17 @@ struct WidgetView : View
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Countdown(startDate: app.refreshedDate, endDate: app.expirationDate)
|
if daysRemaining >= 0
|
||||||
|
{
|
||||||
|
Countdown(startDate: app.refreshedDate,
|
||||||
|
endDate: app.expirationDate)
|
||||||
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
||||||
.foregroundColor(Color.white)
|
.foregroundColor(Color.white)
|
||||||
.opacity(0.8)
|
.opacity(0.8)
|
||||||
.fixedSize(horizontal: true, vertical: false)
|
.fixedSize(horizontal: true, vertical: false)
|
||||||
.offset(x: 5)
|
.offset(x: 5)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.offset(y: 5) // Offset so we don't affect layout, but still leave space between app name and Countdown.
|
.offset(y: 5) // Offset so we don't affect layout, but still leave space between app name and Countdown.
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
|||||||
Reference in New Issue
Block a user