mirror of https://github.com/espruino/BangleApps
Merge pull request #3232 from bobrippling/feat/widalarmeta-recheck
widalarmeta: recheck latest alarm when alarms changepull/3236/head
commit
9453d7dac3
|
@ -24,3 +24,4 @@
|
||||||
0.21: Fix crash in clock_info
|
0.21: Fix crash in clock_info
|
||||||
0.22: Dated event repeat option
|
0.22: Dated event repeat option
|
||||||
0.23: Allow buzzing forever when an alarm fires
|
0.23: Allow buzzing forever when an alarm fires
|
||||||
|
0.24: Emit alarmReload when alarms change (used by widalarm)
|
||||||
|
|
|
@ -55,10 +55,7 @@ exports.getTimeToAlarm = function(alarm, time) {
|
||||||
/// Force a reload of the current alarms and widget
|
/// Force a reload of the current alarms and widget
|
||||||
exports.reload = function() {
|
exports.reload = function() {
|
||||||
eval(require("Storage").read("sched.boot.js"));
|
eval(require("Storage").read("sched.boot.js"));
|
||||||
if (global.WIDGETS && WIDGETS["alarm"]) {
|
Bangle.emit("alarmReload");
|
||||||
WIDGETS["alarm"].reload();
|
|
||||||
Bangle.drawWidgets();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// Factory that creates a new alarm with default values
|
// Factory that creates a new alarm with default values
|
||||||
exports.newDefaultAlarm = function () {
|
exports.newDefaultAlarm = function () {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "sched",
|
"id": "sched",
|
||||||
"name": "Scheduler",
|
"name": "Scheduler",
|
||||||
"version": "0.23",
|
"version": "0.24",
|
||||||
"description": "Scheduling library for alarms and timers",
|
"description": "Scheduling library for alarms and timers",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "scheduler",
|
"type": "scheduler",
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
0.01: Moved out of 'alarm' app
|
0.01: Moved out of 'alarm' app
|
||||||
|
0.02: Decouple reloading of widget when alarms change
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "widalarm",
|
"id": "widalarm",
|
||||||
"name": "Alarms Widget",
|
"name": "Alarms Widget",
|
||||||
"version": "0.01",
|
"version": "0.02",
|
||||||
"description": "Displays an alarm icon in the widgets bar if any alarm is active",
|
"description": "Displays an alarm icon in the widgets bar if any alarm is active",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
|
|
|
@ -6,3 +6,9 @@ WIDGETS["alarm"]={area:"tl",width:0,draw:function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
WIDGETS["alarm"].reload();
|
WIDGETS["alarm"].reload();
|
||||||
|
Bangle.on("alarmReload", () => {
|
||||||
|
if (WIDGETS["alarm"]) {
|
||||||
|
WIDGETS["alarm"].reload();
|
||||||
|
Bangle.drawWidgets();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -12,3 +12,4 @@
|
||||||
0.08: Selectable font. Allow to disable hour padding.
|
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.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.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)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "widalarmeta",
|
"id": "widalarmeta",
|
||||||
"name": "Alarm & Timer ETA",
|
"name": "Alarm & Timer ETA",
|
||||||
"shortName": "Alarm 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).",
|
"description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).",
|
||||||
"icon": "widget.png",
|
"icon": "widget.png",
|
||||||
"type": "widget",
|
"type": "widget",
|
||||||
|
|
|
@ -19,7 +19,11 @@
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
function getNextAlarm(date) {
|
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;
|
WIDGETS["widalarmeta"].numActiveAlarms = alarms.length;
|
||||||
if (alarms.length > 0) {
|
if (alarms.length > 0) {
|
||||||
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm, date) || Number.POSITIVE_INFINITY);
|
const times = alarms.map(alarm => require("sched").getTimeToAlarm(alarm, date) || Number.POSITIVE_INFINITY);
|
||||||
|
@ -116,16 +120,18 @@
|
||||||
} /* draw */
|
} /* draw */
|
||||||
|
|
||||||
if (config.maxhours > 0) {
|
if (config.maxhours > 0) {
|
||||||
// add your widget
|
|
||||||
WIDGETS["widalarmeta"]={
|
WIDGETS["widalarmeta"]={
|
||||||
area:"tl",
|
area:"tl",
|
||||||
width: 0, // hide by default = assume no timer
|
width: 0, // hide by default = assume no timer
|
||||||
draw:draw,
|
draw:draw,
|
||||||
reload: () => {
|
reload: function () {
|
||||||
|
this.nextAlarm = undefined;
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
g.clear();
|
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Bangle.on("alarmReload", () => WIDGETS["widalarmeta"].reload());
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue