Harden watch sync and App Group storage

This commit is contained in:
FuelBoard Contributor
2026-09-26 20:03:29 +01:00
parent 004fe2f787
commit c3a975eb10
5 changed files with 95 additions and 16 deletions
+12 -1
View File
@@ -157,6 +157,7 @@ private enum WatchFuelCache {
static let appGroupSuite = "group.com.apt.fuelboard"
static let favouritesKey = "fuelboard.favourites"
static let stationsKey = "fuelboard.stations"
static let stationsFileName = "fuelboard.stations.json"
static let fuelKey = "fuelboard.selectedFuel"
static let distanceUnitKey = "fuelboard.distanceUnit"
static let priceStyleKey = "fuelboard.priceDisplayStyle"
@@ -228,7 +229,17 @@ private enum WatchFuelCache {
}
static func loadStations() -> [WatchStation] {
guard let data = defaults()?.data(forKey: stationsKey),
let fileData: Data?
if let container = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: appGroupSuite
) {
let url = container.appendingPathComponent(stationsFileName)
fileData = try? Data(contentsOf: url)
} else {
fileData = nil
}
let data = fileData ?? defaults()?.data(forKey: stationsKey)
guard let data,
let stations = try? JSONDecoder().decode([WatchStation].self, from: data) else {
return []
}