mirror of https://github.com/espruino/BangleApps
Merge pull request #3579 from bobrippling/feat/alarm-clkinfo
Allow toggling an alarm via clkinfopull/3605/head
commit
8ae59c8db6
|
@ -50,7 +50,7 @@ extensions).
|
||||||
`load()` returns an array of menu objects, where each object contains a list of menu items:
|
`load()` returns an array of menu objects, where each object contains a list of menu items:
|
||||||
* `name` : text to display and identify menu object (e.g. weather)
|
* `name` : text to display and identify menu object (e.g. weather)
|
||||||
* `img` : a 24x24px image
|
* `img` : a 24x24px image
|
||||||
* `dynamic` : if `true`, items are not constant but are sorted (e.g. calendar events sorted by date)
|
* `dynamic` : if `true`, items are not constant but are sorted (e.g. calendar events sorted by date). This is only used by a few clocks, for example `circlesclock`
|
||||||
* `items` : menu items such as temperature, humidity, wind etc.
|
* `items` : menu items such as temperature, humidity, wind etc.
|
||||||
|
|
||||||
Note that each item is an object with:
|
Note that each item is an object with:
|
||||||
|
|
|
@ -27,3 +27,4 @@
|
||||||
0.24: Emit alarmReload when alarms change (used by widalarm)
|
0.24: Emit alarmReload when alarms change (used by widalarm)
|
||||||
0.25: Fix wrap around when snoozed through midnight
|
0.25: Fix wrap around when snoozed through midnight
|
||||||
0.26: Fix hitting snooze on an alarm after when the snooze would've fired
|
0.26: Fix hitting snooze on an alarm after when the snooze would've fired
|
||||||
|
0.27: Tapping clkinfo enables/disables the selected alarm
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
const iconAlarmOff = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA==");
|
const iconAlarmOff = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA==");
|
||||||
const iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA==");
|
const iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA==");
|
||||||
const iconTimerOff = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA==");
|
const iconTimerOff = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA==");
|
||||||
|
const iconEvent = atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B/++B/8+B/5+B8z+B+H+B/P+B//+B//+B//+A//8AAAAAAAAAAAAA==");
|
||||||
|
|
||||||
//from 0 to max, the higher the closer to fire (as in a progress bar)
|
//from 0 to max, the higher the closer to fire (as in a progress bar)
|
||||||
function getAlarmValue(a){
|
function getAlarmValue(a){
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAlarmIcon(a) {
|
function getAlarmIcon(a) {
|
||||||
|
if(a.date) return iconEvent;
|
||||||
if(a.on) {
|
if(a.on) {
|
||||||
if(a.timer) return iconTimerOn;
|
if(a.timer) return iconTimerOn;
|
||||||
return iconAlarmOn;
|
return iconAlarmOn;
|
||||||
|
@ -39,6 +41,10 @@
|
||||||
time += "m";
|
time += "m";
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
if(a.date){
|
||||||
|
const d = new Date(a.date);
|
||||||
|
return `${d.getDate()} ${require("locale").month(d, 1)}`;
|
||||||
|
}
|
||||||
return require("time_utils").formatTime(a.t);
|
return require("time_utils").formatTime(a.t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +102,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var img = iconAlarmOn;
|
var img = iconAlarmOn;
|
||||||
|
var all = alarm.getAlarms();
|
||||||
//get only alarms not created by other apps
|
//get only alarms not created by other apps
|
||||||
var alarmItems = {
|
var alarmItems = {
|
||||||
name: /*LANG*/"Alarms",
|
name: /*LANG*/"Alarms",
|
||||||
img: img,
|
img: img,
|
||||||
dynamic: true,
|
dynamic: true,
|
||||||
items: alarm.getAlarms().filter(a=>!a.appid)
|
items: all.filter(a=>!a.appid)
|
||||||
//.sort((a,b)=>alarm.getTimeToAlarm(a)-alarm.getTimeToAlarm(b))
|
//.sort((a,b)=>alarm.getTimeToAlarm(a)-alarm.getTimeToAlarm(b))
|
||||||
.sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b))
|
.sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b))
|
||||||
.map((a, i)=>({
|
.map((a, i)=>({
|
||||||
|
@ -123,7 +130,14 @@
|
||||||
this.interval = undefined;
|
this.interval = undefined;
|
||||||
this.switchTimeout = undefined;
|
this.switchTimeout = undefined;
|
||||||
},
|
},
|
||||||
run: function() { }
|
run: function() {
|
||||||
|
if (a.date) return; // ignore events
|
||||||
|
a.on = !a.on;
|
||||||
|
if(a.on && a.timer) alarm.resetTimer(a);
|
||||||
|
this.emit("redraw");
|
||||||
|
alarm.setAlarms(all);
|
||||||
|
alarm.reload(); // schedule/unschedule the alarm
|
||||||
|
}
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,14 +34,18 @@ exports.setAlarm = function(id, alarm) {
|
||||||
if (alarm.dow===undefined) alarm.dow = 0b1111111;
|
if (alarm.dow===undefined) alarm.dow = 0b1111111;
|
||||||
if (alarm.on!==false) alarm.on=true;
|
if (alarm.on!==false) alarm.on=true;
|
||||||
if (alarm.timer) { // if it's a timer, set the start time as a time from *now*
|
if (alarm.timer) { // if it's a timer, set the start time as a time from *now*
|
||||||
var time = new Date();
|
exports.resetTimer(alarm);
|
||||||
var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000);
|
|
||||||
alarm.t = (currentTime + alarm.timer) % 86400000;
|
|
||||||
}
|
}
|
||||||
alarms.push(alarm);
|
alarms.push(alarm);
|
||||||
}
|
}
|
||||||
exports.setAlarms(alarms);
|
exports.setAlarms(alarms);
|
||||||
};
|
};
|
||||||
|
/// Set a timer's firing time based off the timer's `timer` property + the given time (or now)
|
||||||
|
exports.resetTimer = function(alarm, time) {
|
||||||
|
time = time || new Date();
|
||||||
|
var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000);
|
||||||
|
alarm.t = (currentTime + alarm.timer) % 86400000;
|
||||||
|
};
|
||||||
/// Get time until the given alarm (object). Return undefined if alarm not enabled, or if 86400000 or more, alarm could be *more* than a day in the future
|
/// Get time until the given alarm (object). Return undefined if alarm not enabled, or if 86400000 or more, alarm could be *more* than a day in the future
|
||||||
exports.getTimeToAlarm = function(alarm, time) {
|
exports.getTimeToAlarm = function(alarm, time) {
|
||||||
if (!alarm) return undefined;
|
if (!alarm) return undefined;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "sched",
|
"id": "sched",
|
||||||
"name": "Scheduler",
|
"name": "Scheduler",
|
||||||
"version": "0.26",
|
"version": "0.27",
|
||||||
"description": "Scheduling library for alarms and timers",
|
"description": "Scheduling library for alarms and timers",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"type": "scheduler",
|
"type": "scheduler",
|
||||||
|
|
|
@ -77,6 +77,8 @@ declare module Sched {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type Timer = Sched & { timer: Milliseconds };
|
||||||
|
|
||||||
type Repeat = {
|
type Repeat = {
|
||||||
num: number,
|
num: number,
|
||||||
interval: "day" | "week" | "month" | "year",
|
interval: "day" | "week" | "month" | "year",
|
||||||
|
@ -103,6 +105,8 @@ declare module Sched {
|
||||||
|
|
||||||
function setAlarm(id: string, alarm?: NewSched): void;
|
function setAlarm(id: string, alarm?: NewSched): void;
|
||||||
|
|
||||||
|
function resetTimer(alarm: Timer, time?: Date): void;
|
||||||
|
|
||||||
function getTimeToAlarm(alarm: Sched | undefined | null, time?: Date): number | undefined;
|
function getTimeToAlarm(alarm: Sched | undefined | null, time?: Date): number | undefined;
|
||||||
function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined;
|
function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue