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>
91 lines
2.6 KiB
Swift
91 lines
2.6 KiB
Swift
//
|
|
// VanAligneiOSWidget.swift
|
|
// VanAligneiOSWidget
|
|
//
|
|
// Created by Christopher Helberg on 02.09.26.
|
|
//
|
|
|
|
import WidgetKit
|
|
import SwiftUI
|
|
|
|
struct Provider: AppIntentTimelineProvider {
|
|
func placeholder(in context: Context) -> SimpleEntry {
|
|
SimpleEntry(date: Date(), configuration: ConfigurationAppIntent())
|
|
}
|
|
|
|
func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
|
|
SimpleEntry(date: Date(), configuration: configuration)
|
|
}
|
|
|
|
func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> {
|
|
var entries: [SimpleEntry] = []
|
|
|
|
// Generate a timeline consisting of five entries an hour apart, starting from the current date.
|
|
let currentDate = Date()
|
|
for hourOffset in 0 ..< 5 {
|
|
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
|
|
let entry = SimpleEntry(date: entryDate, configuration: configuration)
|
|
entries.append(entry)
|
|
}
|
|
|
|
return Timeline(entries: entries, policy: .atEnd)
|
|
}
|
|
|
|
// func relevances() async -> WidgetRelevances<ConfigurationAppIntent> {
|
|
// // Generate a list containing the contexts this widget is relevant in.
|
|
// }
|
|
}
|
|
|
|
struct SimpleEntry: TimelineEntry {
|
|
let date: Date
|
|
let configuration: ConfigurationAppIntent
|
|
}
|
|
|
|
struct VanAligneiOSWidgetEntryView : View {
|
|
var entry: Provider.Entry
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text("Time:")
|
|
Text(entry.date, style: .time)
|
|
|
|
Text("Favorite Emoji:")
|
|
Text(entry.configuration.favoriteEmoji)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
struct VanAligneiOSWidget: Widget {
|
|
let kind: String = "VanAligneiOSWidget"
|
|
|
|
var body: some WidgetConfiguration {
|
|
AppIntentConfiguration(kind: kind, intent: ConfigurationAppIntent.self, provider: Provider()) { entry in
|
|
VanAligneiOSWidgetEntryView(entry: entry)
|
|
.containerBackground(.fill.tertiary, for: .widget)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
extension ConfigurationAppIntent {
|
|
fileprivate static var smiley: ConfigurationAppIntent {
|
|
let intent = ConfigurationAppIntent()
|
|
intent.favoriteEmoji = "😀"
|
|
return intent
|
|
}
|
|
|
|
fileprivate static var starEyes: ConfigurationAppIntent {
|
|
let intent = ConfigurationAppIntent()
|
|
intent.favoriteEmoji = "🤩"
|
|
return intent
|
|
}
|
|
}
|
|
|
|
#Preview(as: .systemSmall) {
|
|
VanAligneiOSWidget()
|
|
} timeline: {
|
|
SimpleEntry(date: .now, configuration: .smiley)
|
|
SimpleEntry(date: .now, configuration: .starEyes)
|
|
}
|