forked from firka/firka
Introduce App Shortcuts and AppIntents support: add multiple shortcut intents (next/closest lesson, today/tomorrow/closest timetable, recent grades, subject/overall averages), AppShortcuts provider, and ShortcutError. Add AppEntity types (Average, Grade, Lesson, Subject) and corresponding entity queries. Refactor Controls to use AppIntent-based navigation (OpenHome/OpenGrades/OpenTimetable) with localized labels/descriptions and remove duplicate SubjectEntity from AveragesIntent. Update TimetableProvider to use a lock-screen-friendly timeline refresh policy. Add localization resources (AppShortcuts.strings and expanded Localizable.strings) for en/de/hu and register new strings in project files; update Info.plist/project.pbxproj accordingly.
33 lines
1.4 KiB
Swift
33 lines
1.4 KiB
Swift
import AppIntents
|
|
|
|
@available(iOS 16.0, *)
|
|
struct GetClosestLessonIntent: AppIntent {
|
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_closest_lesson_title", defaultValue: "Closest lesson")
|
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_closest_lesson_description", defaultValue: "Get the closest lesson (today, tomorrow, or next school day)"))
|
|
|
|
func perform() async throws -> some ReturnsValue<LessonEntity> & ProvidesDialog {
|
|
guard let data = WidgetData.load() else {
|
|
throw ShortcutError.noData
|
|
}
|
|
let now = Date()
|
|
|
|
if let lesson = data.timetable.today.first(where: { $0.start > now })
|
|
?? data.timetable.today.first(where: { $0.end > now }) {
|
|
let entity = LessonEntity(from: lesson)
|
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
|
}
|
|
|
|
if let lesson = data.timetable.tomorrow.first {
|
|
let entity = LessonEntity(from: lesson)
|
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
|
}
|
|
|
|
if let lesson = data.timetable.nextSchoolDay?.first {
|
|
let entity = LessonEntity(from: lesson)
|
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
|
}
|
|
|
|
throw ShortcutError.noUpcomingLesson
|
|
}
|
|
}
|