Merge pull request #2789 from stweedo/shadowclk

[shadowclk] - Better settings and hour formatting
pull/2799/head
Gordon Williams 2023-06-05 09:39:18 +01:00 committed by GitHub
commit 6cc74bb4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 28 deletions

View File

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

View File

@ -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);
})();
})();

View File

@ -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"
}]
}
}

View File

@ -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 === "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 === "shadowclk.app.js") {
sysSettings['12hour'] = appSettings.enable12Hour;
require('Storage').writeJSON("setting.json", sysSettings);
}
}
function showMenu() {