Files
Calendarr/ios/CalendarrWidgets/CalendarIntent.swift
T
ScarriffleandClaude Opus 5 6e981e7aea chore(repo): iOS-App als ios/ ins Hauptrepo uebernehmen
Calendarr-IOS wird mit vollstaendiger Historie als Unterverzeichnis
ios/ eingebunden. Damit liegen Server, Web, Android und iOS in einem
gemeinsamen Repo.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-14 09:20:12 +02:00

48 lines
1.9 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.
/// No selection means "show all calendars" (the default).
///
/// The parameter must be optional: WidgetConfigurationIntent requires every
/// parameter type to be optional, and the macOS/Mac Catalyst SDK enforces that
/// where the iOS one lets a bare array through. `nil` and `[]` are treated
/// alike downstream, so this is behaviour-preserving.
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]?
}