44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
import Intents
|
|
import Shared
|
|
import SwiftUI
|
|
import WidgetKit
|
|
|
|
@available(iOS 17, *)
|
|
struct WidgetGauge: Widget {
|
|
var body: some WidgetConfiguration {
|
|
AppIntentConfiguration(
|
|
kind: WidgetsKind.gauge.rawValue,
|
|
intent: WidgetGaugeAppIntent.self,
|
|
provider: WidgetGaugeAppIntentTimelineProvider()
|
|
) { timelineEntry in
|
|
if timelineEntry.runAction, let intent = intent(for: timelineEntry) {
|
|
Button(intent: intent) {
|
|
WidgetGaugeView(entry: timelineEntry)
|
|
.widgetBackground(Color.clear)
|
|
}
|
|
.buttonStyle(.plain)
|
|
} else {
|
|
WidgetGaugeView(entry: timelineEntry)
|
|
.widgetBackground(Color.clear)
|
|
}
|
|
}
|
|
.contentMarginsDisabledIfAvailable()
|
|
.configurationDisplayName(L10n.Widgets.Gauge.title)
|
|
.description(L10n.Widgets.Gauge.description)
|
|
.supportedFamilies(WidgetGaugeSupportedFamilies.families)
|
|
}
|
|
|
|
private func intent(for entry: WidgetGaugeEntry) -> PerformAction? {
|
|
if let action = entry.action {
|
|
let intent = PerformAction()
|
|
intent.action = IntentActionAppEntity(id: action.ID, displayString: action.Text)
|
|
return intent
|
|
} else { return nil }
|
|
}
|
|
}
|
|
|
|
@available(iOS 17, *)
|
|
enum WidgetGaugeSupportedFamilies {
|
|
static let families: [WidgetFamily] = [.accessoryCircular]
|
|
}
|