ReportageWidgets/ReportageWidgets.swift (2181B)
1import AppIntents
2import SwiftUI
3import WidgetKit
4
5@main
6struct ReportageWidgets: WidgetBundle {
7 var body: some Widget {
8 InstantReportControl()
9 InstantReportWidget()
10 }
11}
12
13
14
15struct InstantReportControl: ControlWidget {
16 var body: some ControlWidgetConfiguration {
17 StaticControlConfiguration(kind: "net.inqk.reportage.instant-report") {
18 ControlWidgetButton(action: LogPassiveReportIntent()) {
19 Label("Instant Report", systemImage: "bolt.fill")
20 }
21 }
22 .displayName("Instant Report")
23 .description("Files this report without a survey.")
24 }
25}
26
27
28
29struct InstantReportWidget: Widget {
30 var body: some WidgetConfiguration {
31 StaticConfiguration(kind: "net.inqk.reportage.instant-report-widget", provider: Provider()) { _ in
32 Button(intent: LogPassiveReportIntent()) {
33 ZStack {
34 AccessoryWidgetBackground()
35 Image(systemName: "bolt.fill")
36 .font(.title2.weight(.semibold))
37 }
38 }
39 .buttonStyle(.plain)
40 .accessibilityLabel(Text("Instant Report"))
41 .containerBackground(for: .widget) { Color.clear }
42 }
43 .configurationDisplayName("Instant Report")
44 .description("Files this report without a survey.")
45 .supportedFamilies([.accessoryCircular])
46 }
47
48 struct Provider: TimelineProvider {
49 func placeholder(in context: Context) -> Entry { Entry() }
50
51 func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
52 completion(Entry())
53 }
54
55 func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
56 completion(Timeline(entries: [Entry()], policy: .never))
57 }
58 }
59
60 struct Entry: TimelineEntry {
61 var date = Date.distantPast
62 }
63}