tileclk: Convert nearly all functions to arrow syntax for memory savings
parent
efbe79b51d
commit
e4aa9ed930
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
|
|
||||||
// ===== STATE PERSISTENCE =====
|
// ===== STATE PERSISTENCE =====
|
||||||
function loadDisplayState() {
|
const loadDisplayState = () => {
|
||||||
const state = require('Storage').readJSON("tileclk.state.json", true) || {};
|
const state = require('Storage').readJSON("tileclk.state.json", true) || {};
|
||||||
showingClockInfo = state.showingClockInfo || false;
|
showingClockInfo = state.showingClockInfo || false;
|
||||||
userClockInfoPreference = state.userClockInfoPreference || null;
|
userClockInfoPreference = state.userClockInfoPreference || null;
|
||||||
|
|
@ -47,7 +47,7 @@
|
||||||
initialUserClockInfoPreference = userClockInfoPreference;
|
initialUserClockInfoPreference = userClockInfoPreference;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveDisplayState() {
|
const saveDisplayState = () => {
|
||||||
// Only save if values have changed to reduce flash wear
|
// Only save if values have changed to reduce flash wear
|
||||||
if (showingClockInfo !== initialShowingClockInfo ||
|
if (showingClockInfo !== initialShowingClockInfo ||
|
||||||
userClockInfoPreference !== initialUserClockInfoPreference) {
|
userClockInfoPreference !== initialUserClockInfoPreference) {
|
||||||
|
|
@ -218,11 +218,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== ANIMATION FUNCTIONS =====
|
// ===== ANIMATION FUNCTIONS =====
|
||||||
function animateTransition(x, y, s, startColor, endColor, drawBorderFunc, callback) {
|
const animateTransition = (x, y, s, startColor, endColor, drawBorderFunc, callback) => {
|
||||||
let step = 0;
|
let step = 0;
|
||||||
const colors = startColor === g.theme.bg ? colorOn : colorOff;
|
const colors = startColor === g.theme.bg ? colorOn : colorOff;
|
||||||
|
|
||||||
function transition() {
|
const transition = () => {
|
||||||
if (!isDrawing || (pendingSwitch && isSeconds)) return;
|
if (!isDrawing || (pendingSwitch && isSeconds)) return;
|
||||||
|
|
||||||
// Use pre-calculated color
|
// Use pre-calculated color
|
||||||
|
|
@ -246,12 +246,12 @@
|
||||||
transition();
|
transition();
|
||||||
}
|
}
|
||||||
|
|
||||||
function animateTileOn(x, y, s, callback, isMainDigit) {
|
const animateTileOn = (x, y, s, callback, isMainDigit) => {
|
||||||
const borderFunc = showBorders ? () => drawBorder(x, y, s, isMainDigit) : null;
|
const borderFunc = showBorders ? () => drawBorder(x, y, s, isMainDigit) : null;
|
||||||
animateTransition(x, y, s, g.theme.bg, g.theme.fg, borderFunc, callback);
|
animateTransition(x, y, s, g.theme.bg, g.theme.fg, borderFunc, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function animateTileOff(x, y, s, callback) {
|
const animateTileOff = (x, y, s, callback) => {
|
||||||
animateTransition(x, y, s, g.theme.fg, g.theme.bg, null, callback);
|
animateTransition(x, y, s, g.theme.fg, g.theme.bg, null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== TILE UPDATE =====
|
// ===== TILE UPDATE =====
|
||||||
function updateTile(tile, s, skipAnimation, isMainDigit, isClearing) {
|
const updateTile = (tile, s, skipAnimation, isMainDigit, isClearing) => {
|
||||||
if (tile.state) {
|
if (tile.state) {
|
||||||
if (skipAnimation) {
|
if (skipAnimation) {
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
|
|
@ -300,7 +300,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTiles(tiles, s, callback, skipAnimation, isMainDigit, isClearing) {
|
const updateTiles = (tiles, s, callback, skipAnimation, isMainDigit, isClearing) => {
|
||||||
if (!isDrawing || !tiles.length || (pendingSwitch && isSeconds)) {
|
if (!isDrawing || !tiles.length || (pendingSwitch && isSeconds)) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
|
|
@ -314,7 +314,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== DIGIT DRAWING =====
|
// ===== DIGIT DRAWING =====
|
||||||
function drawDigit(x, y, s, num, prevNum, callback, skipAnimation, isMainDigit) {
|
const drawDigit = (x, y, s, num, prevNum, callback, skipAnimation, isMainDigit) => {
|
||||||
if (num === prevNum) {
|
if (num === prevNum) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
|
|
@ -330,7 +330,7 @@
|
||||||
updateTiles(tiles, s, callback, skipAnimation, isMainDigit, num === null);
|
updateTiles(tiles, s, callback, skipAnimation, isMainDigit, num === null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawColon(x, y, callback) {
|
const drawColon = (x, y, callback) => {
|
||||||
if (!isDrawing || isColonDrawn) {
|
if (!isDrawing || isColonDrawn) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
|
|
@ -344,7 +344,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== TIME UPDATE SCHEDULING =====
|
// ===== TIME UPDATE SCHEDULING =====
|
||||||
function scheduleNextUpdate() {
|
const scheduleNextUpdate = () => {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const msUntilNextMinute = (60 - now.getSeconds()) * 1000 - now.getMilliseconds();
|
const msUntilNextMinute = (60 - now.getSeconds()) * 1000 - now.getMilliseconds();
|
||||||
|
|
@ -353,7 +353,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== CLEARING FUNCTIONS (Direct callback approach for performance) =====
|
// ===== CLEARING FUNCTIONS (Direct callback approach for performance) =====
|
||||||
function clearColon(callback) {
|
const clearColon = (callback) => {
|
||||||
if (!isColonDrawn) {
|
if (!isColonDrawn) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
|
|
@ -374,14 +374,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAllDigits(callback) {
|
const clearAllDigits = (callback) => {
|
||||||
const wasThreeDigit = is12Hour && lastTime !== null && lastTime < 1000;
|
const wasThreeDigit = is12Hour && lastTime !== null && lastTime < 1000;
|
||||||
const layout = wasThreeDigit ? threeDigitLayout : fourDigitLayout;
|
const layout = wasThreeDigit ? threeDigitLayout : fourDigitLayout;
|
||||||
|
|
||||||
const previousDigits = extractTimeDigits(lastTime);
|
const previousDigits = extractTimeDigits(lastTime);
|
||||||
|
|
||||||
// Direct callback chaining for better performance
|
// Direct callback chaining for better performance
|
||||||
function clearItems(items, next) {
|
const clearItems = (items, next) => {
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
|
|
@ -600,11 +600,11 @@
|
||||||
updateDigit(0);
|
updateDigit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawSecondDigit(index, digit, prevDigit, callback, skipAnimation) {
|
const drawSecondDigit = (index, digit, prevDigit, callback, skipAnimation) => {
|
||||||
drawDigit(positions.seconds.x[index], positions.seconds.y + widgetYOffset, SEC_SCALE, digit, prevDigit, callback, skipAnimation, false);
|
drawDigit(positions.seconds.x[index], positions.seconds.y + widgetYOffset, SEC_SCALE, digit, prevDigit, callback, skipAnimation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearSeconds(callback) {
|
const clearSeconds = (callback) => {
|
||||||
// If not drawing seconds, just call callback
|
// If not drawing seconds, just call callback
|
||||||
if (lastSeconds === null) {
|
if (lastSeconds === null) {
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
|
|
@ -639,7 +639,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== ANIMATION CLEANUP =====
|
// ===== ANIMATION CLEANUP =====
|
||||||
function cancelAllAnimations() {
|
const cancelAllAnimations = () => {
|
||||||
// Use typed array for better performance
|
// Use typed array for better performance
|
||||||
for (let i = 0; i < animationTimeoutCount; i++) {
|
for (let i = 0; i < animationTimeoutCount; i++) {
|
||||||
clearTimeout(animationTimeouts[i]);
|
clearTimeout(animationTimeouts[i]);
|
||||||
|
|
@ -648,7 +648,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== SWITCHING FUNCTIONS (Optimized with direct state changes) =====
|
// ===== SWITCHING FUNCTIONS (Optimized with direct state changes) =====
|
||||||
function switchToClockInfo() {
|
const switchToClockInfo = () => {
|
||||||
if (showingClockInfo || !clockInfoMenu) {
|
if (showingClockInfo || !clockInfoMenu) {
|
||||||
pendingSwitch = false;
|
pendingSwitch = false;
|
||||||
return;
|
return;
|
||||||
|
|
@ -691,7 +691,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideClockInfo() {
|
const hideClockInfo = () => {
|
||||||
if (!showingClockInfo) return;
|
if (!showingClockInfo) return;
|
||||||
|
|
||||||
pendingSwitch = false;
|
pendingSwitch = false;
|
||||||
|
|
@ -704,7 +704,7 @@
|
||||||
g.flip();
|
g.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchToSeconds() {
|
const switchToSeconds = () => {
|
||||||
if (!showingClockInfo || !showSeconds) return;
|
if (!showingClockInfo || !showSeconds) return;
|
||||||
|
|
||||||
pendingSwitch = false;
|
pendingSwitch = false;
|
||||||
|
|
@ -722,7 +722,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== TOUCH HANDLING =====
|
// ===== TOUCH HANDLING =====
|
||||||
function setupTouchHandler() {
|
const setupTouchHandler = () => {
|
||||||
// Remove old handler if exists
|
// Remove old handler if exists
|
||||||
if (touchHandler) {
|
if (touchHandler) {
|
||||||
Bangle.removeListener("touch", touchHandler);
|
Bangle.removeListener("touch", touchHandler);
|
||||||
|
|
@ -785,7 +785,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== CLOCK INFO SETUP =====
|
// ===== CLOCK INFO SETUP =====
|
||||||
function setupClockInfo() {
|
const setupClockInfo = () => {
|
||||||
if (clockInfoMenu) return;
|
if (clockInfoMenu) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -845,7 +845,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== MAIN CLOCK DRAW =====
|
// ===== MAIN CLOCK DRAW =====
|
||||||
function drawClock() {
|
const drawClock = () => {
|
||||||
g.clear(Bangle.appRect);
|
g.clear(Bangle.appRect);
|
||||||
if (settings.widgets !== "hide") Bangle.drawWidgets();
|
if (settings.widgets !== "hide") Bangle.drawWidgets();
|
||||||
lastTime = null;
|
lastTime = null;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
haptics: true
|
haptics: true
|
||||||
}, require("Storage").readJSON("tileclk.json", true) || {});
|
}, require("Storage").readJSON("tileclk.json", true) || {});
|
||||||
|
|
||||||
function writeSettings() {
|
const writeSettings = () => {
|
||||||
require("Storage").writeJSON("tileclk.json", appSettings);
|
require("Storage").writeJSON("tileclk.json", appSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
"Yellow": "#FFFF00"
|
"Yellow": "#FFFF00"
|
||||||
};
|
};
|
||||||
|
|
||||||
function showMenu() {
|
const showMenu = () => {
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
"": { "title": "Tile Clock" },
|
"": { "title": "Tile Clock" },
|
||||||
"< Back": () => back(),
|
"< Back": () => back(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue