macOS widgets

This commit is contained in:
Hillel Coren 2023-06-14 23:41:31 +03:00
parent c137b55c85
commit ef6e7a206b
4 changed files with 46 additions and 21 deletions

View File

@ -2,7 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<true/> <true/>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.invoiceninja.app</string>
</array>
</dict> </dict>
</plist> </plist>

View File

@ -9,35 +9,49 @@ import Intents
import DashboardWidgetExtension import DashboardWidgetExtension
class IntentHandler: INExtension, ConfigurationIntentHandling { class IntentHandler: INExtension, ConfigurationIntentHandling {
func provideCompanyOptionsCollection(for intent: ConfigurationIntent) async throws -> INObjectCollection<Company> { func provideCompanyOptionsCollection(for intent: ConfigurationIntent) async throws -> INObjectCollection<Company> {
// 1 // 1
// Fetch list of top ten crypto from API // Fetch list of top ten crypto from API
//let assets = try await AssetFetcher.fetchTopTenAssets() //let assets = try await AssetFetcher.fetchTopTenAssets()
// 2
// Transform `[Asset]` to `[Crypto]`
/* let sharedDefaults = UserDefaults.init(suiteName: "group.com.invoiceninja.app")
let cryptos = assets.map { asset in var exampleData: WidgetData = WidgetData(tokens:[:])
let crypto = Crypto( if sharedDefaults != nil {
identifier: asset.id, do {
display: "\(asset.name) (\(asset.symbol))" let shared = sharedDefaults!.string(forKey: "widgetData")
) if shared != nil {
crypto.symbol = asset.symbol let decoder = JSONDecoder()
crypto.name = asset.name exampleData = try decoder.decode(WidgetData.self, from: shared!.data(using: .utf8)!)
}
return crypto } 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 // 3
// Create a collection with the array of cryptos. // Create a collection with the array of cryptos.
let company1 = Company(identifier: "1", display: "Test 1") //let company1 = Company(identifier: "1", display: "Test 1")
let company2 = Company(identifier: "2", display: "Test 2") //let company2 = Company(identifier: "2", display: "Test 2")
//let collection = INObjectCollection(items: [company1, company2])
let collection = INObjectCollection(items: [company1, company2])
let collection = INObjectCollection(items: companies)
// Return the collections // Return the collections
return collection return collection

View File

@ -155,6 +155,11 @@
<string>Field</string> <string>Field</string>
<key>INIntentParameterEnumTypeNamespace</key> <key>INIntentParameterEnumTypeNamespace</key>
<string>88xZPY</string> <string>88xZPY</string>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataDefaultValue</key>
<string>invoices</string>
</dict>
<key>INIntentParameterName</key> <key>INIntentParameterName</key>
<string>field</string> <string>field</string>
<key>INIntentParameterPromptDialogs</key> <key>INIntentParameterPromptDialogs</key>

View File

@ -20,6 +20,7 @@ import sign_in_with_apple
import smart_auth import smart_auth
import sqflite import sqflite
import url_launcher_macos import url_launcher_macos
import widget_kit_plugin
import window_manager import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
@ -38,5 +39,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin")) SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WidgetKitPlugin.register(with: registry.registrar(forPlugin: "WidgetKitPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
} }