Files
fuelboard/FuelBoard/FuelBoardApp.swift
T
FuelBoard Contributor 1ff14607c5 Widget tap relay via fuelboard:// scheme; full station names; no check-again
- WidgetKit widgets can only open their containing app — the Link URL is
  delivered to FuelBoard via onOpenURL, never opened directly in Maps. The
  widget now links to a registered fuelboard://directions?lat=&lng= URL,
  and FuelBoardApp forwards it to native maps://?daddr= directions.
  (http://maps.apple.com and raw maps:// both silently dropped in-app.)
- Widget rows (small + medium) now show the full station name (station.name)
  instead of just the brand.
- Onboarding network page: removed the 'Check again' secondary screen after
  the Local Network prompt — Open Settings remains the only retry path.
  35 tests pass.
2026-08-12 12:54:08 +01:00

27 lines
1.1 KiB
Swift

import SwiftUI
@main
struct FuelBoardApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL(perform: handleOpenURL)
}
}
/// WidgetKit widgets can only open their containing app, so a widget tap
/// delivers a `fuelboard://directions?lat=..&lng=..` URL here instead of
/// opening Apple Maps itself. Forward it to the native Maps directions
/// URL (`maps://?daddr=`), which is what the app's own rows use.
private func handleOpenURL(_ url: URL) {
guard url.scheme == "fuelboard",
url.host == "directions",
let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let lat = components.queryItems?.first(where: { $0.name == "lat" })?.value.flatMap(Double.init),
let lng = components.queryItems?.first(where: { $0.name == "lng" })?.value.flatMap(Double.init),
let mapsURL = URL(string: "maps://?daddr=\(lat),\(lng)&t=d")
else { return }
UIApplication.shared.open(mapsURL)
}
}