Files
Siro/siro_rider/ios/RideWidget/RideWidgetControl.swift
2026-06-09 08:40:31 +03:00

55 lines
1.3 KiB
Swift

//
// RideWidgetControl.swift
// RideWidget
//
// Created by Hamza Aleghwairyeen on 26/02/2026.
//
import AppIntents
import SwiftUI
import WidgetKit
struct RideWidgetControl: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(
kind: "com.siro.siro_rider.RideWidget",
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 RideWidgetControl {
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()
}
}