mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 19:53: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 currentDate = Calendar.current.startOfDay(for: Date())
|
||||||
let numberOfDays = snapshot.expirationDate.numberOfCalendarDays(since: currentDate)
|
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 }
|
for dayOffset in 0 ..< min(numberOfDays, 7)
|
||||||
|
{
|
||||||
let score = Float(dayOffset + 1) / Float(numberOfDays)
|
guard let entryDate = Calendar.current.date(byAdding: .day, value: dayOffset, to: currentDate) else { continue }
|
||||||
let entry = AppEntry(date: entryDate, relevance: TimelineEntryRelevance(score: score), app: snapshot)
|
|
||||||
|
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)
|
entries.append(entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,12 +69,16 @@ struct WidgetView : View
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Countdown(startDate: app.refreshedDate, endDate: app.expirationDate)
|
if daysRemaining >= 0
|
||||||
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
{
|
||||||
.foregroundColor(Color.white)
|
Countdown(startDate: app.refreshedDate,
|
||||||
.opacity(0.8)
|
endDate: app.expirationDate)
|
||||||
.fixedSize(horizontal: true, vertical: false)
|
.font(.system(size: 20, weight: .semibold, design: .rounded))
|
||||||
.offset(x: 5)
|
.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.
|
.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