From 8c048f321c5cbf441620b3c6f276db55209cbd3a Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Wed, 20 Apr 2022 19:32:23 +0200 Subject: [PATCH 1/8] Refactor some methods to scheduling library --- apps/alarm/ChangeLog | 1 + apps/alarm/app.js | 29 ++++++----------------------- apps/alarm/metadata.json | 2 +- apps/sched/ChangeLog | 1 + apps/sched/lib.js | 19 ++++++++++++++++++- apps/sched/metadata.json | 2 +- apps/sched/sched.js | 14 +------------- apps/sleepphasealarm/ChangeLog | 1 + apps/sleepphasealarm/app.js | 10 +--------- apps/sleepphasealarm/metadata.json | 3 ++- css/main.css | 2 +- 11 files changed, 34 insertions(+), 50 deletions(-) diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index 3f56f4c20..876459e82 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -19,3 +19,4 @@ 0.18: Cope with >1 identical alarm at once (#1667) 0.19: Ensure rescheduled alarms that already fired have 'last' reset 0.20: Use the new 'sched' factories to initialize new alarms/timers +0.21: Refactor some methods to scheduling library diff --git a/apps/alarm/app.js b/apps/alarm/app.js index 1fc32ecb9..0caada4df 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -4,23 +4,6 @@ Bangle.drawWidgets(); // An array of alarm objects (see sched/README.md) let alarms = require("sched").getAlarms(); -// time in ms -> { hrs, mins } -function decodeTime(t) { - t = 0 | t; // sanitise - let hrs = 0 | (t / 3600000); - return { hrs: hrs, mins: Math.round((t - hrs * 3600000) / 60000) }; -} - -// time in { hrs, mins } -> ms -function encodeTime(o) { - return o.hrs * 3600000 + o.mins * 60000; -} - -function formatTime(t) { - let o = decodeTime(t); - return o.hrs + ":" + ("0" + o.mins).substr(-2); -} - function getCurrentTime() { let time = new Date(); return ( @@ -48,10 +31,10 @@ function showMainMenu() { var type,txt; // a leading space is currently required (JS error in Espruino 2v12) if (alarm.timer) { type = /*LANG*/"Timer"; - txt = " "+formatTime(alarm.timer); + txt = " "+require("sched").formatTime(alarm.timer); } else { type = /*LANG*/"Alarm"; - txt = " "+formatTime(alarm.t); + txt = " "+require("sched").formatTime(alarm.t); } if (alarm.rp) txt += "\0"+atob("FBaBAAABgAAcAAHn//////wAHsABzAAYwAAMAADAAAAAAwAAMAADGAAzgAN4AD//////54AAOAABgAA="); // rename duplicate alarms @@ -94,7 +77,7 @@ function editAlarm(alarmIndex, alarm) { let a = require("sched").newDefaultAlarm(); if (!newAlarm) Object.assign(a, alarms[alarmIndex]); if (alarm) Object.assign(a,alarm); - let t = decodeTime(a.t); + let t = require("sched").decodeTime(a.t); const menu = { '': { 'title': /*LANG*/'Alarm' }, @@ -129,7 +112,7 @@ function editAlarm(alarmIndex, alarm) { } }; menu[/*LANG*/"Save"] = function() { - a.t = encodeTime(t); + a.t = require("sched").encodeTime(t); a.last = (a.t < getCurrentTime()) ? (new Date()).getDate() : 0; if (newAlarm) alarms.push(a); else alarms[alarmIndex] = a; @@ -151,7 +134,7 @@ function editTimer(alarmIndex, alarm) { let a = require("sched").newDefaultTimer(); if (!newAlarm) Object.assign(a, alarms[alarmIndex]); if (alarm) Object.assign(a,alarm); - let t = decodeTime(a.timer); + let t = require("sched").decodeTime(a.timer); const menu = { '': { 'title': /*LANG*/'Timer' }, @@ -172,7 +155,7 @@ function editTimer(alarmIndex, alarm) { /*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ), }; menu[/*LANG*/"Save"] = function() { - a.timer = encodeTime(t); + a.timer = require("sched").encodeTime(t); a.t = getCurrentTime() + a.timer; a.last = 0; if (newAlarm) alarms.push(a); diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index db36b3ca9..5c443dcec 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,7 +2,7 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.20", + "version": "0.21", "description": "Set alarms and timers on your Bangle", "icon": "app.png", "tags": "tool,alarm,widget", diff --git a/apps/sched/ChangeLog b/apps/sched/ChangeLog index 0f935caf8..7372f9c4a 100644 --- a/apps/sched/ChangeLog +++ b/apps/sched/ChangeLog @@ -3,3 +3,4 @@ 0.03: Fix `getTimeToAlarm` for a timer already used at same day, don't set `last` for timers. 0.04: Fix `getTimeToAlarm` to check for next dow if alarm.t lower currentTime. 0.05: Export new functions (`newDefaultAlarm/Timer`), add Settings page +0.06: Refactor some methods to library diff --git a/apps/sched/lib.js b/apps/sched/lib.js index bfad1ac2d..8f3f9c88a 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -106,4 +106,21 @@ exports.getSettings = function () { // Write the updated settings back to storage exports.setSettings = function(settings) { require("Storage").writeJSON("sched.settings.json", settings); -}; \ No newline at end of file +}; + +// time in ms -> { hrs, mins } +exports.decodeTime = function(t) { + t = 0 | t; // sanitise + let hrs = 0 | (t / 3600000); + return { hrs: hrs, mins: Math.round((t - hrs * 3600000) / 60000) }; +} + +// time in { hrs, mins } -> ms +exports.encodeTime = function(o) { + return o.hrs * 3600000 + o.mins * 60000; +} + +exports.formatTime = function(t) { + let o = decodeTime(t); + return o.hrs + ":" + ("0" + o.mins).substr(-2); +} diff --git a/apps/sched/metadata.json b/apps/sched/metadata.json index 3454d2397..5f61d7d04 100644 --- a/apps/sched/metadata.json +++ b/apps/sched/metadata.json @@ -1,7 +1,7 @@ { "id": "sched", "name": "Scheduler", - "version": "0.05", + "version": "0.06", "description": "Scheduling library for alarms and timers", "icon": "app.png", "type": "scheduler", diff --git a/apps/sched/sched.js b/apps/sched/sched.js index 83f03ac01..7c97600d9 100644 --- a/apps/sched/sched.js +++ b/apps/sched/sched.js @@ -5,23 +5,11 @@ if (Bangle.SCHED) { delete Bangle.SCHED; } -// time in ms -> { hrs, mins } -function decodeTime(t) { - t = 0|t; // sanitise - var hrs = 0|(t/3600000); - return { hrs : hrs, mins : Math.round((t-hrs*3600000)/60000) }; -} - -function formatTime(t) { - var o = decodeTime(t); - return o.hrs+":"+("0"+o.mins).substr(-2); -} - function showAlarm(alarm) { const settings = require("sched").getSettings(); let msg = ""; - msg += alarm.timer ? formatTime(alarm.timer) : formatTime(alarm.t); + msg += alarm.timer ? require("sched").formatTime(alarm.timer) : require("sched").formatTime(alarm.t); if (alarm.msg) { msg += "\n"+alarm.msg; } else { diff --git a/apps/sleepphasealarm/ChangeLog b/apps/sleepphasealarm/ChangeLog index b07c5b9f7..875b3c1da 100644 --- a/apps/sleepphasealarm/ChangeLog +++ b/apps/sleepphasealarm/ChangeLog @@ -2,3 +2,4 @@ 0.02: Respect Quiet Mode 0.03: Add compatibility for Bangle.js 2 and new firmware, added "Alarm at " for the alarm time 0.04: Read alarms from new scheduling library, account for higher acceleration sensor noise on Bangle.js 2 +0.05: Refactor decodeTime() to scheduling library diff --git a/apps/sleepphasealarm/app.js b/apps/sleepphasealarm/app.js index dcd176617..236b71c0b 100644 --- a/apps/sleepphasealarm/app.js +++ b/apps/sleepphasealarm/app.js @@ -38,19 +38,11 @@ function calc_ess(acc_magn) { } } -// copied from alarm app -// time in ms -> { hrs, mins } -function decodeTime(t) { - t = 0|t; // sanitise - var hrs = 0|(t/3600000); - return { hrs : hrs, mins : Math.round((t-hrs*3600000)/60000) }; -} - // locate next alarm var nextAlarm; active.forEach(alarm => { const now = new Date(); - const t = decodeTime(alarm.t); + const t = require("sched").decodeTime(alarm.t); var dateAlarm = new Date(now.getFullYear(), now.getMonth(), now.getDate(), t.hrs, t.mins); if (dateAlarm < now) { // dateAlarm in the past, add 24h dateAlarm.setTime(dateAlarm.getTime() + (24*60*60*1000)); diff --git a/apps/sleepphasealarm/metadata.json b/apps/sleepphasealarm/metadata.json index bc75027c2..aecfa36e4 100644 --- a/apps/sleepphasealarm/metadata.json +++ b/apps/sleepphasealarm/metadata.json @@ -2,11 +2,12 @@ "id": "sleepphasealarm", "name": "SleepPhaseAlarm", "shortName": "SleepPhaseAlarm", - "version": "0.04", + "version": "0.05", "description": "Uses the accelerometer to estimate sleep and wake states with the principle of Estimation of Stationary Sleep-segments (ESS, see https://ubicomp.eti.uni-siegen.de/home/datasets/ichi14/index.html.en). This app will read the next alarm from the alarm application and will wake you up to 30 minutes early at the best guessed time when you are almost already awake.", "icon": "app.png", "tags": "alarm", "supports": ["BANGLEJS","BANGLEJS2"], + "dependencies": {"scheduler":"type"}, "storage": [ {"name":"sleepphasealarm.app.js","url":"app.js"}, {"name":"sleepphasealarm.img","url":"app-icon.js","evaluate":true} diff --git a/css/main.css b/css/main.css index f4850babe..c4e5286cc 100644 --- a/css/main.css +++ b/css/main.css @@ -81,7 +81,7 @@ a.btn.btn-link.dropdown-toggle { min-height: 8em; } -.tile-content { position: relative; } +.tile-content { position: relative; word-break: break-word; } .link-github { position:absolute; top: 36px; From 5e847a56fd00ad978650be434b52907c3bfeed2a Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Wed, 20 Apr 2022 20:26:06 +0200 Subject: [PATCH 2/8] sched: fix formatTime reference --- apps/sched/lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 8f3f9c88a..58ba5daf0 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -121,6 +121,6 @@ exports.encodeTime = function(o) { } exports.formatTime = function(t) { - let o = decodeTime(t); + let o = exports.decodeTime(t); return o.hrs + ":" + ("0" + o.mins).substr(-2); } From d832610a55e5b285bf49ba8cff6e68c647f22d52 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Wed, 20 Apr 2022 20:50:48 +0200 Subject: [PATCH 3/8] Ignore Jekyll local output folder --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 523dc5f20..fce2efb1a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ appdates.csv _config.yml tests/Layout/bin/tmp.* tests/Layout/testresult.bmp -apps.local.json \ No newline at end of file +apps.local.json +_site From 109ef4f417748252b0220d06fc38bcb0aa150faa Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Thu, 21 Apr 2022 09:56:52 +0200 Subject: [PATCH 4/8] [Launcher] Add README --- apps/launch/README.md | 14 ++++++++++++++ apps/launch/metadata.json | 1 + 2 files changed, 15 insertions(+) create mode 100644 apps/launch/README.md diff --git a/apps/launch/README.md b/apps/launch/README.md new file mode 100644 index 000000000..4e6185dea --- /dev/null +++ b/apps/launch/README.md @@ -0,0 +1,14 @@ +Launcher +======== + +This is the default launcher but you can replace it with a customised launcher. + +The app is needed to display a menu with all the apps installed on your Bangle. You can launch an app by touching its name/icon. + +Settings +-------- + +- `Font` - The font used (`4x6`, `6x8`, `12x20`, `6x15` or `Vector`). Default `12x20`. +- `Vector Font Size` - The size of the font if `Font` is set to `Vector`. Default `10`. +- `Show Clocks` - If set to `No` then clocks won't appear in the app list. Default `Yes`. +- `Fullscreen` - If set to `Yes` then widgets won't be loaded. Default `No`. diff --git a/apps/launch/metadata.json b/apps/launch/metadata.json index ab218412d..da76fc4bb 100644 --- a/apps/launch/metadata.json +++ b/apps/launch/metadata.json @@ -4,6 +4,7 @@ "shortName": "Launcher", "version": "0.13", "description": "This is needed to display a menu allowing you to choose your own applications. You can replace this with a customised launcher.", + "readme": "README.md", "icon": "app.png", "type": "launch", "tags": "tool,system,launcher", From 3ab7add1ef3328f93c2cb28e0aca2af1ecc21c4e Mon Sep 17 00:00:00 2001 From: Marco H Date: Thu, 21 Apr 2022 10:45:04 +0200 Subject: [PATCH 5/8] Fix typo --- apps/activityreminder/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index 39c5bc71f..9fb52e9ac 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -1,5 +1,5 @@ function drawAlert(){ - E.showPrompt("Innactivity detected",{ + E.showPrompt("Inactivity detected",{ title:"Activity reminder", buttons : {"Ok": true,"Dismiss": false} }).then(function(v) { From 85268b8f826e1920bc843b9ff3b99c806aeecd3e Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Thu, 21 Apr 2022 11:15:49 +0200 Subject: [PATCH 6/8] [Alarms & Timers] Avoid time reset after a dow change --- apps/alarm/ChangeLog | 1 + apps/alarm/app.js | 6 +++++- apps/alarm/metadata.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index 3f56f4c20..906169a04 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -19,3 +19,4 @@ 0.18: Cope with >1 identical alarm at once (#1667) 0.19: Ensure rescheduled alarms that already fired have 'last' reset 0.20: Use the new 'sched' factories to initialize new alarms/timers +0.21: Fix time reset after a day of week change (#1676) diff --git a/apps/alarm/app.js b/apps/alarm/app.js index 1fc32ecb9..e895f9041 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -119,7 +119,11 @@ function editAlarm(alarmIndex, alarm) { }, /*LANG*/'Days': { value: "SMTWTFS".split("").map((d,n)=>a.dow&(1< editDOW(a.dow, d=>{a.dow=d;editAlarm(alarmIndex,a)}) + onchange: () => editDOW(a.dow, d => { + a.dow = d; + a.t = encodeTime(t); + editAlarm(alarmIndex, a); + }) }, /*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ), /*LANG*/'Auto Snooze': { diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index db36b3ca9..5c443dcec 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,7 +2,7 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.20", + "version": "0.21", "description": "Set alarms and timers on your Bangle", "icon": "app.png", "tags": "tool,alarm,widget", From 03c1f330adc22dbdf295e13e4e22840c53442162 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 21 Apr 2022 11:50:23 +0200 Subject: [PATCH 7/8] revert main.css --- css/main.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/main.css b/css/main.css index c4e5286cc..f4850babe 100644 --- a/css/main.css +++ b/css/main.css @@ -81,7 +81,7 @@ a.btn.btn-link.dropdown-toggle { min-height: 8em; } -.tile-content { position: relative; word-break: break-word; } +.tile-content { position: relative; } .link-github { position:absolute; top: 36px; From 856164a58e21300ef137751d787a568c1e3e9408 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Thu, 21 Apr 2022 11:56:39 +0200 Subject: [PATCH 8/8] alarm update version to 0.22 --- apps/alarm/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index 5c443dcec..906df810f 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,7 +2,7 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.21", + "version": "0.22", "description": "Set alarms and timers on your Bangle", "icon": "app.png", "tags": "tool,alarm,widget",