Fix iOS timer widget not displaying active timers
The widget was failing to decode the cached timer data because WidgetTimer struct didn't match the OngoingTimer JSON structure saved by the app. Changes: - Added missing fields (project, createdAt, updatedAt) to WidgetTimer - Added WidgetProjectReference struct for nested project data - Fixed project name to use project.name instead of projectId - Added project color support - Increased refresh interval from 15 min to 1 min for live updates
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array/>
|
||||
<array>
|
||||
<string>group.com.timetracker.app</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.application-groups</key>
|
||||
<array/>
|
||||
<array>
|
||||
<string>group.com.timetracker.app</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -12,6 +12,9 @@ struct WidgetTimer: Codable {
|
||||
let id: String
|
||||
let startTime: String
|
||||
let projectId: String?
|
||||
let project: WidgetProjectReference?
|
||||
let createdAt: String
|
||||
let updatedAt: String
|
||||
|
||||
var elapsedTime: TimeInterval {
|
||||
guard let start = ISO8601DateFormatter().date(from: startTime) else {
|
||||
@@ -21,6 +24,12 @@ struct WidgetTimer: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
struct WidgetProjectReference: Codable {
|
||||
let id: String
|
||||
let name: String
|
||||
let color: String?
|
||||
}
|
||||
|
||||
struct Provider: TimelineProvider {
|
||||
private let appGroupIdentifier = "group.com.timetracker.app"
|
||||
|
||||
@@ -41,7 +50,8 @@ struct Provider: TimelineProvider {
|
||||
func getTimeline(in context: Context, completion: @escaping (Timeline<TimerEntry>) -> Void) {
|
||||
let entry = loadTimerEntry()
|
||||
|
||||
let nextUpdate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())!
|
||||
// Update every minute to show live timer countdown
|
||||
let nextUpdate = Calendar.current.date(byAdding: .minute, value: 1, to: Date())!
|
||||
let timeline = Timeline(entries: [entry], policy: .after(nextUpdate))
|
||||
|
||||
completion(timeline)
|
||||
@@ -63,8 +73,8 @@ struct Provider: TimelineProvider {
|
||||
return TimerEntry(
|
||||
date: Date(),
|
||||
timer: timer,
|
||||
projectName: timer.projectId,
|
||||
projectColor: nil
|
||||
projectName: timer.project?.name ?? timer.projectId,
|
||||
projectColor: timer.project?.color
|
||||
)
|
||||
} catch {
|
||||
return TimerEntry(
|
||||
|
||||
Reference in New Issue
Block a user