Add tokenExpired property and update warning display logic in live activity

This commit is contained in:
Horváth Gergely
2025-12-30 04:03:09 +01:00
committed by 4831c0
parent f866052905
commit 1f57281004
2 changed files with 24 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ struct TimetableActivityAttributes: ActivityAttributes {
var labels: Labels?
var tokenExpirationWarning: String?
var tokenExpired: Bool?
var compactTimerText: String?
var lessonIcon: String?
@@ -68,11 +69,12 @@ struct TimetableActivityAttributes: ActivityAttributes {
case currentTime
case labels
case tokenExpirationWarning
case tokenExpired
case compactTimerText
case lessonIcon
}
init(isBreak: Bool, lessonName: String, lessonTheme: String?, roomName: String?, teacherName: String?, startTime: Date, endTime: Date, lessonNumber: Int?, mode: String?, message: String?, season: String?, nextLessonName: String?, nextRoomName: String?, nextStartTime: Date?, isSubstitution: Bool, isCancelled: Bool, substituteTeacher: String?, currentTime: Date, labels: Labels? = nil, tokenExpirationWarning: String? = nil, compactTimerText: String? = nil, lessonIcon: String? = nil) {
init(isBreak: Bool, lessonName: String, lessonTheme: String?, roomName: String?, teacherName: String?, startTime: Date, endTime: Date, lessonNumber: Int?, mode: String?, message: String?, season: String?, nextLessonName: String?, nextRoomName: String?, nextStartTime: Date?, isSubstitution: Bool, isCancelled: Bool, substituteTeacher: String?, currentTime: Date, labels: Labels? = nil, tokenExpirationWarning: String? = nil, tokenExpired: Bool? = nil, compactTimerText: String? = nil, lessonIcon: String? = nil) {
self.isBreak = isBreak
self.lessonName = lessonName
self.lessonTheme = lessonTheme
@@ -93,6 +95,7 @@ struct TimetableActivityAttributes: ActivityAttributes {
self.currentTime = currentTime
self.labels = labels
self.tokenExpirationWarning = tokenExpirationWarning
self.tokenExpired = tokenExpired
self.compactTimerText = compactTimerText
self.lessonIcon = lessonIcon
}
@@ -139,6 +142,7 @@ struct TimetableActivityAttributes: ActivityAttributes {
substituteTeacher = try container.decodeIfPresent(String.self, forKey: .substituteTeacher)
labels = try container.decodeIfPresent(Labels.self, forKey: .labels)
tokenExpirationWarning = try container.decodeIfPresent(String.self, forKey: .tokenExpirationWarning)
tokenExpired = try container.decodeIfPresent(Bool.self, forKey: .tokenExpired)
compactTimerText = try container.decodeIfPresent(String.self, forKey: .compactTimerText)
lessonIcon = try container.decodeIfPresent(String.self, forKey: .lessonIcon)
@@ -180,6 +184,7 @@ struct TimetableActivityAttributes: ActivityAttributes {
try container.encodeIfPresent(substituteTeacher, forKey: .substituteTeacher)
try container.encodeIfPresent(labels, forKey: .labels)
try container.encodeIfPresent(tokenExpirationWarning, forKey: .tokenExpirationWarning)
try container.encodeIfPresent(tokenExpired, forKey: .tokenExpired)
try container.encodeIfPresent(compactTimerText, forKey: .compactTimerText)
try container.encodeIfPresent(lessonIcon, forKey: .lessonIcon)
@@ -322,6 +327,9 @@ extension TimetableActivityAttributes.ContentState {
if let tokenExpirationWarning = tokenExpirationWarning {
json["tokenExpirationWarning"] = tokenExpirationWarning
}
if let tokenExpired = tokenExpired {
json["tokenExpired"] = tokenExpired
}
if let compactTimerText = compactTimerText {
json["compactTimerText"] = compactTimerText
}
@@ -399,6 +407,7 @@ extension TimetableActivityAttributes.ContentState {
currentTime: currentTime,
labels: labels,
tokenExpirationWarning: json["tokenExpirationWarning"] as? String,
tokenExpired: json["tokenExpired"] as? Bool,
compactTimerText: json["compactTimerText"] as? String,
lessonIcon: json["lessonIcon"] as? String
)

View File

@@ -218,13 +218,17 @@ struct TimetableLiveActivity: Widget {
let mode3 = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
let showWarningModes = ["newYearEve", "lesson", "break", "seasonalBreak"]
if let warning = context.state.tokenExpirationWarning, !warning.isEmpty, showWarningModes.contains(mode3) {
let isExpired = context.state.tokenExpired ?? false
let warningColor: Color = isExpired ? .red : .orange
let warningIcon = isExpired ? "exclamationmark.circle.fill" : "exclamationmark.triangle.fill"
HStack(spacing: 3) {
Image(systemName: "exclamationmark.triangle.fill")
Image(systemName: warningIcon)
.font(.system(size: 8))
.foregroundColor(.orange)
.foregroundColor(warningColor)
Text(warning)
.font(.system(size: 8, weight: .semibold))
.foregroundColor(.orange)
.foregroundColor(warningColor)
.lineLimit(1)
.minimumScaleFactor(0.6)
}
@@ -540,13 +544,17 @@ struct TimetableLiveActivityView: View {
// Token expiration warning (only for specific modes)
let showWarningModes = ["newYearEve", "lesson", "break", "seasonalBreak"]
if let warning = context.state.tokenExpirationWarning, !warning.isEmpty, showWarningModes.contains(mode) {
let isExpired = context.state.tokenExpired ?? false
let warningColor: Color = isExpired ? .red : .orange
let warningIcon = isExpired ? "exclamationmark.circle.fill" : "exclamationmark.triangle.fill"
HStack(spacing: 4) {
Image(systemName: "exclamationmark.triangle.fill")
Image(systemName: warningIcon)
.font(.system(size: 10))
.foregroundColor(.orange)
.foregroundColor(warningColor)
Text(warning)
.font(.system(size: 10, weight: .semibold))
.foregroundColor(.orange)
.foregroundColor(warningColor)
.lineLimit(1)
.minimumScaleFactor(0.7)
}