From ef6e7a206be7e62bf28c3ccef4eb2cc23233b6cd Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 14 Jun 2023 23:41:31 +0300 Subject: [PATCH] macOS widgets --- .../CompanyIntent/CompanyIntent.entitlements | 8 ++- macos/CompanyIntent/IntentHandler.swift | 52 ++++++++++++------- .../DashboardWidget.intentdefinition | 5 ++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 + 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/macos/CompanyIntent/CompanyIntent.entitlements b/macos/CompanyIntent/CompanyIntent.entitlements index 13cb114cf..d59f66b26 100644 --- a/macos/CompanyIntent/CompanyIntent.entitlements +++ b/macos/CompanyIntent/CompanyIntent.entitlements @@ -2,7 +2,11 @@ - com.apple.security.app-sandbox - + com.apple.security.app-sandbox + + com.apple.security.application-groups + + group.com.invoiceninja.app + diff --git a/macos/CompanyIntent/IntentHandler.swift b/macos/CompanyIntent/IntentHandler.swift index 52058e288..5d477ee53 100644 --- a/macos/CompanyIntent/IntentHandler.swift +++ b/macos/CompanyIntent/IntentHandler.swift @@ -9,35 +9,49 @@ import Intents import DashboardWidgetExtension class IntentHandler: INExtension, ConfigurationIntentHandling { - + func provideCompanyOptionsCollection(for intent: ConfigurationIntent) async throws -> INObjectCollection { // 1 // Fetch list of top ten crypto from API //let assets = try await AssetFetcher.fetchTopTenAssets() - // 2 - // Transform `[Asset]` to `[Crypto]` - /* - let cryptos = assets.map { asset in - - let crypto = Crypto( - identifier: asset.id, - display: "\(asset.name) (\(asset.symbol))" - ) - crypto.symbol = asset.symbol - crypto.name = asset.name - - return crypto + + + let sharedDefaults = UserDefaults.init(suiteName: "group.com.invoiceninja.app") + var exampleData: WidgetData = WidgetData(tokens:[:]) + + if sharedDefaults != nil { + do { + let shared = sharedDefaults!.string(forKey: "widgetData") + if shared != nil { + let decoder = JSONDecoder() + exampleData = try decoder.decode(WidgetData.self, from: shared!.data(using: .utf8)!) + } + } catch { + print(error) + } + } + + let companies = exampleData.tokens.keys.map { token in + + let company = Company( + identifier: token, + display: exampleData.tokens[token] ?? "" + ) + //company.symbol = asset.symbol + //company.name = asset.name + + return company } - */ // 3 // Create a collection with the array of cryptos. - let company1 = Company(identifier: "1", display: "Test 1") - let company2 = Company(identifier: "2", display: "Test 2") - - let collection = INObjectCollection(items: [company1, company2]) + //let company1 = Company(identifier: "1", display: "Test 1") + //let company2 = Company(identifier: "2", display: "Test 2") + //let collection = INObjectCollection(items: [company1, company2]) + + let collection = INObjectCollection(items: companies) // Return the collections return collection diff --git a/macos/DashboardWidget/DashboardWidget.intentdefinition b/macos/DashboardWidget/DashboardWidget.intentdefinition index e5d98304b..a96d536c7 100644 --- a/macos/DashboardWidget/DashboardWidget.intentdefinition +++ b/macos/DashboardWidget/DashboardWidget.intentdefinition @@ -155,6 +155,11 @@ Field INIntentParameterEnumTypeNamespace 88xZPY + INIntentParameterMetadata + + INIntentParameterMetadataDefaultValue + invoices + INIntentParameterName field INIntentParameterPromptDialogs diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 277ab105c..34a4b8cd7 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -20,6 +20,7 @@ import sign_in_with_apple import smart_auth import sqflite import url_launcher_macos +import widget_kit_plugin import window_manager func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { @@ -38,5 +39,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) + WidgetKitPlugin.register(with: registry.registrar(forPlugin: "WidgetKitPlugin")) WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) }