-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriele Monaco
committed
Nov 16, 2022
1 parent
581ec4d
commit ae1bf1c
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
(function() { | ||
const alarm = require('sched'); | ||
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=="); | ||
const iconAlarmOff = (g.theme.dark | ||
? atob("GBjBAP////8AAAAAAAAGAGAOAHAcfjg5/5wD/8AH/+AP5/AP5/Af5/gf5/gf5wAf5gAf4Hgf+f4P+bYP8wMH84cD84cB8wMAebYAAf4AAHg=") | ||
: atob("GBjBAP//AAAAAAAAAAAGAGAOAHAcfjg5/5wD/8AH/+AP5/AP5/Af5/gf5/gf5wAf5gAf4Hgf+f4P+bYP8wMH84cD84cB8wMAebYAAf4AAHg=")); | ||
|
||
const iconTimerOn = (g.theme.dark | ||
? atob("GBjBAP////8AAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5wAAwwABgYABgYABgYAH/+AH/+AAAAAAAAAAAAA=") | ||
: atob("GBjBAP//AAAAAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5wAAwwABgYABgYABgYAH/+AH/+AAAAAAAAAAAAA=")); | ||
const iconTimerOff = (g.theme.dark | ||
? atob("GBjBAP////8AAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5HgAwf4BgbYBgwMBg4cH84cH8wMAAbYAAf4AAHg=") | ||
: atob("GBjBAP//AAAAAAAAAAAAAAAH/+AH/+ABgYABgYABgYAA/wAA/wAAfgAAPAAAPAAAfgAA5HgAwf4BgbYBgwMBg4cH84cH8wMAAbYAAf4AAHg=")); | ||
|
||
function getAlarmMinutes(a){ | ||
if(!a.on) return 0; //may be completely wrong | ||
//value to be used in progress-bars | ||
return getAlarmMax(a) - Math.round(alarm.getTimeToAlarm(a)/(60*1000)); | ||
} | ||
|
||
function getAlarmMax(a) { | ||
if(a.timer) | ||
return Math.round(a.timer/(60*1000)); | ||
//minutes cannot be more than a full day | ||
return 1440; | ||
} | ||
|
||
function getAlarmIcon(a) { | ||
if(a.on) { | ||
if(a.timer) return iconTimerOn; | ||
return iconAlarmOn; | ||
} else { | ||
if(a.timer) return iconTimerOff; | ||
return iconAlarmOff; | ||
} | ||
} | ||
|
||
function formatTimer(time) { | ||
if(time > 60) | ||
time = Math.round(time / 60) + "h"; | ||
else | ||
time += "m"; | ||
return time; | ||
} | ||
|
||
function formatAlarm(a) { | ||
return require("locale").time(new Date(a.t),1); | ||
} | ||
|
||
function getAlarmText(a){ | ||
if(a.timer) { | ||
let min = getAlarmMinutes(a); | ||
let max = getAlarmMax(a); | ||
return formatTimer(min)+"/"+formatTimer(max); | ||
} | ||
return formatAlarm(a); | ||
} | ||
|
||
//TODO maybe change this icon with something for alarms? | ||
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==") | ||
//get only alarms not created by other apps | ||
var alarmItems = { | ||
name: "Alarms", | ||
img: img, | ||
items: alarm.getAlarms().filter(a=>!a.appid).sort((a,b)=>getAlarmMinutes(b)-getAlarmMinutes(a)) | ||
.map((a, i)=>({ | ||
name: null, | ||
get: () => ({ text: getAlarmText(a), img: getAlarmIcon(a), | ||
hasRange: true, v: getAlarmMinutes(a), min:0, max:getAlarmMax(a)}), | ||
show: function() { alarmItems.items[i].emit("redraw"); }, | ||
hide: function () {}, | ||
run: function() { } | ||
})), | ||
}; | ||
|
||
return alarmItems; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters