fix(color-picker): 修复颜色参数回写失败问题

根因: Rhino JS 闭包中局部变量捕获异常,onSelect 回调无法访问 inputShortXIconTint

修复:
- 将输入框引用存储到 self.state._btnEditorTintInput,绕过闭包问题
- onSelect 回调从 self.state 读取输入框,同时直接更新 targetBtn.iconTint 作为双保险
- 保存按钮优先使用 targetBtn.iconTint,回退到输入框 getValue()
This commit is contained in:
Hermes
2026-04-20 21:00:13 +08:00
parent d03f4d677f
commit 4ab42b274a

View File

@@ -935,10 +935,15 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
onSelect: function(colorHex) { onSelect: function(colorHex) {
try { try {
var safeColor = String(colorHex || ""); var safeColor = String(colorHex || "");
if (inputShortXIconTint && inputShortXIconTint.input) { // # 避免 Rhino 闭包问题:从 self.state 读取输入框引用
inputShortXIconTint.input.setText(safeColor); var tintInput = self.state._btnEditorTintInput || inputShortXIconTint;
try { inputShortXIconTint.input.invalidate(); } catch(e) {} if (tintInput && tintInput.input) {
tintInput.input.setText(safeColor);
try { tintInput.input.invalidate(); } catch(e) {}
} }
// # 双保险:直接更新 targetBtn确保保存时能拿到正确值
if (safeColor) targetBtn.iconTint = safeColor;
else delete targetBtn.iconTint;
try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {} try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {}
} catch(eSelect) { } catch(eSelect) {
safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect)); safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect));
@@ -1254,6 +1259,8 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
var defaultTint = targetBtn.iconTint ? String(targetBtn.iconTint) : ""; var defaultTint = targetBtn.iconTint ? String(targetBtn.iconTint) : "";
var inputShortXIconTint = self.ui.createInputGroup(self, "图标颜色 (留空跟随主题)", defaultTint, false, "支持 #RRGGBB / #AARRGGBB下方可展开完整调色板"); var inputShortXIconTint = self.ui.createInputGroup(self, "图标颜色 (留空跟随主题)", defaultTint, false, "支持 #RRGGBB / #AARRGGBB下方可展开完整调色板");
form.addView(inputShortXIconTint.view); form.addView(inputShortXIconTint.view);
// # 避免 Rhino 闭包问题:将输入框引用存储到 self.state供颜色选择器回调使用
self.state._btnEditorTintInput = inputShortXIconTint;
function updateTintPaletteToggleText() { function updateTintPaletteToggleText() {
try { try {
@@ -1499,10 +1506,15 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() {
onSelect: function(colorHex) { onSelect: function(colorHex) {
try { try {
var safeColor = String(colorHex || ""); var safeColor = String(colorHex || "");
if (inputShortXIconTint && inputShortXIconTint.input) { // # 避免 Rhino 闭包问题:从 self.state 读取输入框引用
inputShortXIconTint.input.setText(safeColor); var tintInput = self.state._btnEditorTintInput || inputShortXIconTint;
try { inputShortXIconTint.input.invalidate(); } catch(e) {} if (tintInput && tintInput.input) {
tintInput.input.setText(safeColor);
try { tintInput.input.invalidate(); } catch(e) {}
} }
// # 双保险:直接更新 targetBtn确保保存时能拿到正确值
if (safeColor) targetBtn.iconTint = safeColor;
else delete targetBtn.iconTint;
try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {} try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {}
} catch(eSelect) { } catch(eSelect) {
safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect)); safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect));
@@ -3314,8 +3326,11 @@ shortcutWrap.addView(scBody);
} else { } else {
var sxIcon = self.normalizeShortXIconName(currentShortXIconName, false); var sxIcon = self.normalizeShortXIconName(currentShortXIconName, false);
if (sxIcon) newBtn.iconResName = sxIcon; else delete newBtn.iconResName; if (sxIcon) newBtn.iconResName = sxIcon; else delete newBtn.iconResName;
// 保存 ShortX 图标颜色 // # 保存 ShortX 图标颜色:优先使用 targetBtn.iconTint颜色选择器已更新回退到输入框
var sxTint = inputShortXIconTint.getValue(); var sxTint = targetBtn.iconTint || "";
if (!sxTint) {
try { sxTint = inputShortXIconTint.getValue(); } catch(eGetTint) {}
}
if (sxTint && sxTint.length > 0) newBtn.iconTint = sxTint; else delete newBtn.iconTint; if (sxTint && sxTint.length > 0) newBtn.iconTint = sxTint; else delete newBtn.iconTint;
delete newBtn.iconPath; // 清除文件路径 delete newBtn.iconPath; // 清除文件路径
} }