From 9f6ecb610c6c642991d200526a31211f41db6d33 Mon Sep 17 00:00:00 2001 From: FuelBoard Contributor Date: Wed, 12 Aug 2026 09:41:48 +0100 Subject: [PATCH] Alerts show actual station name, distance and price MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both the real alert path and the real-data Settings test now render the notification body as 'Station · 1.2 mi away · 145.9p' — actual haversine distance to the station in the user's unit, not just the radius. --- FuelBoard/ProximityMonitor.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/FuelBoard/ProximityMonitor.swift b/FuelBoard/ProximityMonitor.swift index 2ea3b18..91e1e79 100644 --- a/FuelBoard/ProximityMonitor.swift +++ b/FuelBoard/ProximityMonitor.swift @@ -166,15 +166,19 @@ final class ProximityMonitor: NSObject, ObservableObject, @preconcurrency CLLoca private func fireAlert(for station: FuelStation, price: Double) { let brand = station.brand.isEmpty ? station.name : station.brand let unit = FuelStore.loadDistanceUnit() + let distanceText: String = { + guard let location = FuelStore.loadLocation() else { return unit.format(0) } + return unit.format(station.distanceKM(to: location.lat, lng2: location.lng)) + }() let content = UNMutableNotificationContent() content.title = "Cheapest \(fuel.displayName) nearby: \(brand)" - content.body = "\(station.name) is the cheapest within \(unit.format(radiusKM)) at \(String(format: "%.1fp", price)). Tap to open." + content.body = "\(station.name) · \(distanceText) away · \(String(format: "%.1fp", price)). Tap to open." content.sound = .default let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) UNUserNotificationCenter.current().add(request) - lastAlert = "\(brand) · \(String(format: "%.1fp", price)) · \(unit.format(radiusKM)) radius" + lastAlert = "\(brand) · \(String(format: "%.1fp", price)) · \(distanceText) away" } /// Fires a test alert built from REAL data: the cheapest station selling @@ -197,13 +201,17 @@ final class ProximityMonitor: NSObject, ObservableObject, @preconcurrency CLLoca if let candidate, let price = candidate.prices[fuel] { let brand = candidate.brand.isEmpty ? candidate.name : candidate.brand + let distanceText: String = { + guard let location else { return unit.format(0) } + return unit.format(candidate.distanceKM(to: location.lat, lng2: location.lng)) + }() let content = UNMutableNotificationContent() content.title = "Cheapest \(fuel.displayName) nearby: \(brand)" - content.body = "\(candidate.name) is the cheapest within \(unit.format(radiusKM)) at \(String(format: "%.1fp", price)). Tap to open." + content.body = "\(candidate.name) · \(distanceText) away · \(String(format: "%.1fp", price)). Tap to open." content.sound = .default let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) UNUserNotificationCenter.current().add(request) - lastTestResult = "\(fuel.displayName) · \(brand) · \(String(format: "%.1fp", price)) · radius \(unit.format(radiusKM))" + lastTestResult = "\(fuel.displayName) · \(brand) · \(String(format: "%.1fp", price)) · \(distanceText) away · radius \(unit.format(radiusKM))" } else { // No real candidate (no stations loaded yet, or none sell the // monitored fuel) — still fire so delivery is testable, but say