Fix bug if using theme colors w/ modded g.setColor

master
stweedo 2023-06-18 19:11:48 -05:00
parent ce11203a12
commit c294a974e0
1 changed files with 22 additions and 10 deletions

View File

@ -9,7 +9,6 @@
let widgets = require("widget_utils"); let widgets = require("widget_utils");
let date = new Date(); let date = new Date();
let bgImage; let bgImage;
let configNumber = (storage.readJSON("boxclk.json", 1) || {}).selectedConfig || 0; let configNumber = (storage.readJSON("boxclk.json", 1) || {}).selectedConfig || 0;
let fileName = 'boxclk' + (configNumber > 0 ? `-${configNumber}` : '') + '.json'; let fileName = 'boxclk' + (configNumber > 0 ? `-${configNumber}` : '') + '.json';
// Add a condition to check if the file exists, if it does not, default to 'boxclk.json' // Add a condition to check if the file exists, if it does not, default to 'boxclk.json'
@ -17,12 +16,12 @@
fileName = 'boxclk.json'; fileName = 'boxclk.json';
} }
let boxesConfig = storage.readJSON(fileName, 1) || {}; let boxesConfig = storage.readJSON(fileName, 1) || {};
let boxes = {}; let boxes = {};
let boxPos = {}; let boxPos = {};
let isDragging = {}; let isDragging = {};
let wasDragging = {}; let wasDragging = {};
let doubleTapTimer = null; let doubleTapTimer = null;
let g_setColor;
let saveIcon = require("heatshrink").decompress(atob("mEwwkEogA/AHdP/4AK+gWVDBQWNAAIuVGBAIB+UQdhMfGBAHBCxUAgIXHIwPyCxQwEJAgXB+MAl/zBwQGBn8ggQjBGAQXG+EA/4XI/8gBIQXTGAMPC6n/C6HzkREBC6YACC6QAFC57aHCYIXOOgLsEn4XPABIX/C6vykQAEl6/WgCQBC5imFAAT2BC5gCBI4oUCC5x0IC/4X/C4K8Bl4XJ+TCCC4wKBABkvC4tEEoMQCxcBB4IWEC4XyDBUBFwIXGJAIAOIwowDABoWGGB4uHDBwWJAH4AzA")); let saveIcon = require("heatshrink").decompress(atob("mEwwkEogA/AHdP/4AK+gWVDBQWNAAIuVGBAIB+UQdhMfGBAHBCxUAgIXHIwPyCxQwEJAgXB+MAl/zBwQGBn8ggQjBGAQXG+EA/4XI/8gBIQXTGAMPC6n/C6HzkREBC6YACC6QAFC57aHCYIXOOgLsEn4XPABIX/C6vykQAEl6/WgCQBC5imFAAT2BC5gCBI4oUCC5x0IC/4X/C4K8Bl4XJ+TCCC4wKBABkvC4tEEoMQCxcBB4IWEC4XyDBUBFwIXGJAIAOIwowDABoWGGB4uHDBwWJAH4AzA"));
@ -97,7 +96,10 @@
// Overwrite the setColor function to allow the // Overwrite the setColor function to allow the
// use of (x) in g.theme.x as a string // use of (x) in g.theme.x as a string
// in your JSON config ("fg", "bg", "fg2", "bg2", "fgH", "bgH") // in your JSON config ("fg", "bg", "fg2", "bg2", "fgH", "bgH")
let g_setColor = g.setColor; let modSetColor = function() {
// Save the original setColor function
g_setColor = g.setColor;
// Overwrite setColor with the new function
g.setColor = function(color) { g.setColor = function(color) {
if (typeof color === "string" && color in g.theme) { if (typeof color === "string" && color in g.theme) {
g_setColor.call(g, g.theme[color]); g_setColor.call(g, g.theme[color]);
@ -105,6 +107,14 @@
g_setColor.call(g, color); g_setColor.call(g, color);
} }
}; };
};
let restoreSetColor = function() {
// Restore the original setColor function
if (g_setColor) {
g.setColor = g_setColor;
}
};
// Overwrite the drawString function // Overwrite the drawString function
let g_drawString = g.drawString; let g_drawString = g.drawString;
@ -243,8 +253,10 @@
Object.keys(isDragging).forEach((boxKey) => { Object.keys(isDragging).forEach((boxKey) => {
isDragging[boxKey] = false; isDragging[boxKey] = false;
}); });
restoreSetColor();
widgets.show(); widgets.show();
widgets.swipeOn(); widgets.swipeOn();
modSetColor();
}; };
/** /**
@ -339,8 +351,7 @@
delete Graphics.prototype.setFontBrunoAce; delete Graphics.prototype.setFontBrunoAce;
// Restore original drawString function (no outlines) // Restore original drawString function (no outlines)
g.drawString = g_drawString; g.drawString = g_drawString;
// Restore original setColor function (no string filtering) restoreSetColor();
g.setColor = g_setColor;
widgets.show(); widgets.show();
} }
}); });
@ -355,5 +366,6 @@
*/ */
Bangle.loadWidgets(); Bangle.loadWidgets();
widgets.swipeOn(); widgets.swipeOn();
modSetColor();
setup(); setup();
} }