Exposer le snapshot stocke pour trancher un widget fige

Sans lecture de l'App Group, un widget qui n'affiche pas la bonne chose laisse
trois hypotheses ouvertes — rien d'ecrit, ecrit sans le champ, ou ecrit mais
pas reaffiche — et le JS ne peut en departager aucune : l'App Group lui est
invisible.

Vecu ce soir : tout etait correct jusqu'au stockage, seul le rafraichissement
de la timeline manquait. getSnapshot rend hasDoneToday, hasToday, l'horodatage
et le contenu, ce qui designe directement le maillon fautif.

⚠️ NON COMPILE — a embarquer au prochain build.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sylvain Bettinelli
2026-08-11 20:02:15 +00:00
parent c74faeaad5
commit 8a25f3604a

View File

@@ -24,6 +24,7 @@ public class CoachWidgetBridgePlugin: CAPPlugin, CAPBridgedPlugin {
public let pluginMethods: [CAPPluginMethod] = [ public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "setSnapshot", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "setSnapshot", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "clear", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "clear", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getSnapshot", returnType: CAPPluginReturnPromise),
] ]
@objc func setSnapshot(_ call: CAPPluginCall) { @objc func setSnapshot(_ call: CAPPluginCall) {
@@ -118,6 +119,31 @@ public class CoachWidgetBridgePlugin: CAPPlugin, CAPBridgedPlugin {
try? session.updateApplicationContext(["widgetSnapshot": data]) try? session.updateApplicationContext(["widgetSnapshot": data])
} }
/// Relit le snapshot RÉELLEMENT stocké dans l'App Group.
///
/// Sans cette lecture, un widget figé laisse trois hypothèses ouvertes
/// (rien d'écrit, écrit sans le champ, écrit mais pas réaffiché) et aucun
/// moyen de trancher depuis le web : l'App Group est invisible du JS.
@objc func getSnapshot(_ call: CAPPluginCall) {
guard let s = CoachWidgetStore.load() else {
call.resolve(["stored": false])
return
}
var out: [String: Any] = [
"stored": true,
"updatedAt": ISO8601DateFormatter().string(from: s.updatedAt),
"hasToday": s.today != nil,
"hasDoneToday": s.doneToday != nil,
]
if let d = s.doneToday {
out["doneToday"] = ["sport": d.sport,
"title": d.title ?? "",
"subtitle": d.subtitle ?? ""]
}
if let r = s.routine { out["routine"] = ["done": r.done, "total": r.total] }
call.resolve(out)
}
@objc func clear(_ call: CAPPluginCall) { @objc func clear(_ call: CAPPluginCall) {
CoachWidgetStore.clear() CoachWidgetStore.clear()
if #available(iOS 14.0, *) { WidgetCenter.shared.reloadAllTimelines() } if #available(iOS 14.0, *) { WidgetCenter.shared.reloadAllTimelines() }