diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 10:30:51 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 10:30:51 +0200 |
| commit | 377442f2f1f0f08bc525393c9bd1c84f159c5159 (patch) | |
| tree | ab7f62cda14f1d85a30e65b130cf289f3a04947b /Captura/Intents | |
| parent | 8e9321304ca80e9ada7ac01058a5f4603cb37fab (diff) | |
Add AppleScript support
Diffstat (limited to 'Captura/Intents')
| -rw-r--r-- | Captura/Intents/CapturaShortcutsProvider.swift | 10 | ||||
| -rw-r--r-- | Captura/Intents/GetRemoteCaptures.swift | 29 |
2 files changed, 39 insertions, 0 deletions
diff --git a/Captura/Intents/CapturaShortcutsProvider.swift b/Captura/Intents/CapturaShortcutsProvider.swift new file mode 100644 index 0000000..2727325 --- /dev/null +++ b/Captura/Intents/CapturaShortcutsProvider.swift @@ -0,0 +1,10 @@ +import AppIntents + +struct CapturaShortcutsProvider: AppShortcutsProvider { + + static var appShortcuts: [AppShortcut] { + + AppShortcut(intent: GetRemoteCaptures(), phrases: ["Get \(.applicationName) remote captures"]) + + } +} diff --git a/Captura/Intents/GetRemoteCaptures.swift b/Captura/Intents/GetRemoteCaptures.swift new file mode 100644 index 0000000..58d9583 --- /dev/null +++ b/Captura/Intents/GetRemoteCaptures.swift @@ -0,0 +1,29 @@ +import AppIntents +import CoreData + +struct GetRemoteCaptures: AppIntent { + static var title: LocalizedStringResource = "Get remote captures" + + static var description = + IntentDescription("Return a list of remote captures") + + @Parameter(title: "Count") var count: Int? + + static var parameterSummary: some ParameterSummary { + Summary("Get \(\.$count) latest captures.") + } + + func perform() async throws -> some IntentResult & ReturnsValue { + let viewContext = PersistenceController.shared.container.viewContext + let fetchRequest = NSFetchRequest<CapturaRemoteFile>(entityName: "CapturaRemoteFile") + fetchRequest.fetchLimit = min(10, max(1, count ?? 5)) + fetchRequest.sortDescriptors = [NSSortDescriptor(key: "timestamp", ascending: false)] + + let results = await viewContext.perform { + return try? viewContext.fetch(fetchRequest) + } + + let finalResults = results?.compactMap { URL(string: $0.url ?? "")} ?? [] + return .result(value: finalResults) + } +} |