From 557950f69293987529a81b2da6235fa4c0bf9b94 Mon Sep 17 00:00:00 2001 From: Hermes Date: Fri, 22 May 2026 06:54:34 +0800 Subject: [PATCH] Fix ToolApp back preview snapshots --- code/th_15_extra.js | 120 +++++++++++++++++++++++++++++++------------- manifest.json | 6 +-- manifest.sig | 2 +- 3 files changed, 90 insertions(+), 38 deletions(-) diff --git a/code/th_15_extra.js b/code/th_15_extra.js index 48e9e19..a3e0276 100644 --- a/code/th_15_extra.js +++ b/code/th_15_extra.js @@ -611,19 +611,83 @@ FloatBallAppWM.prototype.hasToolAppBackTarget = function() { return false; }; +FloatBallAppWM.prototype.captureToolAppPageSnapshot = function(route) { + var r = this.isToolAppRoute(route) ? String(route) : (this.isToolAppRoute(this.state.toolAppRoute) ? String(this.state.toolAppRoute) : "settings"); + var s = this.state || {}; + var entry = { + route: r, + settingsGroupKey: (s.settingsGroupKey !== undefined && s.settingsGroupKey !== null) ? String(s.settingsGroupKey) : "", + settingsHomeSelectedItemId: (s.settingsHomeSelectedItemId !== undefined) ? s.settingsHomeSelectedItemId : null, + editingButtonIndex: (s.editingButtonIndex !== undefined) ? s.editingButtonIndex : null, + editingSchemaIndex: (s.editingSchemaIndex !== undefined) ? s.editingSchemaIndex : null, + keepBtnEditorState: !!s.keepBtnEditorState, + keepSchemaEditorState: !!s.keepSchemaEditorState, + toolAppSubRoute: (s.toolAppSubRoute !== undefined) ? s.toolAppSubRoute : null, + toolAppSubPage: (s.toolAppSubPage !== undefined) ? s.toolAppSubPage : null, + toolAppSubKey: (s.toolAppSubKey !== undefined) ? s.toolAppSubKey : null, + toolAppSubPayload: (s.toolAppSubPayload !== undefined) ? s.toolAppSubPayload : null + }; + if (r !== "settings_group") entry.settingsGroupKey = ""; + if (r !== "settings") entry.settingsHomeSelectedItemId = null; + if (r !== "btn_editor") { entry.editingButtonIndex = null; entry.keepBtnEditorState = false; } + if (r !== "schema_editor") { entry.editingSchemaIndex = null; entry.keepSchemaEditorState = false; } + return entry; +}; + FloatBallAppWM.prototype.makeToolAppStackEntry = function(route) { + return this.captureToolAppPageSnapshot(route); +}; + +FloatBallAppWM.prototype.applyToolAppPageSnapshot = function(entry) { + try { + if (!entry || typeof entry !== "object") return false; + var r = this.isToolAppRoute(entry.route) ? String(entry.route) : "settings"; + this.state.toolAppRoute = r; + this.state.settingsGroupKey = (entry.settingsGroupKey !== undefined && entry.settingsGroupKey !== null) ? String(entry.settingsGroupKey) : ""; + this.state.settingsHomeSelectedItemId = (entry.settingsHomeSelectedItemId !== undefined) ? entry.settingsHomeSelectedItemId : null; + this.state.editingButtonIndex = (entry.editingButtonIndex !== undefined) ? entry.editingButtonIndex : null; + this.state.editingSchemaIndex = (entry.editingSchemaIndex !== undefined) ? entry.editingSchemaIndex : null; + this.state.keepBtnEditorState = !!entry.keepBtnEditorState; + this.state.keepSchemaEditorState = !!entry.keepSchemaEditorState; + this.state.toolAppSubRoute = (entry.toolAppSubRoute !== undefined) ? entry.toolAppSubRoute : null; + this.state.toolAppSubPage = (entry.toolAppSubPage !== undefined) ? entry.toolAppSubPage : null; + this.state.toolAppSubKey = (entry.toolAppSubKey !== undefined) ? entry.toolAppSubKey : null; + this.state.toolAppSubPayload = (entry.toolAppSubPayload !== undefined) ? entry.toolAppSubPayload : null; + return true; + } catch(e) { safeLog(this.L, 'w', "apply tool app snapshot fail: " + String(e)); } + return false; +}; + +FloatBallAppWM.prototype.cloneToolAppPageSnapshot = function(entry) { + if (!entry || typeof entry !== "object") return this.makeToolAppStackEntry("settings"); return { - route: String(route || "settings"), - settingsGroupKey: String(this.state.settingsGroupKey || "") + route: this.isToolAppRoute(entry.route) ? String(entry.route) : "settings", + settingsGroupKey: (entry.settingsGroupKey !== undefined && entry.settingsGroupKey !== null) ? String(entry.settingsGroupKey) : "", + settingsHomeSelectedItemId: (entry.settingsHomeSelectedItemId !== undefined) ? entry.settingsHomeSelectedItemId : null, + editingButtonIndex: (entry.editingButtonIndex !== undefined) ? entry.editingButtonIndex : null, + editingSchemaIndex: (entry.editingSchemaIndex !== undefined) ? entry.editingSchemaIndex : null, + keepBtnEditorState: !!entry.keepBtnEditorState, + keepSchemaEditorState: !!entry.keepSchemaEditorState, + toolAppSubRoute: (entry.toolAppSubRoute !== undefined) ? entry.toolAppSubRoute : null, + toolAppSubPage: (entry.toolAppSubPage !== undefined) ? entry.toolAppSubPage : null, + toolAppSubKey: (entry.toolAppSubKey !== undefined) ? entry.toolAppSubKey : null, + toolAppSubPayload: (entry.toolAppSubPayload !== undefined) ? entry.toolAppSubPayload : null }; }; FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) { var self = this; - var oldGroupKey = null; - var hasOldGroupKey = false; + var oldSnap = null; var r = "settings"; try { + oldSnap = this.captureToolAppPageSnapshot ? this.captureToolAppPageSnapshot(this.state.toolAppRoute || "settings") : null; + if (entry && typeof entry === "object") { + if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(entry); + r = this.isToolAppRoute(entry.route) ? String(entry.route) : "settings"; + } else { + r = this.isToolAppRoute(entry) ? String(entry) : "settings"; + if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(this.makeToolAppStackEntry(r)); + } var spec = null; try { spec = this.getToolAppResponsiveSpec ? this.getToolAppResponsiveSpec() : null; @@ -632,18 +696,6 @@ FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) { } var topBarHeight = spec ? spec.topBarHeight : this.dp(56); - oldGroupKey = this.state.settingsGroupKey; - hasOldGroupKey = true; - var groupKey = null; - if (entry && typeof entry === "object") { - r = this.isToolAppRoute(entry.route) ? String(entry.route) : "settings"; - if (entry.settingsGroupKey !== undefined && entry.settingsGroupKey !== null) groupKey = String(entry.settingsGroupKey); - } else { - r = this.isToolAppRoute(entry) ? String(entry) : "settings"; - } - if (r === "settings") this.state.settingsGroupKey = null; - else if (r === "settings_group") this.state.settingsGroupKey = groupKey !== null ? groupKey : String(oldGroupKey || ""); - var isDark = this.isDarkTheme(); var C = this.ui.colors; var T = this.getAnimalIslandTheme(); @@ -722,8 +774,8 @@ FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) { } catch (e) { safeLog(this.L, 'w', "build tool app preview body fail route=" + String(r || "") + " err=" + String(e)); } finally { - if (hasOldGroupKey) { - try { this.state.settingsGroupKey = oldGroupKey; } catch (eRestore) {} + if (oldSnap && this.applyToolAppPageSnapshot) { + try { this.applyToolAppPageSnapshot(oldSnap); } catch (eRestore) {} } } return null; @@ -1429,8 +1481,6 @@ FloatBallAppWM.prototype.showToolApp = function(route, resetStack) { } if (resetStack || !this.state.toolAppNavStack || !this.state.toolAppNavStack.length) { this.state.toolAppNavStack = [this.makeToolAppStackEntry(r)]; - } else { - this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = this.makeToolAppStackEntry(r); } var raw = this.buildPanelView(r); @@ -1470,7 +1520,12 @@ FloatBallAppWM.prototype.showToolApp = function(route, resetStack) { FloatBallAppWM.prototype.pushToolAppPage = function(route) { if (!this.isToolAppRoute(route)) return; if (!this.state.toolAppNavStack) this.state.toolAppNavStack = []; - this.state.toolAppNavStack.push(this.makeToolAppStackEntry(route)); + if (this.state.toolAppNavStack.length <= 0) { + this.state.toolAppNavStack.push(this.makeToolAppStackEntry(this.state.toolAppRoute || "settings")); + } + var nextEntry = this.makeToolAppStackEntry(route); + this.state.toolAppNavStack.push(nextEntry); + if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(nextEntry); this.showToolApp(route, false); }; @@ -1481,8 +1536,10 @@ FloatBallAppWM.prototype.pushToolAppSettingsGroup = function(groupKey) { FloatBallAppWM.prototype.replaceToolAppPage = function(route) { if (!this.isToolAppRoute(route)) return; - if (!this.state.toolAppNavStack || !this.state.toolAppNavStack.length) this.state.toolAppNavStack = [this.makeToolAppStackEntry(route)]; - else this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = this.makeToolAppStackEntry(route); + var entry = this.makeToolAppStackEntry(route); + if (!this.state.toolAppNavStack || !this.state.toolAppNavStack.length) this.state.toolAppNavStack = [entry]; + else this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = entry; + if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(entry); this.showToolApp(route, false); }; @@ -1493,27 +1550,22 @@ FloatBallAppWM.prototype.popToolAppPage = function(reason) { var specBack = this.getSettingsResponsiveSpec ? this.getSettingsResponsiveSpec() : null; if (curRoute === "settings" && specBack && specBack.useSideBySide && this.state.settingsHomeSelectedItemId) { this.state.settingsHomeSelectedItemId = null; + if (this.state.toolAppNavStack && this.state.toolAppNavStack.length > 0) { + this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = this.makeToolAppStackEntry("settings"); + } this.showToolApp("settings", false); return true; } } catch(ePaneBack) {} - if (curRoute === "btn_editor" && this.state.editingButtonIndex !== null && this.state.editingButtonIndex !== undefined) { - this.state.editingButtonIndex = null; - this.state.keepBtnEditorState = true; - } - if (curRoute === "schema_editor" && this.state.editingSchemaIndex !== null && this.state.editingSchemaIndex !== undefined) { - this.state.editingSchemaIndex = null; - this.state.keepSchemaEditorState = true; - } if (!this.state.toolAppNavStack || this.state.toolAppNavStack.length <= 1) { this.closeToolApp(); return true; } this.state.toolAppNavStack.pop(); var top = this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1]; - var nextRoute = top && top.route ? String(top.route) : "settings"; - if (nextRoute === "settings_group") this.state.settingsGroupKey = String((top && top.settingsGroupKey) ? top.settingsGroupKey : (this.state.settingsGroupKey || "")); - else this.state.settingsGroupKey = null; + var target = this.cloneToolAppPageSnapshot ? this.cloneToolAppPageSnapshot(top) : top; + var nextRoute = target && target.route ? String(target.route) : "settings"; + if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(target); this.showToolApp(nextRoute, false); return true; } catch (e) { diff --git a/manifest.json b/manifest.json index bd66107..be9f722 100644 --- a/manifest.json +++ b/manifest.json @@ -58,8 +58,8 @@ "size": 304993 }, "th_15_extra.js": { - "sha256": "5fcd5a8146c6bc68e8adc6660c9b12d1f918d7a5a83e00d745a7e18e34ad6f39", - "size": 112080 + "sha256": "97b3118f13328e9717f8931bec0c59fa2192f303aa5964cb483c9599a9d6ec02", + "size": 115930 }, "th_16_entry.js": { "sha256": "6c59d9891cd010647f84c3db93f1cf95c7bbfb758470ea21044bf72eb8ff73d1", @@ -68,5 +68,5 @@ }, "keyId": "toolhub-targets-2026-rsa3072", "schema": 2, - "version": 20260521224041 + "version": 20260521225420 } diff --git a/manifest.sig b/manifest.sig index 9001bba..026f8a5 100644 --- a/manifest.sig +++ b/manifest.sig @@ -1 +1 @@ -OcvlczPduvM0/xKzxRszzLAAOoXdCJ5vj0tf38jAHCYmPA+w0E2JSHIR3uSdr7tBNS42SeBnoHctm9PL00HyaytJvS/N+QIUo8oe6UWK5kVxx5xfeMqmwScGHV6tt93BVc03SwAKepaQZE0dBOFpsEGADwuoVHUEuwsFgRlc6Wl3UuGhcDVrALXgYlZBLy51fs8DmBHxK5CM26Oi2pLC/mI2VpwqMkx64VmsJtgbtVwQdFmwM2Y7tRUf9bGFkPld2gSvWyAAEk/Zul/6z61DHwCSmk0HIuIUb/yFBRxDtBhgQx50jUtKu6JEHhEMFe/eLkb/lfwXPmNIuoHIF89/t8Rf7k7cd5ZrolqeVR0uYcXlmJ3i8nadasnJn1NJh6YobbnmLOoC1NQm5mw2l8e0Q0B+5HEG2NyfxVHxgh1dIvGll2MroJqzpNMTeUW7adE3UBc/wgTO8s6MBAhs+lNLFikgtMvCEDczwymPOn2wBuRxrUY+Ni1UJveGcbNhmUUH +lHCOD29vBFlyfpr/VbWetJp809qyTfiuiRcRmP3KTTCyHDUgyAJSpnLiUaBPdI3y9841uz6M22OY9uL/2FlXnfLUtyimTM0EMJd5CL3EyY4LTNsoRZWb20CHz/DY0jBBH1lT03j3EM6kQgWijxeyh2ynHk79UQzuFtcrnCAYUYqh1Gu4SxJ/eAWVPJ5788gr2hiiDClCvaOY6QUPAifwJ5zBkDSx4+k9gfI4XSKnnJmqFpdjtj5cLsYUuRWzmIlvTV55JQgqtjrLUKSVdoAXEai6twmjbwLOTlq/kBDFB4w/kxT0cjHQgZCwYpIclo0drday2Qs1NKtIHi0AktisuZf7QXgp29kx6PWI7iQL0RRfxRqGUSN640k8q0QTZwgLB3OP7k5URVVQX1lCbgWJ+o4RBBaX9OjfNc6QNJV01keK069jVUgiBa2LPnp6gwzuSbTmaPglaKW4J7WWXUtitIAvZ/Ah+aa124XoSvxdRdpZPgvsHORycXhgN5Y4qTuG