Siri: scope cheapest-near-me to the saved search radius (5/10/15 mi)

This commit is contained in:
FuelBoard Contributor
2026-08-14 12:49:30 +01:00
parent be781d80f5
commit 037c2418af
3 changed files with 64 additions and 28 deletions
+14 -7
View File
@@ -6,9 +6,10 @@ import SwiftUI
/// Design (see skill reference `siri-app-intents-scope.md`):
/// - App Intents (iOS 16+), no entitlements/capabilities/Info.plist keys.
/// - Cached-data-first: answers from the full-UK dump saved in the app-group
/// defaults by the normal app fetch. The dialog ALWAYS labels data age
/// ("as of 6:30 AM") silent stale answers are a trust killer for fuel
/// prices. The fresh-data path (relay baseURL is LAN-only) is a P0
/// defaults by the normal app fetch, SCOPED to the app's saved search radius
/// (5/10/15 mi) so "near me" really means near me. The dialog ALWAYS labels
/// data age ("as of 6:30 AM") silent stale answers are a trust killer for
/// fuel prices. The fresh-data path (relay baseURL is LAN-only) is a P0
/// dependency; until it lands, off-LAN answers use whatever the phone
/// last fetched at home.
/// - Location: last-known location fallback (background CoreLocation from a
@@ -60,17 +61,23 @@ struct CheapestFuelIntent: AppIntent {
)
}
// Scope to the app's saved search radius (5/10/15 mi, default 5) so
// "near me" really means near me the UK-wide minimum can be hundreds
// of miles away.
let radiusMiles = Double(FuelStore.loadStationLimit())
guard let station = SiriCheapestLookup.cheapest(
in: stations,
fuel: fuel,
fromLat: coordinate.lat,
lng: coordinate.lng
lng: coordinate.lng,
withinMiles: radiusMiles
), let price = station.prices[fuel] else {
let fuelName = fuel.displayName.lowercased()
let radiusText = radiusMiles == 1 ? "1 mile" : "\(Int(radiusMiles)) miles"
return .result(
value: "No \(fuelName) stations found",
dialog: IntentDialog(stringLiteral: "I couldn't find any station selling \(fuelName) near you."),
view: CheapestFuelMessage(text: "No \(fuelName) stations found.")
value: "No \(fuelName) stations within \(radiusText)",
dialog: IntentDialog(stringLiteral: "I couldn't find any station selling \(fuelName) within \(radiusText) of you."),
view: CheapestFuelMessage(text: "No \(fuelName) stations within \(radiusText).")
)
}