From 8a25f3604ae3980806fac9985adc77153df77df9 Mon Sep 17 00:00:00 2001 From: Sylvain Bettinelli Date: Tue, 11 Aug 2026 20:02:15 +0000 Subject: [PATCH] Exposer le snapshot stocke pour trancher un widget fige MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- ios/App/App/CoachWidgetBridge.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ios/App/App/CoachWidgetBridge.swift b/ios/App/App/CoachWidgetBridge.swift index e189f41..3af4b1a 100644 --- a/ios/App/App/CoachWidgetBridge.swift +++ b/ios/App/App/CoachWidgetBridge.swift @@ -24,6 +24,7 @@ public class CoachWidgetBridgePlugin: CAPPlugin, CAPBridgedPlugin { public let pluginMethods: [CAPPluginMethod] = [ CAPPluginMethod(name: "setSnapshot", returnType: CAPPluginReturnPromise), CAPPluginMethod(name: "clear", returnType: CAPPluginReturnPromise), + CAPPluginMethod(name: "getSnapshot", returnType: CAPPluginReturnPromise), ] @objc func setSnapshot(_ call: CAPPluginCall) { @@ -118,6 +119,31 @@ public class CoachWidgetBridgePlugin: CAPPlugin, CAPBridgedPlugin { 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) { CoachWidgetStore.clear() if #available(iOS 14.0, *) { WidgetCenter.shared.reloadAllTimelines() }