Location-driven results: widget fetches its own location (async, cache fallback), app auto-requests on first launch, Halifax sample stations

This commit is contained in:
FuelBoard Contributor
2026-08-11 14:03:41 +01:00
parent b0a5b5a326
commit 4f5f1999a9
6 changed files with 171 additions and 56 deletions
+7 -2
View File
@@ -12,6 +12,11 @@ import Security
// MARK: - Fuel types
struct Coordinate: Equatable, Codable {
let lat: Double
let lng: Double
}
enum FuelType: String, Codable, CaseIterable, Identifiable {
case e10 // Unleaded 95 (E10)
case e5 // Premium 97/98 (E5)
@@ -94,11 +99,11 @@ struct FuelStore {
// MARK: Last known location ("lat,lng,unixTime")
static func loadLocation() -> (lat: Double, lng: Double, date: Date)? {
static func loadLocation() -> Coordinate? {
let raw = loadString(service: locationKey)
let parts = raw?.split(separator: ",").compactMap { Double($0) }
guard let parts, parts.count == 3 else { return nil }
return (parts[0], parts[1], Date(timeIntervalSince1970: parts[2]))
return Coordinate(lat: parts[0], lng: parts[1])
}
static func saveLocation(lat: Double, lng: Double, date: Date = Date()) {