forked from fritob/Camper-Monitor
solar-integration (aus dem separaten VanAligneiOS-Repo) und dev_watch haben unabhängige Git-Historien, decken aber überlappende und sich ergänzende Funktionen ab. Übernommen aus solar-integration: Votronic- Solar-ESP-Anbindung samt Geräterolle, die Live-Activity/Widget-Extension fürs Sperrbildschirm/Dynamic-Island/CarPlay, das Querformat-Layout für Libelle/Fahrzeug-Ansicht und Ausrichtungs-Assistent, sowie die mehreren Fahrzeuggrafik-Stile (Vanster/California). Beibehalten aus dev_watch: alle zusätzlichen Geräteprotokolle (Daly-/JBD-BMS, Alpicool- Kühlbox, WattCycle, Victron), die dort zwischenzeitlich entstanden. Die Xcode-Projektdatei wurde von Hand um die neue Widget-Extension samt SharedActivity-Gruppe erweitert (Datei-synchronisierte Gruppen, kein App-Group-Entitlement nötig). Build für App, Watch und Widget-Extension geprüft (Debug und Release). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
78 lines
2.1 KiB
Swift
78 lines
2.1 KiB
Swift
//
|
|
// VanAligneiOSWidgetControl.swift
|
|
// VanAligneiOSWidget
|
|
//
|
|
// Created by Christopher Helberg on 02.09.26.
|
|
//
|
|
|
|
import AppIntents
|
|
import SwiftUI
|
|
import WidgetKit
|
|
|
|
struct VanAligneiOSWidgetControl: ControlWidget {
|
|
static let kind: String = "fototeddy.VanAligneiOS.VanAligneiOSWidget"
|
|
|
|
var body: some ControlWidgetConfiguration {
|
|
AppIntentControlConfiguration(
|
|
kind: Self.kind,
|
|
provider: Provider()
|
|
) { value in
|
|
ControlWidgetToggle(
|
|
"Start Timer",
|
|
isOn: value.isRunning,
|
|
action: StartTimerIntent(value.name)
|
|
) { isRunning in
|
|
Label(isRunning ? "On" : "Off", systemImage: "timer")
|
|
}
|
|
}
|
|
.displayName("Timer")
|
|
.description("A an example control that runs a timer.")
|
|
}
|
|
}
|
|
|
|
extension VanAligneiOSWidgetControl {
|
|
struct Value {
|
|
var isRunning: Bool
|
|
var name: String
|
|
}
|
|
|
|
struct Provider: AppIntentControlValueProvider {
|
|
func previewValue(configuration: TimerConfiguration) -> Value {
|
|
VanAligneiOSWidgetControl.Value(isRunning: false, name: configuration.timerName)
|
|
}
|
|
|
|
func currentValue(configuration: TimerConfiguration) async throws -> Value {
|
|
let isRunning = true // Check if the timer is running
|
|
return VanAligneiOSWidgetControl.Value(isRunning: isRunning, name: configuration.timerName)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TimerConfiguration: ControlConfigurationIntent {
|
|
static let title: LocalizedStringResource = "Timer Name Configuration"
|
|
|
|
@Parameter(title: "Timer Name", default: "Timer")
|
|
var timerName: String
|
|
}
|
|
|
|
struct StartTimerIntent: SetValueIntent {
|
|
static let title: LocalizedStringResource = "Start a timer"
|
|
|
|
@Parameter(title: "Timer Name")
|
|
var name: String
|
|
|
|
@Parameter(title: "Timer is running")
|
|
var value: Bool
|
|
|
|
init() {}
|
|
|
|
init(_ name: String) {
|
|
self.name = name
|
|
}
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
// Start the timer…
|
|
return .result()
|
|
}
|
|
}
|