diff options
Diffstat (limited to 'WidgetDashboardIntentHandler/IntentHandler.swift')
-rw-r--r-- | WidgetDashboardIntentHandler/IntentHandler.swift | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/WidgetDashboardIntentHandler/IntentHandler.swift b/WidgetDashboardIntentHandler/IntentHandler.swift new file mode 100644 index 000000000..0be2ead90 --- /dev/null +++ b/WidgetDashboardIntentHandler/IntentHandler.swift @@ -0,0 +1,42 @@ +// +// IntentHandler.swift +// WidgetDashboardIntentHandler +// +// Created by Marino Faggiana on 08/10/22. +// Copyright © 2022 Marino Faggiana. All rights reserved. +// + +import Intents +import RealmSwift + +class IntentHandler: INExtension, DashboardIntentHandling { + + func provideApplicationsOptionsCollection(for intent: DashboardIntent, with completion: @escaping (INObjectCollection<Applications>?, Error?) -> Void) { + + var applications: [Applications] = [] + + guard let account = NCManageDatabase.shared.getActiveAccount() else { + completion(nil, nil) + return + } + + let results = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account) + for result in results { + let application = Applications(identifier: result.id, display: result.title) + applications.append(application) + } + + completion(INObjectCollection(items: applications), nil) + } + + func defaultApplications(for intent: DashboardIntent) -> Applications? { + + guard let account = NCManageDatabase.shared.getActiveAccount() else { + return nil + } + if let result = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account).first { + return Applications(identifier: result.id, display: result.title) + } + return nil + } +} |