From 3f1ded53ede093c29023a96541eb0738d3f04f25 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 2 May 2023 19:33:29 +0200 Subject: [PATCH 01/14] calendar: Read day names from locale --- apps/calendar/calendar.js | 65 ++++----------------------------------- 1 file changed, 6 insertions(+), 59 deletions(-) diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index 6aab1aecd..ffe3084e6 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -55,65 +55,12 @@ if (settings.ndColors === true) { } function getDowLbls(locale) { - let dowLbls; - //TODO: Find some clever way to generate this programmatically from locale lib - switch (locale) { - case "de_AT": - case "de_CH": - case "de_DE": - if (startOnSun) { - dowLbls = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]; - } else { - dowLbls = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]; - } - break; - case "nl_NL": - if (startOnSun) { - dowLbls = ["zo", "ma", "di", "wo", "do", "vr", "za"]; - } else { - dowLbls = ["ma", "di", "wo", "do", "vr", "za", "zo"]; - } - break; - case "fr_BE": - case "fr_CH": - case "fr_FR": - if (startOnSun) { - dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"]; - } - break; - case "sv_SE": - if (startOnSun) { - dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"]; - } - break; - case "it_CH": - case "it_IT": - if (startOnSun) { - dowLbls = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"]; - } - break; - case "oc_FR": - if (startOnSun) { - dowLbls = ["dg", "dl", "dm", "dc", "dj", "dv", "ds"]; - } else { - dowLbls = ["dl", "dm", "dc", "dj", "dv", "ds", "dg"]; - } - break; - default: - if (startOnSun) { - dowLbls = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; - } else { - dowLbls = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]; - } - break; - } - return dowLbls; + let days = startOnSun ? [0, 1, 2, 3, 4, 5, 6] : [1, 2, 3, 4, 5, 6, 0]; + const d = new Date(); + return days.map(i => { + d.setDate(d.getDate() + (i + 7 - d.getDay()) % 7); + return require("locale").dow(d, 1); + }); } function sameDay(d1, d2) { From aa6d7cdbe197f8c8dde64699372f8c445aa7583f Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 2 May 2023 20:03:58 +0200 Subject: [PATCH 02/14] calendar: Display holidays --- apps/calendar/ChangeLog | 1 + apps/calendar/calendar.js | 47 ++++++++++++++++++++++--------------- apps/calendar/metadata.json | 2 +- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index 27e1e2517..c7902e263 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -13,3 +13,4 @@ 0.12: Mark dated events on a day 0.13: Switch to swipe left/right for month and up/down for year selection Display events for current month on touch +0.14: Add support for holidays diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index ffe3084e6..92e3428ba 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -36,7 +36,12 @@ const events = (require("Storage").readJSON("sched.json",1) || []).filter(a => a date.setHours(time.h); date.setMinutes(time.m); date.setSeconds(time.s); - return {date: date, msg: a.msg}; + return {date: date, msg: a.msg, type: "e"}; +}); +// add holidays +(require("Storage").readJSON("calendar.holiday.json",1) || []).forEach(h => { + const date = new Date(h.date); + events.push({date: date, msg: h.name, type: "h"}); }); events.sort((a,b) => a.date - b.date); @@ -167,6 +172,27 @@ function drawCalendar(date) { const y1 = y * rowH + headerH + rowH; const x2 = x * colW + colW; const y2 = y * rowH + headerH + rowH + rowH; + + if (eventsThisMonth.length > 0) { + // Display events for this day + eventsThisMonth.forEach((ev, idx) => { + if (sameDay(ev.date, curDay)) { + if (ev.type === "e") { // alarm/event + const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; + const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 + const height = (y2-2) - (y1+2); // height of a cell + const sliceHeight = height/eventsPerDay; + const ystart = (y1+2) + slice*sliceHeight; + g.setColor(bgEvent).fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); + } else if (ev.type === "h") { // holiday + g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1); + } + + eventsThisMonth.splice(idx, 1); // this event is no longer needed + } + }); + } + if (isToday) { g.setColor(red); g.drawRect(x1, y1, x2, y2); @@ -178,23 +204,6 @@ function drawCalendar(date) { ); } - if (eventsThisMonth.length > 0) { - // Display events for this day - g.setColor(bgEvent); - eventsThisMonth.forEach((ev, idx) => { - if (sameDay(ev.date, curDay)) { - const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; - const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 - const height = (y2-2) - (y1+2); // height of a cell - const sliceHeight = height/eventsPerDay; - const ystart = (y1+2) + slice*sliceHeight; - g.fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); - - eventsThisMonth.splice(idx, 1); // this event is no longer needed - } - }); - } - require("Font8x12").add(Graphics); g.setFont("8x12", fontSize); g.setColor(day < 50 ? fgOtherMonth : fgSameMonth); @@ -236,7 +245,7 @@ function setUI() { const menu = events.filter(ev => ev.date.getFullYear() === date.getFullYear() && ev.date.getMonth() === date.getMonth()).map(e => { const dateStr = require("locale").date(e.date, 1); const timeStr = require("locale").time(e.date, 1); - return { title: `${dateStr} ${timeStr}` + (e.msg ? " " + e.msg : "") }; + return { title: `${dateStr} ${e.type === "e" ? timeStr : ""}` + (e.msg ? " " + e.msg : "") }; }); if (menu.length === 0) { menu.push({title: /*LANG*/"No events"}); diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index 87599e3f4..bf5c67b09 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -1,7 +1,7 @@ { "id": "calendar", "name": "Calendar", - "version": "0.13", + "version": "0.14", "description": "Simple calendar", "icon": "calendar.png", "screenshots": [{"url":"screenshot_calendar.png"}], From 8650595ca42879087f496b40f81dcd7ddebcdcc9 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 2 May 2023 22:30:47 +0200 Subject: [PATCH 03/14] calendar: Add interface.html for holidays --- apps/calendar/interface.html | 186 +++++++++++++++++++++++++++++++++++ apps/calendar/metadata.json | 3 +- 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 apps/calendar/interface.html diff --git a/apps/calendar/interface.html b/apps/calendar/interface.html new file mode 100644 index 000000000..b70b26f9c --- /dev/null +++ b/apps/calendar/interface.html @@ -0,0 +1,186 @@ + + + + + + + + + +

Holidays

+ +
+ +
+ + + + + + + + + + + +
DateHoliday
+ +
+
+
+
+ +
+
+ +
+
+
+
+ + + + + diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index bf5c67b09..b7e40a1fd 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -9,10 +9,11 @@ "supports": ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "allow_emulator": true, + "interface": "interface.html", "storage": [ {"name":"calendar.app.js","url":"calendar.js"}, {"name":"calendar.settings.js","url":"settings.js"}, {"name":"calendar.img","url":"calendar-icon.js","evaluate":true} ], - "data": [{"name":"calendar.json"}] + "data": [{"name":"calendar.json"}, {"name":"calendar.holiday.json"}] } From 2d752832b734aa85052c63211f7e9ea8be53a7b6 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Tue, 2 May 2023 22:31:21 +0200 Subject: [PATCH 04/14] sched/interface: fix date format --- apps/sched/interface.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/sched/interface.html b/apps/sched/interface.html index 366e597a2..f1ace7d0c 100644 --- a/apps/sched/interface.html +++ b/apps/sched/interface.html @@ -3,7 +3,7 @@ - + -

Holidays

+

Holidays

- +
+ + diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index b7e40a1fd..44a68d879 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -15,5 +15,5 @@ {"name":"calendar.settings.js","url":"settings.js"}, {"name":"calendar.img","url":"calendar-icon.js","evaluate":true} ], - "data": [{"name":"calendar.json"}, {"name":"calendar.holiday.json"}] + "data": [{"name":"calendar.json"}, {"name":"calendar.days.json"}] } From d4116f80d56b8ff1a9f8651d274cac0a06c7fd01 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 4 May 2023 21:27:20 +0200 Subject: [PATCH 07/14] calendar: Change color for holidays --- apps/calendar/calendar.js | 8 ++++++-- apps/calendar/interface.html | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index 7977b0196..d7c43eb1f 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -16,6 +16,7 @@ const white = "#ffffff"; const red = "#d41706"; const blue = "#0000ff"; const yellow = "#ffff00"; +const cyan = "#00ffff"; let bgColor = color4; let bgColorMonth = color1; let bgColorDow = color2; @@ -23,6 +24,7 @@ let bgColorWeekend = color3; let fgOtherMonth = gray1; let fgSameMonth = white; let bgEvent = blue; +let bgOtherEvent = "#ff8800"; const eventsPerDay=6; // how much different events per day we can display const date = new Date(); @@ -60,6 +62,7 @@ if (settings.ndColors === true) { fgOtherMonth = blue; fgSameMonth = black; bgEvent = color2; + bgOtherEvent = cyan; } function getDowLbls(locale) { @@ -163,10 +166,11 @@ function drawCalendar(date) { week2AfterMonth.setDate(week2AfterMonth.getDate() + 14); events.forEach(ev => { if (ev.repeat === "y") { - ev.date.setFullYear(date.getFullYear()); + ev.date.setFullYear(ev.date.getMonth() < 6 ? week2AfterMonth.getFullYear() : weekBeforeMonth.getFullYear()); } }); const eventsThisMonth = events.filter(ev => ev.date > weekBeforeMonth && ev.date < week2AfterMonth); + eventsThisMonth.sort((a,b) => a.date - b.date); let i = 0; for (y = 0; y < rowN - 1; y++) { for (x = 0; x < colN; x++) { @@ -197,7 +201,7 @@ function drawCalendar(date) { g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1); break; case "o": // other - g.setColor("#88ff00").fillRect(x1+1, y1+1, x2-1, y2-1); + g.setColor(bgOtherEvent).fillRect(x1+1, y1+1, x2-1, y2-1); break; } diff --git a/apps/calendar/interface.html b/apps/calendar/interface.html index 509a6bebd..280a96c0b 100644 --- a/apps/calendar/interface.html +++ b/apps/calendar/interface.html @@ -160,7 +160,7 @@ function renderHoliday(holiday) { } function addHoliday() { - const holiday = {date: formatDate(new Date())}; + const holiday = {date: formatDate(new Date()), type: 'h'}; renderHoliday(holiday); holidays.push(holiday); render(); From fc91e7db89d78d5aa3816590f10e6fb593f2a25a Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 6 May 2023 11:23:01 +0100 Subject: [PATCH 08/14] stlap: add state and lap data files --- apps/stlap/metadata.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/stlap/metadata.json b/apps/stlap/metadata.json index 1ecdc5b6e..2a814eb0b 100644 --- a/apps/stlap/metadata.json +++ b/apps/stlap/metadata.json @@ -20,5 +20,9 @@ "url": "icon.js", "evaluate": true } + ], + "data": [ + {"name":"stlap.state.json"}, + {"wildcard":"stlap-*.json"} ] } \ No newline at end of file From 8702b3504569a7a0bfd9fd24ba1d5568f30bd41c Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 6 May 2023 11:23:16 +0100 Subject: [PATCH 09/14] stlap: no exceptions when STATE_PATH doesn't exist --- apps/stlap/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/stlap/app.js b/apps/stlap/app.js index 0bd18311f..0c0bb33ca 100644 --- a/apps/stlap/app.js +++ b/apps/stlap/app.js @@ -8,7 +8,7 @@ const BUTTON_ICONS = { reset: heatshrink.decompress(atob("jEYwMA/4BB/+BAQPDAQPnAQIAKv///0///8j///EP//wAQQICBwQUCEhgyCHAQ+CIgI=")) }; -let state = storage.readJSON(STATE_PATH); +let state = storage.readJSON(STATE_PATH, 1); const STATE_DEFAULT = { wasRunning: false, //If the stopwatch was ever running since being reset sessionStart: 0, //When the stopwatch was first started From 16d4dc758875bdef5fc12eef0f906903dcb64c1d Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 6 May 2023 11:37:55 +0100 Subject: [PATCH 10/14] stlap: slow down javascript when the user's not watching --- apps/stlap/app.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/stlap/app.js b/apps/stlap/app.js index 0c0bb33ca..ad5463180 100644 --- a/apps/stlap/app.js +++ b/apps/stlap/app.js @@ -157,7 +157,7 @@ function firstTimeStart(now, time) { elapsedTime: 0, }; lapFile = 'stlap-' + state.sessionStart + '.json'; - setupTimerInterval(); + setupTimerIntervalFast(); Bangle.buzz(200); drawButtons(); } @@ -201,13 +201,15 @@ function start(now, time) { state.elapsedTime += (state.pausedTime - state.startTime); state.startTime = now; state.running = true; - setupTimerInterval(); + setupTimerIntervalFast(); Bangle.buzz(200); drawTime(); drawButtons(); } Bangle.on("touch", (button, xy) => { + setupTimerIntervalFast(); + //In gesture mode, just turn on the light and then return if (gestureMode) { Bangle.setLCDPower(true); @@ -242,6 +244,8 @@ Bangle.on("touch", (button, xy) => { }); Bangle.on('swipe', direction => { + setupTimerIntervalFast(); + let now = (new Date()).getTime(); let time = getTime(); @@ -272,12 +276,23 @@ setWatch(() => { }, BTN1, { repeat: true }); let timerInterval; +let userWatching = false; + +function setupTimerIntervalFast() { + userWatching = true; + setupTimerInterval(); + + setTimeout(() => { + userWatching = false; + setupTimerInterval(); + }, 5000); +} function setupTimerInterval() { if (timerInterval !== undefined) { clearInterval(timerInterval); } - timerInterval = setInterval(drawTime, 10); + timerInterval = setInterval(drawTime, userWatching ? 10 : 1000); } function stopTimerInterval() { @@ -289,7 +304,7 @@ function stopTimerInterval() { drawTime(); if (state.running) { - setupTimerInterval(); + setupTimerIntervalFast(); } //Save our state when the app is closed @@ -300,5 +315,8 @@ E.on('kill', () => { } }); +// change interval depending of whether the user's looking +Bangle.on("twist", setupTimerIntervalFast); + Bangle.loadWidgets(); Bangle.drawWidgets(); \ No newline at end of file From 7dca61a0d5dbe74debe6608aae030ecbf3dcb852 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 6 May 2023 12:27:21 +0100 Subject: [PATCH 11/14] Fix d888b80ea - correctly bump ratchet launcher's version --- apps/powermanager/ChangeLog | 2 +- apps/ratchet_launch/ChangeLog | 1 + apps/ratchet_launch/metadata.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/powermanager/ChangeLog b/apps/powermanager/ChangeLog index d1c288f97..de3fd021c 100644 --- a/apps/powermanager/ChangeLog +++ b/apps/powermanager/ChangeLog @@ -9,4 +9,4 @@ 0.07: Convert Yes/No On/Off in settings to checkboxes 0.08: Fix the wrapping of intervals/timeouts with parameters Fix the widget drawing if widgets are hidden and Bangle.setLCDBrightness is called -0.09: Cache the app-launch info \ No newline at end of file +0.09: Accidental version bump \ No newline at end of file diff --git a/apps/ratchet_launch/ChangeLog b/apps/ratchet_launch/ChangeLog index af7f83942..e60ca42d2 100644 --- a/apps/ratchet_launch/ChangeLog +++ b/apps/ratchet_launch/ChangeLog @@ -1 +1,2 @@ 0.01: Initial release +0.02: Cache the app-launch info diff --git a/apps/ratchet_launch/metadata.json b/apps/ratchet_launch/metadata.json index 45057b0b9..7ebe0c4cd 100644 --- a/apps/ratchet_launch/metadata.json +++ b/apps/ratchet_launch/metadata.json @@ -2,7 +2,7 @@ "id": "ratchet_launch", "name": "Ratchet Launcher", "shortName": "Ratchet", - "version": "0.01", + "version": "0.02", "description": "Launcher with discrete scrolling for quicker app selection", "icon": "app.png", "type": "launch", From 2c896c8567479bbe42ed4a3f0f290ec71f1fc07a Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sat, 6 May 2023 17:58:36 +0100 Subject: [PATCH 12/14] stlap: bump version --- apps/stlap/ChangeLog | 3 ++- apps/stlap/metadata.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/stlap/ChangeLog b/apps/stlap/ChangeLog index 35ba8b130..0c21e6efd 100644 --- a/apps/stlap/ChangeLog +++ b/apps/stlap/ChangeLog @@ -1,3 +1,4 @@ 0.01: New app! 0.02: Bug fixes -0.03: Submitted to the app loader \ No newline at end of file +0.03: Submitted to the app loader +0.04: Reduce battery consumption when the user's not looking \ No newline at end of file diff --git a/apps/stlap/metadata.json b/apps/stlap/metadata.json index 2a814eb0b..ac846dfd7 100644 --- a/apps/stlap/metadata.json +++ b/apps/stlap/metadata.json @@ -1,7 +1,7 @@ { "id": "stlap", "name": "Stopwatch", - "version": "0.03", + "version": "0.04", "description": "A stopwatch that remembers its state, with a lap timer and a gesture mode (enable by swiping)", "icon": "icon.png", "type": "app", From b8b8bc41f3f2fa094616bccb234b9690380c002d Mon Sep 17 00:00:00 2001 From: gellnerm <47713613+gellnerm@users.noreply.github.com> Date: Mon, 8 May 2023 11:20:39 +0200 Subject: [PATCH 13/14] Update ChangeLog --- apps/widtemp/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/widtemp/ChangeLog b/apps/widtemp/ChangeLog index af7f83942..8fd2f7ca1 100644 --- a/apps/widtemp/ChangeLog +++ b/apps/widtemp/ChangeLog @@ -1 +1,2 @@ 0.01: Initial release +0.02: Disallow emulator From 52fd577a939d1063bbedea538a68c56ba072fd89 Mon Sep 17 00:00:00 2001 From: gellnerm <47713613+gellnerm@users.noreply.github.com> Date: Mon, 8 May 2023 11:21:00 +0200 Subject: [PATCH 14/14] Update metadata.json Disallow emulator --- apps/widtemp/metadata.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/widtemp/metadata.json b/apps/widtemp/metadata.json index 7b28acd38..5ec0f2f0e 100644 --- a/apps/widtemp/metadata.json +++ b/apps/widtemp/metadata.json @@ -1,7 +1,7 @@ { "id": "widtemp", "name": "Temperature widget", - "version": "0.01", + "version": "0.02", "description": "A temperature widget, showing the current internal temperature", "readme": "README.md", "icon": "widtemp.png", @@ -10,7 +10,7 @@ "tags": "widget,health", "supports": ["BANGLEJS","BANGLEJS2"], "dependencies" : {}, - "allow_emulator":true, + "allow_emulator":false, "storage": [ {"name":"widtemp.wid.js","url":"widtemp.wid.js"} ]
Date HolidayTypeRepeat