diff --git a/apps/clock_info/README.md b/apps/clock_info/README.md index 031f89121..220a0cf4d 100644 --- a/apps/clock_info/README.md +++ b/apps/clock_info/README.md @@ -50,7 +50,7 @@ extensions). `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) * `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. Note that each item is an object with: diff --git a/apps/sched/ChangeLog b/apps/sched/ChangeLog index 1b385c8ea..46cf02caa 100644 --- a/apps/sched/ChangeLog +++ b/apps/sched/ChangeLog @@ -27,3 +27,4 @@ 0.24: Emit alarmReload when alarms change (used by widalarm) 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.27: Tapping clkinfo enables/disables the selected alarm diff --git a/apps/sched/clkinfo.js b/apps/sched/clkinfo.js index 89402ea67..65e462042 100644 --- a/apps/sched/clkinfo.js +++ b/apps/sched/clkinfo.js @@ -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 iconTimerOn = atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA=="); 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) function getAlarmValue(a){ @@ -20,6 +21,7 @@ } function getAlarmIcon(a) { + if(a.date) return iconEvent; if(a.on) { if(a.timer) return iconTimerOn; return iconAlarmOn; @@ -39,6 +41,10 @@ time += "m"; 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); } @@ -96,12 +102,13 @@ } var img = iconAlarmOn; + var all = alarm.getAlarms(); //get only alarms not created by other apps var alarmItems = { name: /*LANG*/"Alarms", img: img, 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)=>getAlarmOrder(a)-getAlarmOrder(b)) .map((a, i)=>({ @@ -123,7 +130,14 @@ this.interval = 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 + } })), }; diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 13cce1ef2..fcd971fc4 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -34,14 +34,18 @@ exports.setAlarm = function(id, alarm) { if (alarm.dow===undefined) alarm.dow = 0b1111111; if (alarm.on!==false) alarm.on=true; if (alarm.timer) { // if it's a timer, set the start time as a time from *now* - var time = new Date(); - var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000); - alarm.t = (currentTime + alarm.timer) % 86400000; + exports.resetTimer(alarm); } alarms.push(alarm); } 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 exports.getTimeToAlarm = function(alarm, time) { if (!alarm) return undefined; diff --git a/apps/sched/metadata.json b/apps/sched/metadata.json index be4dcdf33..591e9d3e9 100644 --- a/apps/sched/metadata.json +++ b/apps/sched/metadata.json @@ -1,7 +1,7 @@ { "id": "sched", "name": "Scheduler", - "version": "0.26", + "version": "0.27", "description": "Scheduling library for alarms and timers", "icon": "app.png", "type": "scheduler", diff --git a/typescript/types/sched.d.ts b/typescript/types/sched.d.ts index c2cd23d35..1bcffb632 100644 --- a/typescript/types/sched.d.ts +++ b/typescript/types/sched.d.ts @@ -77,6 +77,8 @@ declare module Sched { } ); + type Timer = Sched & { timer: Milliseconds }; + type Repeat = { num: number, interval: "day" | "week" | "month" | "year", @@ -103,6 +105,8 @@ declare module Sched { 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?: undefined | null, time?: Date): undefined;