Files
fuelboard/Shared/FuelBoardLiveActivity.swift
T
FuelBoard Contributor 20fe251b8e feat: honour Tap station action in widgets
Small widgetURL and medium list Links route through
StationTapAction via FuelStation.tapDestinationURL: Open map
keeps the Maps URL, More info uses a fuelboard://station
deep link (stationID plus coordinate/name fallback).

Deep link carries fallback coords; ContentView presents the
detail sheet when the station is cached, else the map sheet.
Live Activity detailURL upgraded to the same rich link.
2026-09-16 16:15:07 +01:00

40 lines
1.8 KiB
Swift

// FuelBoardLiveActivity.swift — Live Activity shared model.
//
// Compiled into BOTH the app target (to start/update/end the activity) and
// the widget extension (to render it). ActivityKit is iOS-only, so this file
// is deliberately NOT symlinked into FuelBoardTests/Sources — the SPM test
// target runs on macOS where ActivityKit does not exist.
//
// The activity tracks the cheapest station for the fuel + radius configured
// in Settings → Live Activity (INDEPENDENT of the Stations-tab selection).
// Everything dynamic lives in ContentState so updates — including a fuel
// change — apply to the running activity without needing to restart it.
// Tapping the activity honours Settings → Tap station: Open map opens Apple
// Maps driving directions (maps://), More info opens the detail sheet in
// the app (fuelboard://station).
import ActivityKit
import Foundation
/// Attributes are fixed at request time. Kept empty: the fuel itself lives in
/// ContentState so a fuel change in Settings updates the running activity
/// in place instead of requiring an end + restart.
struct FuelBoardLiveActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
var fuel: FuelType
var stationID: String
var stationName: String
var brand: String
/// Price in pence per litre (same unit as `FuelStation.prices`).
var pricePence: Double
/// Display style at push time (station sign vs pounds & pence) — carried
/// in the state so the extension renders deterministically instead of
/// re-reading storage that may not be shared on sideloads.
var priceDisplayStyle: PriceDisplayStyle
var distanceKM: Double
var lat: Double
var lng: Double
var updatedAt: Date
}
}