summaryrefslogtreecommitdiffstats
path: root/Solsnu.Widget/Solsnu_WidgetControl.swift
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-12-17 00:16:58 +0100
committerivar <i@oiee.no>2025-12-17 00:16:58 +0100
commitbfd75822b3e9882ff4e85d13a0e3658b60e6329d (patch)
tree223462af215c5ee7eef9e6bcbb48dfbe1b97d1e3 /Solsnu.Widget/Solsnu_WidgetControl.swift
parent0e1635b057903434c0f193ad9ead7035150b0773 (diff)
downloadsolverv-master.tar.xz
solverv-master.zip
Initial commitHEADmaster
Diffstat (limited to 'Solsnu.Widget/Solsnu_WidgetControl.swift')
-rw-r--r--Solsnu.Widget/Solsnu_WidgetControl.swift54
1 files changed, 54 insertions, 0 deletions
diff --git a/Solsnu.Widget/Solsnu_WidgetControl.swift b/Solsnu.Widget/Solsnu_WidgetControl.swift
new file mode 100644
index 0000000..62cd817
--- /dev/null
+++ b/Solsnu.Widget/Solsnu_WidgetControl.swift
@@ -0,0 +1,54 @@
+//
+// Solsnu_WidgetControl.swift
+// Solsnu.Widget
+//
+// Created by Ivar Løvlie on 15/12/2025.
+//
+
+import AppIntents
+import SwiftUI
+import WidgetKit
+
+struct Solsnu_WidgetControl: ControlWidget {
+ var body: some ControlWidgetConfiguration {
+ StaticControlConfiguration(
+ kind: "ivarivarivar.Solverv.Solsnu.Widget",
+ provider: Provider()
+ ) { value in
+ ControlWidgetToggle(
+ "Start Timer",
+ isOn: value,
+ action: StartTimerIntent()
+ ) { isRunning in
+ Label(isRunning ? "On" : "Off", systemImage: "timer")
+ }
+ }
+ .displayName("Timer")
+ .description("A an example control that runs a timer.")
+ }
+}
+
+extension Solsnu_WidgetControl {
+ struct Provider: ControlValueProvider {
+ var previewValue: Bool {
+ false
+ }
+
+ func currentValue() async throws -> Bool {
+ let isRunning = true // Check if the timer is running
+ return isRunning
+ }
+ }
+}
+
+struct StartTimerIntent: SetValueIntent {
+ static let title: LocalizedStringResource = "Start a timer"
+
+ @Parameter(title: "Timer is running")
+ var value: Bool
+
+ func perform() async throws -> some IntentResult {
+ // Start / stop the timer based on `value`.
+ return .result()
+ }
+}