Merge pull request #3232 from bobrippling/feat/widalarmeta-recheck

widalarmeta: recheck latest alarm when alarms change
pull/3236/head
Rob Pilling 2024-03-04 08:59:23 +00:00 committed by GitHub
commit 9453d7dac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 23 additions and 11 deletions

View File

@ -24,3 +24,4 @@
0.21: Fix crash in clock_info
0.22: Dated event repeat option
0.23: Allow buzzing forever when an alarm fires
0.24: Emit alarmReload when alarms change (used by widalarm)

View File

@ -55,10 +55,7 @@ exports.getTimeToAlarm = function(alarm, time) {
/// Force a reload of the current alarms and widget
exports.reload = function() {
eval(require("Storage").read("sched.boot.js"));
if (global.WIDGETS && WIDGETS["alarm"]) {
WIDGETS["alarm"].reload();
Bangle.drawWidgets();
}
Bangle.emit("alarmReload");
};
// Factory that creates a new alarm with default values
exports.newDefaultAlarm = function () {

View File

@ -1,7 +1,7 @@
{
"id": "sched",
"name": "Scheduler",
"version": "0.23",
"version": "0.24",
"description": "Scheduling library for alarms and timers",
"icon": "app.png",
"type": "scheduler",

View File

@ -1 +1,2 @@
0.01: Moved out of 'alarm' app
0.02: Decouple reloading of widget when alarms change

View File

@ -1,7 +1,7 @@
{
"id": "widalarm",
"name": "Alarms Widget",
"version": "0.01",
"version": "0.02",
"description": "Displays an alarm icon in the widgets bar if any alarm is active",
"icon": "app.png",
"type": "widget",

View File

@ -6,3 +6,9 @@ WIDGETS["alarm"]={area:"tl",width:0,draw:function() {
}
};
WIDGETS["alarm"].reload();
Bangle.on("alarmReload", () => {
if (WIDGETS["alarm"]) {
WIDGETS["alarm"].reload();
Bangle.drawWidgets();
}
});

View File

@ -12,3 +12,4 @@
0.08: Selectable font. Allow to disable hour padding.
0.09: Match draw() API e.g. to allow wid_edit to alter this widget
0.10: Change 4x5 font to 6x8, teletext is now default font
0.11: Bugfix: handle changes in alarms (e.g. done without a load, such as via fastload)

View File

@ -2,7 +2,7 @@
"id": "widalarmeta",
"name": "Alarm & Timer ETA",
"shortName": "Alarm ETA",
"version": "0.10",
"version": "0.11",
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).",
"icon": "widget.png",
"type": "widget",

View File

@ -19,7 +19,11 @@
loadSettings();
function getNextAlarm(date) {
const alarms = (require("Storage").readJSON("sched.json",1) || []).filter(alarm => alarm.on && alarm.hidden !== true);
const alarms = require("sched")
.getAlarms()
// more precise filtering is done using getTimeToAlarm() below
.filter(alarm => alarm.on && alarm.hidden !== true);
WIDGETS["widalarmeta"].numActiveAlarms = alarms.length;
if (alarms.length > 0) {
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm, date) || Number.POSITIVE_INFINITY);
@ -116,16 +120,18 @@
} /* draw */
if (config.maxhours > 0) {
// add your widget
WIDGETS["widalarmeta"]={
area:"tl",
width: 0, // hide by default = assume no timer
draw:draw,
reload: () => {
reload: function () {
this.nextAlarm = undefined;
loadSettings();
g.clear();
Bangle.drawWidgets();
},
};
Bangle.on("alarmReload", () => WIDGETS["widalarmeta"].reload());
}
})();