Files
firka/firka/ios/HomeWidgetsExtension/Shortcuts/Intents/GetSubjectAverageIntent.swift
Horváth Gergely 2d14c41070 Add Shortcuts intents, entities & localizations
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.
2026-01-31 11:52:01 +01:00

22 lines
1.0 KiB
Swift

import AppIntents
@available(iOS 16.0, *)
struct GetSubjectAverageIntent: AppIntent {
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_subject_average_title", defaultValue: "Subject average")
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_subject_average_description", defaultValue: "Get the average for a subject"))
@Parameter(title: LocalizedStringResource("shortcut_param_subject", defaultValue: "Subject"))
var subject: SubjectEntity
func perform() async throws -> some ReturnsValue<AverageEntity> & ProvidesDialog {
guard let data = WidgetData.load() else {
throw ShortcutError.noData
}
guard let avg = data.averages.subjects.first(where: { $0.uid == subject.id }) else {
throw ShortcutError.subjectNotFound
}
let entity = AverageEntity(from: avg)
return .result(value: entity, dialog: "\(entity.subjectName): \(String(format: "%.2f", entity.average))")
}
}