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.01: New App!
|
||||||
0.02: New 'Settings Menu' to choose your favorite color and switch between light or dark themes
|
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.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 enableLeadingZero = appSettings.enableLeadingZero !== undefined ? appSettings.enableLeadingZero : false;
|
||||||
let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSuffix : true;
|
let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSuffix : true;
|
||||||
|
|
||||||
// Draw the time and date
|
|
||||||
(function () {
|
(function () {
|
||||||
let drawTimeout;
|
let drawTimeout;
|
||||||
|
|
||||||
|
@ -46,30 +45,17 @@ let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSu
|
||||||
var y = g.getHeight() / 2;
|
var y = g.getHeight() / 2;
|
||||||
g.reset().clearRect(Bangle.appRect);
|
g.reset().clearRect(Bangle.appRect);
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
var hour = date.getHours();
|
var locale = require("locale");
|
||||||
var minutes = String(date.getMinutes()).padStart(2, '0');
|
var timeStr = locale.time(date, 1);
|
||||||
|
|
||||||
// Handle 12-hour format
|
// If 24-hour format and leading zero should be removed
|
||||||
if (is12Hour) {
|
if (!is12Hour && !enableLeadingZero && timeStr.charAt(0) === '0') {
|
||||||
hour = hour % 12 || 12; // Convert 0 to 12 for 12-hour format
|
timeStr = timeStr.substr(1);
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setFontAlign(0, 0).setFont("LondrinaSolid").setColor(color).drawString(timeStr, x - 1, y);
|
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);
|
g.reset().setFontAlign(0, 0).setFont("LondrinaShadow").drawString(timeStr, x - 1, y);
|
||||||
|
|
||||||
var locale = require("locale");
|
|
||||||
var dayOfMonth = date.getDate();
|
var dayOfMonth = date.getDate();
|
||||||
var month = locale.month(date, 1).slice(0, 1).toUpperCase() + locale.month(date, 1).slice(1).toLowerCase();
|
var month = locale.month(date, 1).slice(0, 1).toUpperCase() + locale.month(date, 1).slice(1).toLowerCase();
|
||||||
var year = date.getFullYear();
|
var year = date.getFullYear();
|
||||||
|
@ -110,4 +96,4 @@ let enableSuffix = appSettings.enableSuffix !== undefined ? appSettings.enableSu
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
draw();
|
draw();
|
||||||
setTimeout(Bangle.drawWidgets, 0);
|
setTimeout(Bangle.drawWidgets, 0);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "shadowclk",
|
"id": "shadowclk",
|
||||||
"name": "Shadow Clock",
|
"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.",
|
"description": "A simple clock using the Londrina font in color with a shadowed outline. Based on the Anton Clock.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"screenshots": [{
|
"screenshots": [{
|
||||||
|
@ -32,4 +32,4 @@
|
||||||
"data": [{
|
"data": [{
|
||||||
"name": "shadowclk.json"
|
"name": "shadowclk.json"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,18 @@
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
enableSuffix: true,
|
enableSuffix: true,
|
||||||
enableLeadingZero: false,
|
enableLeadingZero: false,
|
||||||
enable12Hour: false // default time mode
|
enable12Hour: false
|
||||||
}, require('Storage').readJSON("shadowclk.json", true) || {});
|
}, 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
|
// Colors from 'Light BW' and 'Dark BW' themes
|
||||||
function createThemeColors(mode) {
|
function createThemeColors(mode) {
|
||||||
let cl = x => g.setColor(x).getColor();
|
let cl = x => g.setColor(x).getColor();
|
||||||
|
@ -37,9 +46,10 @@
|
||||||
// Switch theme and save to storage
|
// Switch theme and save to storage
|
||||||
function switchTheme(mode) {
|
function switchTheme(mode) {
|
||||||
if (mode === g.theme.dark) return;
|
if (mode === g.theme.dark) return;
|
||||||
let s = require('Storage').readJSON("setting.json", 1) || {};
|
sysSettings.theme = createThemeColors(mode);
|
||||||
s.theme = createThemeColors(mode);
|
if (sysSettings.clock && sysSettings.clock === "shadowclk.app.js") {
|
||||||
require('Storage').writeJSON("setting.json", s);
|
require('Storage').writeJSON("setting.json", sysSettings);
|
||||||
|
}
|
||||||
updateTheme(mode);
|
updateTheme(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +95,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeTimeModeSetting() {
|
function writeTimeModeSetting() {
|
||||||
sysSettings['12hour'] = appSettings.enable12Hour;
|
if (sysSettings.clock && sysSettings.clock === "shadowclk.app.js") {
|
||||||
require('Storage').writeJSON("setting.json", sysSettings);
|
sysSettings['12hour'] = appSettings.enable12Hour;
|
||||||
|
require('Storage').writeJSON("setting.json", sysSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMenu() {
|
function showMenu() {
|
||||||
|
|
Loading…
Reference in New Issue