macOS widgets
This commit is contained in:
parent
5ec3a90925
commit
34a6d960a2
|
|
@ -74,7 +74,7 @@ struct Provider: IntentTimelineProvider {
|
||||||
SimpleEntry(date: Date(),
|
SimpleEntry(date: Date(),
|
||||||
configuration: ConfigurationIntent(),
|
configuration: ConfigurationIntent(),
|
||||||
widgetData: widgetData,
|
widgetData: widgetData,
|
||||||
value: "$100.00",
|
value: 0,
|
||||||
error: "")
|
error: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ struct Provider: IntentTimelineProvider {
|
||||||
let entry = SimpleEntry(date: Date(),
|
let entry = SimpleEntry(date: Date(),
|
||||||
configuration: configuration,
|
configuration: configuration,
|
||||||
widgetData: widgetData,
|
widgetData: widgetData,
|
||||||
value: "$100.00",
|
value: 0,
|
||||||
error: "")
|
error: "")
|
||||||
|
|
||||||
completion(entry)
|
completion(entry)
|
||||||
|
|
@ -98,8 +98,7 @@ struct Provider: IntentTimelineProvider {
|
||||||
Task {
|
Task {
|
||||||
|
|
||||||
var widgetData:WidgetData?
|
var widgetData:WidgetData?
|
||||||
var value = ""
|
var value = 0.0
|
||||||
var label = ""
|
|
||||||
var message = ""
|
var message = ""
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
@ -129,10 +128,9 @@ struct Provider: IntentTimelineProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTimelineData(for configuration: ConfigurationIntent, widgetData:WidgetData) async throws -> (String) {
|
func getTimelineData(for configuration: ConfigurationIntent, widgetData:WidgetData) async throws -> (Double) {
|
||||||
|
|
||||||
var rawValue = 0.0
|
var value = 0.0
|
||||||
var value = "Error"
|
|
||||||
|
|
||||||
let companyId = configuration.company?.identifier ?? ""
|
let companyId = configuration.company?.identifier ?? ""
|
||||||
let company = widgetData.companies[companyId]
|
let company = widgetData.companies[companyId]
|
||||||
|
|
@ -177,31 +175,22 @@ struct Provider: IntentTimelineProvider {
|
||||||
|
|
||||||
switch configuration.dashboardField?.identifier {
|
switch configuration.dashboardField?.identifier {
|
||||||
case "total_active_invoices":
|
case "total_active_invoices":
|
||||||
if let invoicedAmount = data?.invoices?.invoicedAmount, let value = Double(invoicedAmount) {
|
if let invoicedAmount = data?.invoices?.invoicedAmount {
|
||||||
rawValue = value
|
value = Double(invoicedAmount) ?? 0
|
||||||
}
|
}
|
||||||
case "total_outstanding_invoices":
|
case "total_outstanding_invoices":
|
||||||
if let amount = data?.outstanding?.amount, let value = Double(amount) {
|
if let amount = data?.outstanding?.amount {
|
||||||
rawValue = value
|
value = Double(amount) ?? 0
|
||||||
}
|
}
|
||||||
case "total_completed_payments":
|
case "total_completed_payments":
|
||||||
if let paidToDate = data?.revenue?.paidToDate, let value = Double(paidToDate) {
|
if let paidToDate = data?.revenue?.paidToDate {
|
||||||
rawValue = value
|
value = Double(paidToDate) ?? 0
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let formatter = NumberFormatter()
|
|
||||||
formatter.numberStyle = .currency
|
|
||||||
formatter.currencyCode = currency?.code ?? "USD"
|
|
||||||
|
|
||||||
formatter.minimumFractionDigits = 0
|
|
||||||
formatter.maximumFractionDigits = 0
|
|
||||||
|
|
||||||
value = formatter.string(from: NSNumber(value: rawValue))!
|
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,7 +304,7 @@ struct SimpleEntry: TimelineEntry {
|
||||||
let date: Date
|
let date: Date
|
||||||
let configuration: ConfigurationIntent
|
let configuration: ConfigurationIntent
|
||||||
let widgetData: WidgetData?
|
let widgetData: WidgetData?
|
||||||
let value: String
|
let value: Double
|
||||||
let error: String
|
let error: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,6 +322,23 @@ struct DashboardWidgetEntryView : View {
|
||||||
return entry.widgetData?.companies[companyId]?.name ?? entry.configuration.company?.displayString ?? "";
|
return entry.widgetData?.companies[companyId]?.name ?? entry.configuration.company?.displayString ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var value: String {
|
||||||
|
let companyId = entry.configuration.company?.identifier ?? ""
|
||||||
|
let company = entry.widgetData?.companies[companyId]
|
||||||
|
let currencyId = entry.configuration.currency?.identifier ?? ""
|
||||||
|
let currency = company?.currencies[currencyId]
|
||||||
|
|
||||||
|
|
||||||
|
let formatter = NumberFormatter()
|
||||||
|
formatter.numberStyle = .currency
|
||||||
|
formatter.currencyCode = currency?.code ?? "USD"
|
||||||
|
|
||||||
|
formatter.minimumFractionDigits = 0
|
||||||
|
formatter.maximumFractionDigits = 0
|
||||||
|
|
||||||
|
return formatter.string(from: NSNumber(value: entry.value))!
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if (!entry.error.isEmpty) {
|
if (!entry.error.isEmpty) {
|
||||||
Text(entry.error)
|
Text(entry.error)
|
||||||
|
|
@ -349,7 +355,7 @@ struct DashboardWidgetEntryView : View {
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
.foregroundColor(accentColor)
|
.foregroundColor(accentColor)
|
||||||
Text(entry.value)
|
Text(value)
|
||||||
.font(.title)
|
.font(.title)
|
||||||
.privacySensitive()
|
.privacySensitive()
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|
@ -411,7 +417,7 @@ struct DashboardWidget_Previews: PreviewProvider {
|
||||||
let entry = SimpleEntry(date: Date(),
|
let entry = SimpleEntry(date: Date(),
|
||||||
configuration: ConfigurationIntent(),
|
configuration: ConfigurationIntent(),
|
||||||
widgetData: widgetData,
|
widgetData: widgetData,
|
||||||
value: "$100.00",
|
value: 0,
|
||||||
error: "")
|
error: "")
|
||||||
|
|
||||||
DashboardWidgetEntryView(entry: entry)
|
DashboardWidgetEntryView(entry: entry)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue