mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltWidget] Fixes crash when featured app is expired
This commit is contained in:
@@ -113,12 +113,20 @@ struct Provider: IntentTimelineProvider
|
||||
let currentDate = Calendar.current.startOfDay(for: Date())
|
||||
let numberOfDays = snapshot.expirationDate.numberOfCalendarDays(since: currentDate)
|
||||
|
||||
for dayOffset in 0 ..< min(numberOfDays, 7)
|
||||
if numberOfDays >= 0
|
||||
{
|
||||
guard let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate) else { continue }
|
||||
|
||||
let score = Float(dayOffset + 1) / Float(numberOfDays)
|
||||
let entry = AppEntry(date: entryDate, relevance: TimelineEntryRelevance(score: score), app: snapshot)
|
||||
for dayOffset in 0 ..< min(numberOfDays, 7)
|
||||
{
|
||||
guard let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate) else { continue }
|
||||
|
||||
let score = Float(dayOffset + 1) / Float(numberOfDays)
|
||||
let entry = AppEntry(date: entryDate, relevance: TimelineEntryRelevance(score: score), app: snapshot)
|
||||
entries.append(entry)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
let entry = AppEntry(date: Date(), app: snapshot)
|
||||
entries.append(entry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +45,21 @@ struct WidgetView : View
|
||||
}
|
||||
|
||||
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")
|
||||
.font(.system(size: 13, weight: .semibold, design: .rounded))
|
||||
.foregroundColor(Color.white.opacity(0.45)) +
|
||||
|
||||
Text(daysRemaining == 1 ? "1 day" : "\(daysRemaining) days")
|
||||
expirationText
|
||||
.font(.system(size: 15, weight: .semibold, design: .rounded))
|
||||
.foregroundColor(.white)
|
||||
)
|
||||
@@ -60,12 +69,16 @@ struct WidgetView : View
|
||||
|
||||
Spacer()
|
||||
|
||||
Countdown(startDate: app.refreshedDate, endDate: app.expirationDate)
|
||||
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
||||
.foregroundColor(Color.white)
|
||||
.opacity(0.8)
|
||||
.fixedSize(horizontal: true, vertical: false)
|
||||
.offset(x: 5)
|
||||
if daysRemaining >= 0
|
||||
{
|
||||
Countdown(startDate: app.refreshedDate,
|
||||
endDate: app.expirationDate)
|
||||
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
||||
.foregroundColor(Color.white)
|
||||
.opacity(0.8)
|
||||
.fixedSize(horizontal: true, vertical: false)
|
||||
.offset(x: 5)
|
||||
}
|
||||
}
|
||||
.offset(y: 5) // Offset so we don't affect layout, but still leave space between app name and Countdown.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user