From 50319f8ba94e18e2547309790082d83c38626703 Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Thu, 16 Apr 2026 21:49:51 +0200 Subject: [PATCH] fix(calculator): init-Reihenfolge und save() Daten-Erhalt Standard-Modus vor open() registrieren (verhindert leeres Widget bei Restore). save() nutzt read-modify-write statt Overwrite (bewahrt Timer/ImageRef-Daten). Co-Authored-By: Claude Opus 4.6 --- src/js/calculator.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/js/calculator.js b/src/js/calculator.js index a323e1c..488a8f2 100644 --- a/src/js/calculator.js +++ b/src/js/calculator.js @@ -55,11 +55,10 @@ const Calculator = { */ async save() { const data = await Store.get(this.STORAGE_KEY) || {}; - const notesState = Array.isArray(data.notes) ? data.notes : []; // Widget-Position aus WidgetManager holen const widgetState = WidgetManager.getState(this.WIDGET_ID); - const calcData = { + data.calculator = { x: widgetState ? widgetState.x : 400, y: widgetState ? widgetState.y : 120, width: widgetState ? widgetState.width : 280, @@ -69,7 +68,7 @@ const Calculator = { history: this._history.slice(0, this.MAX_HISTORY) }; - await Store.set(this.STORAGE_KEY, { notes: notesState, calculator: calcData }); + await Store.set(this.STORAGE_KEY, data); }, // ---- WIDGET LIFECYCLE ---- @@ -830,6 +829,18 @@ const Calculator = { async init() { await this.load(); + // Standard-Modus ZUERST registrieren, bevor open() aufgerufen wird + this._modes.set('standard', { + label: '🔢', + shortName: 'Std', + titleKey: 'calculator.tab.standard', + render: (bodyEl) => this._renderStandardMode(bodyEl), + destroy: () => { + this._displayExprEl = null; + this._displayResultEl = null; + } + }); + // Wenn Calculator beim letzten Mal offen war, wiederherstellen const data = await Store.get(this.STORAGE_KEY); if (data && data.calculator && data.calculator.open) { @@ -863,17 +874,5 @@ const Calculator = { self.save(); } }); - - // Standard-Modus intern registrieren - this._modes.set('standard', { - label: '🔢', - shortName: 'Std', - titleKey: 'calculator.tab.standard', - render: (bodyEl) => this._renderStandardMode(bodyEl), - destroy: () => { - this._displayExprEl = null; - this._displayResultEl = null; - } - }); } };