From 4bddd3ff8c2b484ab5720294bcd8f884d6044e12 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 22 Jun 2023 16:18:14 +0300 Subject: [PATCH] macOS widgets --- lib/ui/app/window_manager.dart | 23 +++++++-- macos/DashboardWidget/DashboardWidget.swift | 55 +++++++++++---------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/lib/ui/app/window_manager.dart b/lib/ui/app/window_manager.dart index 7fbe8ea62..e9bd83a26 100644 --- a/lib/ui/app/window_manager.dart +++ b/lib/ui/app/window_manager.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/company_model.dart'; +import 'package:invoiceninja_flutter/data/models/static/currency_model.dart'; import 'package:invoiceninja_flutter/main_app.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; @@ -139,10 +140,8 @@ class WidgetCompany { userCompanyState.clientState.map, userCompanyState.groupState.map, ).where((currencyId) => currencyId != kCurrencyAll)) - currencyId: WidgetCurrency( - id: currencyId, - name: staticState.currencyMap[currencyId].name, - exchangeRate: staticState.currencyMap[currencyId].exchangeRate, + currencyId: WidgetCurrency.fromCurrency( + staticState.currencyMap[currencyId], ) }; @@ -172,20 +171,34 @@ class WidgetCompany { } class WidgetCurrency { - WidgetCurrency({this.id, this.name, this.exchangeRate}); + WidgetCurrency({ + this.id, + this.name, + this.code, + this.exchangeRate, + }); + + WidgetCurrency.fromCurrency(CurrencyEntity currency) + : id = currency.id, + name = currency.name, + code = currency.code, + exchangeRate = currency.exchangeRate; WidgetCurrency.fromJson(Map json) : id = json['id'], name = json['name'], + code = json['code'], exchangeRate = json['exchange_rate']; Map toJson() => { 'id': id, 'name': name, + 'code': code, 'exchange_rate': exchangeRate, }; final String id; final String name; + final String code; final double exchangeRate; } diff --git a/macos/DashboardWidget/DashboardWidget.swift b/macos/DashboardWidget/DashboardWidget.swift index 4ab7cc08e..6f66e408f 100644 --- a/macos/DashboardWidget/DashboardWidget.swift +++ b/macos/DashboardWidget/DashboardWidget.swift @@ -33,8 +33,8 @@ struct Provider: IntentTimelineProvider { func getTimeline(for configuration: ConfigurationIntent, in context: Context, - completion: @escaping (Timeline) -> ()) { - + completion: @escaping (Timeline) -> ()) { + print("## getTimeline") Task { @@ -169,11 +169,13 @@ struct WidgetCompany: Decodable, Hashable { struct WidgetCurrency: Decodable, Hashable { let id: String let name: String + let code: String let exchangeRate: Double enum CodingKeys: String, CodingKey { case id case name + case code case exchangeRate = "exchange_rate" } } @@ -190,31 +192,32 @@ struct DashboardWidgetEntryView : View { var entry: Provider.Entry var body: some View { - //Text(entry.widgetData?.tokens.keys.joined() ?? "BLANK") - //Text("TEST \(entry.configuration.field.rawValue)") - VStack { - //Text(entry.configuration.company?.identifier ?? "") - Text(entry.field) - Text("Value: \(entry.value)") - Text(entry.configuration.company?.displayString ?? "") - Text(entry.widgetData?.url ?? "") - } - /* - ZStack { - Rectangle().fill(BackgroundStyle()) - VStack(alignment: .leading) { - Text("Balance") - .font(.largeTitle) - .fontWeight(.bold) - .foregroundColor(Color.blue) - Text("$123.00") - .privacySensitive() - .font(.title2) - .foregroundColor(Color.gray) - } + //Text(entry.widgetData?.tokens.keys.joined() ?? "BLANK") + //Text("TEST \(entry.configuration.field.rawValue)") + VStack { + //Text(entry.configuration.company?.identifier ?? "") + Text(entry.field) + Text("Value: \(entry.value)") + Text(entry.configuration.company?.displayString ?? "") + Text(entry.widgetData?.url ?? "") } */ + + ZStack { + Rectangle().fill(BackgroundStyle()) + VStack(alignment: .leading) { + Text(entry.field) + .font(.body) + .bold() + .foregroundColor(Color.blue) + Text("\(entry.value)") + .font(.title) + .privacySensitive() + .foregroundColor(Color.gray) + .minimumScaleFactor(0.8) + } + } } } @@ -331,12 +334,12 @@ struct ApiService { do { let (data, _) = try await URLSession.shared.data(for: request) // process data - + //print("## Details: \(String(describing: String(data: data, encoding: .utf8)))") let result = try JSONDecoder().decode([String: ApiResult].self, from: data) return result - + } catch { print("Error: \(error)") }