Widget: keychain-free fresh defaults — drop defaultResult(), auto-populate at entry time
The small-widget skeleton (fresh widget stranded on the placeholder while the medium populated in the gallery) traced to the small intent's default configuration resolution: FavouriteFuelQuery/WidgetFavouriteQuery defaultResult() read keychain in the gallery-preview/fresh-add path, failing the whole default config and leaving no timeline. Configured widgets bypassed defaultResult (stored values → lenient entities) — the exact favourites-works/cheapest-closest-doesn't split. - Remove defaultResult() from both queries: fresh configs now resolve from the static @Parameter(default:) values through lenient entities(for:) with ZERO storage reads. - WidgetFavouriteQuery.entities(for:) skips the keychain name lookup for id-only (empty station) values. - Auto-populate moves to makeEntry: empty pinned favourite → first favourite of the fuel (same rendered result as the old sheet default). - Sheet keeps the dependent picker via suggestedEntities() + dependency; fresh widgets show static defaults until picked (approved tradeoff).
This commit is contained in:
@@ -165,16 +165,29 @@ struct FuelPriceTimelineProvider<Configuration: WidgetConfigurationIntent & Widg
|
||||
// fuel, no radius. Freshen its price when a focused fetch covers
|
||||
// it. The chosen favourite wins; when it's missing or stale (fresh
|
||||
// widget, favourite removed, fuel row changed) fall back to the
|
||||
// favourites fuel's cheapest favourite so the face is never blank.
|
||||
// favourites fuel's first favourite so the face is never blank.
|
||||
if let chosen = configuration.favouriteChoice {
|
||||
let favouriteFuelType = configuration.favouriteFuelChoice?.fuel ?? fuel
|
||||
let pinned = favourites.first { $0.id == chosen.id }
|
||||
?? favourites
|
||||
// Fresh widget / static default (empty pinned favourite):
|
||||
// auto-populate to the FIRST favourite of the fuel. This is
|
||||
// the sheet's old defaultResult() auto-populate, moved to
|
||||
// entry time so default-config resolution stays keychain-free
|
||||
// (storage-backed defaultResult() stranding fresh small
|
||||
// widgets on the skeleton placeholder).
|
||||
let pinned: FavouriteEntry?
|
||||
if chosen.stationID.isEmpty {
|
||||
pinned = favourites
|
||||
.filter { $0.fuel == favouriteFuelType && $0.station.prices[favouriteFuelType] != nil }
|
||||
.min { lhs, rhs in
|
||||
(lhs.station.prices[favouriteFuelType] ?? .infinity) <
|
||||
(rhs.station.prices[favouriteFuelType] ?? .infinity)
|
||||
}
|
||||
.first
|
||||
} else {
|
||||
pinned = favourites.first { $0.id == chosen.id }
|
||||
?? favourites
|
||||
.filter { $0.fuel == favouriteFuelType && $0.station.prices[favouriteFuelType] != nil }
|
||||
.min { lhs, rhs in
|
||||
(lhs.station.prices[favouriteFuelType] ?? .infinity) <
|
||||
(rhs.station.prices[favouriteFuelType] ?? .infinity)
|
||||
}
|
||||
}
|
||||
if let pinned {
|
||||
var station = pinned.station
|
||||
if let location,
|
||||
|
||||
Reference in New Issue
Block a user