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.
This commit is contained in:
FuelBoard Contributor
2026-09-16 16:15:07 +01:00
parent 465e6cd4d4
commit 20fe251b8e
6 changed files with 80 additions and 15 deletions
+15 -3
View File
@@ -243,9 +243,21 @@ struct ContentView: View {
)
}
.onReceive(NotificationCenter.default.publisher(for: .fuelBoardShowStationDetail)) { note in
guard let id = note.userInfo?["stationID"] as? String,
let station = stations.first(where: { $0.id == id }) else { return }
monitor.pendingDetailStation = station
let info = note.userInfo ?? [:]
if let id = info["stationID"] as? String,
let station = stations.first(where: { $0.id == id }) {
monitor.pendingDetailStation = station
return
}
// Station left the cache fall back to the map sheet so
// the tap still shows something.
if let lat = info["stationLat"] as? Double,
let lng = info["stationLng"] as? Double {
let name = info["stationName"] as? String ?? "Station"
monitor.pendingStationMap = StationMapRequest(
name: name, latitude: lat, longitude: lng
)
}
}
)
}
+21 -6
View File
@@ -69,20 +69,35 @@ struct FuelBoardApp: App {
/// `http://maps.apple.com` form is also handled, from very old timelines.
/// In CarPlay the widget uses the same `maps://` URL, which routes to
/// Apple Maps without ever launching this app.
/// A `fuelboard://station?stationID=` link (from a Live Activity tap when
/// Settings Tap station = More info) posts a notification that
/// ContentView observes to present the detail sheet.
/// A `fuelboard://station?stationID=&lat=&lng=&name=` link (from a
/// widget or Live Activity tap when Settings Tap station = More info)
/// posts a notification that ContentView observes to present the detail
/// sheet (falling back to the map sheet when the station has left
/// the cache).
private func handleOpenURL(_ url: URL) {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
else { return }
if components.scheme == "fuelboard",
components.host == "station",
let id = components.queryItems?.first(where: { $0.name == "stationID" })?.value {
components.host == "station" {
let items = components.queryItems ?? []
var userInfo: [String: Any] = [:]
if let id = items.first(where: { $0.name == "stationID" })?.value {
userInfo["stationID"] = id
}
if let lat = items.first(where: { $0.name == "lat" })?.value.flatMap(Double.init) {
userInfo["stationLat"] = lat
}
if let lng = items.first(where: { $0.name == "lng" })?.value.flatMap(Double.init) {
userInfo["stationLng"] = lng
}
if let name = items.first(where: { $0.name == "name" })?.value {
userInfo["stationName"] = name
}
NotificationCenter.default.post(
name: .fuelBoardShowStationDetail,
object: nil,
userInfo: ["stationID": id]
userInfo: userInfo
)
return
}