macOS widgets
This commit is contained in:
parent
8f6e27cb77
commit
0641983a4f
|
|
@ -54,7 +54,7 @@ class WidgetData {
|
||||||
'company_id': companyId,
|
'company_id': companyId,
|
||||||
'url': url,
|
'url': url,
|
||||||
'date_ranges': dateRanges,
|
'date_ranges': dateRanges,
|
||||||
'dashboard_Fields': dashboardFields,
|
'dashboard_fields': dashboardFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
final String url;
|
final String url;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ class IntentHandler: INExtension, ConfigurationIntentHandling {
|
||||||
if let sharedDefaults = sharedDefaults {
|
if let sharedDefaults = sharedDefaults {
|
||||||
do {
|
do {
|
||||||
if let shared = sharedDefaults.string(forKey: "widget_data") {
|
if let shared = sharedDefaults.string(forKey: "widget_data") {
|
||||||
|
|
||||||
|
//print("## Shared: \(shared)")
|
||||||
|
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder()
|
||||||
widgetData = try decoder.decode(WidgetData.self, from: shared.data(using: .utf8)!)
|
widgetData = try decoder.decode(WidgetData.self, from: shared.data(using: .utf8)!)
|
||||||
}
|
}
|
||||||
|
|
@ -35,6 +38,11 @@ class IntentHandler: INExtension, ConfigurationIntentHandling {
|
||||||
|
|
||||||
func defaultCompany(for intent: ConfigurationIntent) -> Company? {
|
func defaultCompany(for intent: ConfigurationIntent) -> Company? {
|
||||||
let widgetData = loadWidgetData()
|
let widgetData = loadWidgetData()
|
||||||
|
|
||||||
|
if (widgetData.companyId.isEmpty) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
let company = widgetData.companies[widgetData.companyId];
|
let company = widgetData.companies[widgetData.companyId];
|
||||||
return Company(identifier: company!.id, display: company!.name)
|
return Company(identifier: company!.id, display: company!.name)
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +60,11 @@ class IntentHandler: INExtension, ConfigurationIntentHandling {
|
||||||
|
|
||||||
func defaultCurrency(for intent: ConfigurationIntent) -> Currency? {
|
func defaultCurrency(for intent: ConfigurationIntent) -> Currency? {
|
||||||
let widgetData = loadWidgetData()
|
let widgetData = loadWidgetData()
|
||||||
|
|
||||||
|
if (widgetData.companyId.isEmpty) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
let company = widgetData.companies[widgetData.companyId];
|
let company = widgetData.companies[widgetData.companyId];
|
||||||
let currency = company?.currencies[company!.currencyId];
|
let currency = company?.currencies[company!.currencyId];
|
||||||
return Currency(identifier: currency!.id, display: currency!.name)
|
return Currency(identifier: currency!.id, display: currency!.name)
|
||||||
|
|
@ -70,6 +83,11 @@ class IntentHandler: INExtension, ConfigurationIntentHandling {
|
||||||
|
|
||||||
func defaultDateRange(for intent: ConfigurationIntent) -> DateRange? {
|
func defaultDateRange(for intent: ConfigurationIntent) -> DateRange? {
|
||||||
let widgetData = loadWidgetData()
|
let widgetData = loadWidgetData()
|
||||||
|
|
||||||
|
if (widgetData.dateRanges.isEmpty) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
let defaultDateRange = "last30_days";
|
let defaultDateRange = "last30_days";
|
||||||
let dateRamge = widgetData.dateRanges[defaultDateRange]!;
|
let dateRamge = widgetData.dateRanges[defaultDateRange]!;
|
||||||
return DateRange(identifier: defaultDateRange, display: dateRamge)
|
return DateRange(identifier: defaultDateRange, display: dateRamge)
|
||||||
|
|
@ -88,6 +106,11 @@ class IntentHandler: INExtension, ConfigurationIntentHandling {
|
||||||
|
|
||||||
func defaultDashboardField(for intent: ConfigurationIntent) -> DashboardField? {
|
func defaultDashboardField(for intent: ConfigurationIntent) -> DashboardField? {
|
||||||
let widgetData = loadWidgetData()
|
let widgetData = loadWidgetData()
|
||||||
|
|
||||||
|
if (widgetData.dashboardFields.isEmpty) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
let defaultField = "total_active_invoices";
|
let defaultField = "total_active_invoices";
|
||||||
let field = widgetData.dashboardFields[defaultField]!;
|
let field = widgetData.dashboardFields[defaultField]!;
|
||||||
return DashboardField(identifier: defaultField, display: field)
|
return DashboardField(identifier: defaultField, display: field)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue