import SwiftUI @main struct FuelBoardApp: App { var body: some Scene { WindowGroup { ContentView() .onOpenURL(perform: handleOpenURL) } } /// Handles deep links that end up in the app. Widget taps arrive here in /// two cases: /// - legacy/cached widget timelines using the `fuelboard://` relay, or /// - the Home Screen delivering a `maps://` URL to the containing app /// instead of opening Maps directly (the system's choice on iOS). /// Either way we forward to the native Apple Maps directions URL. The /// `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. private func handleOpenURL(_ url: URL) { guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false), let items = components.queryItems else { return } // Preferred: maps://?daddr=lat,lng&t=d (also covers http://maps.apple.com). if let daddr = items.first(where: { $0.name == "daddr" })?.value { openMaps(daddr: daddr) return } // Legacy relay: fuelboard://directions?lat=..&lng=.. if let lat = items.first(where: { $0.name == "lat" })?.value.flatMap(Double.init), let lng = items.first(where: { $0.name == "lng" })?.value.flatMap(Double.init) { openMaps(daddr: "\(lat),\(lng)") } } private func openMaps(daddr: String) { guard let mapsURL = URL(string: "maps://?daddr=\(daddr)&t=d") else { return } UIApplication.shared.open(mapsURL) } }