From d7f95a4ff59fd9b090eba9fc0067f8d9f538bac1 Mon Sep 17 00:00:00 2001 From: stweedo <108593831+stweedo@users.noreply.github.com> Date: Wed, 31 May 2023 02:10:07 -0500 Subject: [PATCH] [shadowclk] - Better settings and hour formatting --- apps/shadowclk/ChangeLog | 1 + apps/shadowclk/app.js | 26 ++++++-------------------- apps/shadowclk/metadata.json | 4 ++-- apps/shadowclk/settings.js | 24 ++++++++++++++++++------ 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/apps/shadowclk/ChangeLog b/apps/shadowclk/ChangeLog index 7ba343b2f..ce2933f0c 100644 --- a/apps/shadowclk/ChangeLog +++ b/apps/shadowclk/ChangeLog @@ -1,3 +1,4 @@ 0.01: New App! 0.02: New 'Settings Menu' to choose your favorite color and switch between light or dark themes 0.03: New 'Leading Zero' and 'Date Suffix' options in 'Settings Menu' +0.04: Updated settings menu to better maintain app settings and system settings diff --git a/apps/shadowclk/app.js b/apps/shadowclk/app.js index 7ffdc4683..dd47caf7b 100644 --- a/apps/shadowclk/app.js +++ b/apps/shadowclk/app.js @@ -37,7 +37,6 @@ let color = appSettings.color !== undefined ? appSettings.color : "#0ff"; let enableLeadingZero = appSettings.enableLeadingZero !== undefined ? appSettings.enableLeadingZero : false; let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSuffix : true; -// Draw the time and date (function () { let drawTimeout; @@ -46,30 +45,17 @@ let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSu var y = g.getHeight() / 2; g.reset().clearRect(Bangle.appRect); var date = new Date(); - var hour = date.getHours(); - var minutes = String(date.getMinutes()).padStart(2, '0'); + var locale = require("locale"); + var timeStr = locale.time(date, 1); - // Handle 12-hour format - if (is12Hour) { - hour = hour % 12 || 12; // Convert 0 to 12 for 12-hour format - } else { - // If the leading zero option is enabled and hour is less than 10, add leading zero - if (enableLeadingZero && hour < 10) { - hour = '0' + hour; - } - } - - var timeStr = hour + ':' + minutes; - - // Handle midnight in 12-hour format specifically - if (is12Hour && hour === 0) { - timeStr = '12' + timeStr.substring(2); + // If 24-hour format and leading zero should be removed + if (!is12Hour && !enableLeadingZero && timeStr.charAt(0) === '0') { + timeStr = timeStr.substr(1); } g.setFontAlign(0, 0).setFont("LondrinaSolid").setColor(color).drawString(timeStr, x - 1, y); g.reset().setFontAlign(0, 0).setFont("LondrinaShadow").drawString(timeStr, x - 1, y); - var locale = require("locale"); var dayOfMonth = date.getDate(); var month = locale.month(date, 1).slice(0, 1).toUpperCase() + locale.month(date, 1).slice(1).toLowerCase(); var year = date.getFullYear(); @@ -110,4 +96,4 @@ let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSu Bangle.loadWidgets(); draw(); setTimeout(Bangle.drawWidgets, 0); -})(); \ No newline at end of file +})(); diff --git a/apps/shadowclk/metadata.json b/apps/shadowclk/metadata.json index 4e47b9845..432558b95 100644 --- a/apps/shadowclk/metadata.json +++ b/apps/shadowclk/metadata.json @@ -1,7 +1,7 @@ { "id": "shadowclk", "name": "Shadow Clock", - "version": "0.03", + "version": "0.04", "description": "A simple clock using the Londrina font in color with a shadowed outline. Based on the Anton Clock.", "icon": "app.png", "screenshots": [{ @@ -32,4 +32,4 @@ "data": [{ "name": "shadowclk.json" }] -} \ No newline at end of file +} diff --git a/apps/shadowclk/settings.js b/apps/shadowclk/settings.js index 21b4826a5..af94c8494 100644 --- a/apps/shadowclk/settings.js +++ b/apps/shadowclk/settings.js @@ -9,9 +9,18 @@ theme: 'light', enableSuffix: true, enableLeadingZero: false, - enable12Hour: false // default time mode + enable12Hour: false }, require('Storage').readJSON("shadowclk.json", true) || {}); + // Check if shadowclk is the selected clock + if (sysSettings.clock === "shadowclk.app.js") { + // Sync app settings with system settings + appSettings.theme = sysSettings.theme.dark ? 'dark' : 'light'; + if (sysSettings['12hour'] !== undefined) { + appSettings.enable12Hour = sysSettings['12hour']; + } + } + // Colors from 'Light BW' and 'Dark BW' themes function createThemeColors(mode) { let cl = x => g.setColor(x).getColor(); @@ -37,9 +46,10 @@ // Switch theme and save to storage function switchTheme(mode) { if (mode === g.theme.dark) return; - let s = require('Storage').readJSON("setting.json", 1) || {}; - s.theme = createThemeColors(mode); - require('Storage').writeJSON("setting.json", s); + sysSettings.theme = createThemeColors(mode); + if (sysSettings.clock && sysSettings.clock === "shadowclk.app.js") { + require('Storage').writeJSON("setting.json", sysSettings); + } updateTheme(mode); } @@ -85,8 +95,10 @@ } function writeTimeModeSetting() { - sysSettings['12hour'] = appSettings.enable12Hour; - require('Storage').writeJSON("setting.json", sysSettings); + if (sysSettings.clock && sysSettings.clock === "shadowclk.app.js") { + sysSettings['12hour'] = appSettings.enable12Hour; + require('Storage').writeJSON("setting.json", sysSettings); + } } function showMenu() {