Fix ToolApp back preview snapshots

This commit is contained in:
Hermes
2026-05-22 06:54:34 +08:00
parent 855352bfd9
commit 557950f692
3 changed files with 90 additions and 38 deletions

View File

@@ -611,19 +611,83 @@ FloatBallAppWM.prototype.hasToolAppBackTarget = function() {
return false; 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) { 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 { return {
route: String(route || "settings"), route: this.isToolAppRoute(entry.route) ? String(entry.route) : "settings",
settingsGroupKey: String(this.state.settingsGroupKey || "") 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) { FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) {
var self = this; var self = this;
var oldGroupKey = null; var oldSnap = null;
var hasOldGroupKey = false;
var r = "settings"; var r = "settings";
try { 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; var spec = null;
try { try {
spec = this.getToolAppResponsiveSpec ? this.getToolAppResponsiveSpec() : null; spec = this.getToolAppResponsiveSpec ? this.getToolAppResponsiveSpec() : null;
@@ -632,18 +696,6 @@ FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) {
} }
var topBarHeight = spec ? spec.topBarHeight : this.dp(56); 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 isDark = this.isDarkTheme();
var C = this.ui.colors; var C = this.ui.colors;
var T = this.getAnimalIslandTheme(); var T = this.getAnimalIslandTheme();
@@ -722,8 +774,8 @@ FloatBallAppWM.prototype.buildToolAppPreviewBody = function(entry) {
} catch (e) { } catch (e) {
safeLog(this.L, 'w', "build tool app preview body fail route=" + String(r || "") + " err=" + String(e)); safeLog(this.L, 'w', "build tool app preview body fail route=" + String(r || "") + " err=" + String(e));
} finally { } finally {
if (hasOldGroupKey) { if (oldSnap && this.applyToolAppPageSnapshot) {
try { this.state.settingsGroupKey = oldGroupKey; } catch (eRestore) {} try { this.applyToolAppPageSnapshot(oldSnap); } catch (eRestore) {}
} }
} }
return null; return null;
@@ -1429,8 +1481,6 @@ FloatBallAppWM.prototype.showToolApp = function(route, resetStack) {
} }
if (resetStack || !this.state.toolAppNavStack || !this.state.toolAppNavStack.length) { if (resetStack || !this.state.toolAppNavStack || !this.state.toolAppNavStack.length) {
this.state.toolAppNavStack = [this.makeToolAppStackEntry(r)]; this.state.toolAppNavStack = [this.makeToolAppStackEntry(r)];
} else {
this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = this.makeToolAppStackEntry(r);
} }
var raw = this.buildPanelView(r); var raw = this.buildPanelView(r);
@@ -1470,7 +1520,12 @@ FloatBallAppWM.prototype.showToolApp = function(route, resetStack) {
FloatBallAppWM.prototype.pushToolAppPage = function(route) { FloatBallAppWM.prototype.pushToolAppPage = function(route) {
if (!this.isToolAppRoute(route)) return; if (!this.isToolAppRoute(route)) return;
if (!this.state.toolAppNavStack) this.state.toolAppNavStack = []; 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); this.showToolApp(route, false);
}; };
@@ -1481,8 +1536,10 @@ FloatBallAppWM.prototype.pushToolAppSettingsGroup = function(groupKey) {
FloatBallAppWM.prototype.replaceToolAppPage = function(route) { FloatBallAppWM.prototype.replaceToolAppPage = function(route) {
if (!this.isToolAppRoute(route)) return; if (!this.isToolAppRoute(route)) return;
if (!this.state.toolAppNavStack || !this.state.toolAppNavStack.length) this.state.toolAppNavStack = [this.makeToolAppStackEntry(route)]; var entry = this.makeToolAppStackEntry(route);
else this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1] = 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); this.showToolApp(route, false);
}; };
@@ -1493,27 +1550,22 @@ FloatBallAppWM.prototype.popToolAppPage = function(reason) {
var specBack = this.getSettingsResponsiveSpec ? this.getSettingsResponsiveSpec() : null; var specBack = this.getSettingsResponsiveSpec ? this.getSettingsResponsiveSpec() : null;
if (curRoute === "settings" && specBack && specBack.useSideBySide && this.state.settingsHomeSelectedItemId) { if (curRoute === "settings" && specBack && specBack.useSideBySide && this.state.settingsHomeSelectedItemId) {
this.state.settingsHomeSelectedItemId = null; 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); this.showToolApp("settings", false);
return true; return true;
} }
} catch(ePaneBack) {} } 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) { if (!this.state.toolAppNavStack || this.state.toolAppNavStack.length <= 1) {
this.closeToolApp(); this.closeToolApp();
return true; return true;
} }
this.state.toolAppNavStack.pop(); this.state.toolAppNavStack.pop();
var top = this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1]; var top = this.state.toolAppNavStack[this.state.toolAppNavStack.length - 1];
var nextRoute = top && top.route ? String(top.route) : "settings"; var target = this.cloneToolAppPageSnapshot ? this.cloneToolAppPageSnapshot(top) : top;
if (nextRoute === "settings_group") this.state.settingsGroupKey = String((top && top.settingsGroupKey) ? top.settingsGroupKey : (this.state.settingsGroupKey || "")); var nextRoute = target && target.route ? String(target.route) : "settings";
else this.state.settingsGroupKey = null; if (this.applyToolAppPageSnapshot) this.applyToolAppPageSnapshot(target);
this.showToolApp(nextRoute, false); this.showToolApp(nextRoute, false);
return true; return true;
} catch (e) { } catch (e) {

View File

@@ -58,8 +58,8 @@
"size": 304993 "size": 304993
}, },
"th_15_extra.js": { "th_15_extra.js": {
"sha256": "5fcd5a8146c6bc68e8adc6660c9b12d1f918d7a5a83e00d745a7e18e34ad6f39", "sha256": "97b3118f13328e9717f8931bec0c59fa2192f303aa5964cb483c9599a9d6ec02",
"size": 112080 "size": 115930
}, },
"th_16_entry.js": { "th_16_entry.js": {
"sha256": "6c59d9891cd010647f84c3db93f1cf95c7bbfb758470ea21044bf72eb8ff73d1", "sha256": "6c59d9891cd010647f84c3db93f1cf95c7bbfb758470ea21044bf72eb8ff73d1",
@@ -68,5 +68,5 @@
}, },
"keyId": "toolhub-targets-2026-rsa3072", "keyId": "toolhub-targets-2026-rsa3072",
"schema": 2, "schema": 2,
"version": 20260521224041 "version": 20260521225420
} }

View File

@@ -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