mirror of https://github.com/espruino/BangleApps
[shadowclk] - Better settings and hour formatting
parent
f609e3e051
commit
d7f95a4ff5
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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": [{
|
||||
|
|
|
@ -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,9 +95,11 @@
|
|||
}
|
||||
|
||||
function writeTimeModeSetting() {
|
||||
if (sysSettings.clock && sysSettings.clock === "shadowclk.app.js") {
|
||||
sysSettings['12hour'] = appSettings.enable12Hour;
|
||||
require('Storage').writeJSON("setting.json", sysSettings);
|
||||
}
|
||||
}
|
||||
|
||||
function showMenu() {
|
||||
appSettings.theme = getCurrentTheme();
|
||||
|
|
Loading…
Reference in New Issue