Widgets configured per-instance via App Intent
FuelPriceWidget now uses AppIntentConfiguration with a per-widget FuelBoardWidgetConfigurationIntent (fuel + sort). Each widget placed on the home screen carries its OWN fuel type (Unleaded/Premium/Diesel) and ordering (Cheapest/Closest), edited by long-press -> Edit Widget — independent of the app's selection, so multiple widgets can show different data side by side. Widget no longer reads the app's selected fuel. 35 tests pass.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import AppIntents
|
||||
import Foundation
|
||||
|
||||
// Per-widget configuration intent (iOS 17+). Every widget instance carries
|
||||
// its OWN fuel + sort choices, edited directly on the home screen (long-press
|
||||
// → Edit Widget), independent of what the app has selected. This is what
|
||||
// allows several FuelBoard widgets to show different fuels/orderings side by
|
||||
// side.
|
||||
|
||||
enum WidgetFuel: String, AppEnum, CaseIterable, Codable {
|
||||
case e10
|
||||
case e5
|
||||
case diesel
|
||||
|
||||
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Fuel"
|
||||
|
||||
static var caseDisplayRepresentations: [WidgetFuel: DisplayRepresentation] = [
|
||||
.e10: "Unleaded",
|
||||
.e5: "Premium",
|
||||
.diesel: "Diesel",
|
||||
]
|
||||
}
|
||||
|
||||
enum WidgetSort: String, AppEnum, CaseIterable, Codable {
|
||||
case cheapest
|
||||
case closest
|
||||
|
||||
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Sort by"
|
||||
|
||||
static var caseDisplayRepresentations: [WidgetSort: DisplayRepresentation] = [
|
||||
.cheapest: "Cheapest",
|
||||
.closest: "Closest",
|
||||
]
|
||||
}
|
||||
|
||||
struct FuelBoardWidgetConfigurationIntent: WidgetConfigurationIntent {
|
||||
static var title: LocalizedStringResource = "Fuel & Sort"
|
||||
static var description = IntentDescription("Which fuel and ordering this widget shows.")
|
||||
|
||||
@Parameter(title: "Fuel", default: .e10)
|
||||
var fuel: WidgetFuel
|
||||
|
||||
@Parameter(title: "Sort by", default: .cheapest)
|
||||
var sort: WidgetSort
|
||||
}
|
||||
Reference in New Issue
Block a user