|
| 1 | +(function() { |
| 2 | + const alarm = require('sched'); |
| 3 | + const iconAlarmOn = atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/n+B/n+B/h+B/4+A/+8A//8Af/4AP/wAH/gAB+AAAAAAAAAA=="); |
| 4 | + const iconAlarmOff = (g.theme.dark |
| 5 | + ? atob("GBjBAP////8AAAAAAAAGAGAOAHAcfjg5/5wD/8AH/+AP5/AP5/Af5/gf5/gf5wAf5gAf4Hgf+f4P+bYP8wMH84cD84cB8wMAebYAAf4AAHg=") |
| 6 | + : atob("GBjBAP//AAAAAAAAAAAGAGAOAHAcfjg5/5wD/8AH/+AP5/AP5/Af5/gf5/gf5wAf5gAf4Hgf+f4P+bYP8wMH84cD84cB8wMAebYAAf4AAHg=")); |
| 7 | + |
| 8 | + const iconTimerOn = (g.theme.dark |
| 9 | + ? atob("GBjBAP////8AAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5wAAwwABgYABgYABgYAH/+AH/+AAAAAAAAAAAAA=") |
| 10 | + : atob("GBjBAP//AAAAAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5wAAwwABgYABgYABgYAH/+AH/+AAAAAAAAAAAAA=")); |
| 11 | + const iconTimerOff = (g.theme.dark |
| 12 | + ? atob("GBjBAP////8AAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5HgAwf4BgbYBgwMBg4cH84cH8wMAAbYAAf4AAHg=") |
| 13 | + : atob("GBjBAP//AAAAAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5HgAwf4BgbYBgwMBg4cH84cH8wMAAbYAAf4AAHg=")); |
| 14 | + |
| 15 | + function getAlarmMinutes(a){ |
| 16 | + if(!a.on) return 0; //may be completely wrong |
| 17 | + //value to be used in progress-bars |
| 18 | + return getAlarmMax(a) - Math.round(alarm.getTimeToAlarm(a)/(60*1000)); |
| 19 | + } |
| 20 | + |
| 21 | + function getAlarmMax(a) { |
| 22 | + if(a.timer) |
| 23 | + return Math.round(a.timer/(60*1000)); |
| 24 | + //minutes cannot be more than a full day |
| 25 | + return 1440; |
| 26 | + } |
| 27 | + |
| 28 | + function getAlarmIcon(a) { |
| 29 | + if(a.on) { |
| 30 | + if(a.timer) return iconTimerOn; |
| 31 | + return iconAlarmOn; |
| 32 | + } else { |
| 33 | + if(a.timer) return iconTimerOff; |
| 34 | + return iconAlarmOff; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + function formatTimer(time) { |
| 39 | + if(time > 60) |
| 40 | + time = Math.round(time / 60) + "h"; |
| 41 | + else |
| 42 | + time += "m"; |
| 43 | + return time; |
| 44 | + } |
| 45 | + |
| 46 | + function formatAlarm(a) { |
| 47 | + return require("locale").time(new Date(a.t),1); |
| 48 | + } |
| 49 | + |
| 50 | + function getAlarmText(a){ |
| 51 | + if(a.timer) { |
| 52 | + let min = getAlarmMinutes(a); |
| 53 | + let max = getAlarmMax(a); |
| 54 | + return formatTimer(min)+"/"+formatTimer(max); |
| 55 | + } |
| 56 | + return formatAlarm(a); |
| 57 | + } |
| 58 | + |
| 59 | + //TODO maybe change this icon with something for alarms? |
| 60 | + var img = atob("GBiBAeAAB+AAB/v/3/v/3/v/3/v/3/v/n/n/H/z+P/48//85//+b//+b//8p//4E//yCP/kBH/oAn/oAX/oAX/oAX/oAX+AAB+AABw==") |
| 61 | + //get only alarms not created by other apps |
| 62 | + var alarmItems = { |
| 63 | + name: "Alarms", |
| 64 | + img: img, |
| 65 | + items: alarm.getAlarms().filter(a=>!a.appid).sort((a,b)=>getAlarmMinutes(b)-getAlarmMinutes(a)) |
| 66 | + .map((a, i)=>({ |
| 67 | + name: null, |
| 68 | + get: () => ({ text: getAlarmText(a), img: getAlarmIcon(a), |
| 69 | + hasRange: true, v: getAlarmMinutes(a), min:0, max:getAlarmMax(a)}), |
| 70 | + show: function() { alarmItems.items[i].emit("redraw"); }, |
| 71 | + hide: function () {}, |
| 72 | + run: function() { } |
| 73 | + })), |
| 74 | + }; |
| 75 | + |
| 76 | + return alarmItems; |
| 77 | +}) |
0 commit comments