Files
Calendarr-IOS/CalendarrWidgets/CalendarIntent.swift
Scarriffle 4e9ae83299 feat(widget): calendar filter config + fix group-view data leak
Bug fix: publishWidgetSnapshot() now guards against activeGroup != nil,
so group view events/colors never contaminate the widget cache.

Feature: widgets can now be configured via long-press → Edit Widget.
- WidgetCalendar struct + writeCalendars/readCalendars in WidgetData.swift
- calendarKey added to WidgetEvent (backward-compatible decoder)
- CalendarIntent.swift: CalendarAppEntity + CalendarEntityQuery + CalendarSelectionIntent
- CalendarrTimelineProvider migrated from TimelineProvider to AppIntentTimelineProvider
- All 13 StaticConfiguration widgets changed to AppIntentConfiguration
- publishWidgetSnapshot() builds + writes the calendar list for the intent

An empty selection (default) shows all calendars; selecting specific
calendars filters the widget events accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 18:41:43 +02:00

43 lines
1.6 KiB
Swift

import AppIntents
import WidgetKit
/// An individual calendar option shown in the widget configuration picker.
struct CalendarAppEntity: AppEntity, Identifiable {
let id: String
let name: String
let colorHex: String
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Kalender"
static var defaultQuery = CalendarEntityQuery()
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: LocalizedStringResource(stringLiteral: name))
}
}
/// Reads available calendars from the App Group container so the widget
/// extension can offer options without a network call.
struct CalendarEntityQuery: EntityQuery {
func entities(for identifiers: [String]) async throws -> [CalendarAppEntity] {
let ids = Set(identifiers)
return WidgetStore.readCalendars()
.filter { ids.contains($0.id) }
.map { CalendarAppEntity(id: $0.id, name: $0.name, colorHex: $0.colorHex) }
}
func suggestedEntities() async throws -> [CalendarAppEntity] {
WidgetStore.readCalendars()
.map { CalendarAppEntity(id: $0.id, name: $0.name, colorHex: $0.colorHex) }
}
}
/// Widget configuration intent: lets the user pick which calendars to show.
/// An empty selection means "show all calendars" (the default).
struct CalendarSelectionIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Kalender auswählen"
static var description = IntentDescription("Wähle welche Kalender im Widget angezeigt werden. Leer = alle Kalender.")
@Parameter(title: "Kalender")
var selectedCalendars: [CalendarAppEntity]
}