Skip to content

Commit ae1bf1c

Browse files
author
Gabriele Monaco
committed
Added clkinfo to sched
1 parent 581ec4d commit ae1bf1c

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

apps/sched/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
Improve timer message using formatDuration
1515
Fix wrong fallback for buzz pattern
1616
0.13: Ask to delete a timer after stopping it
17+
0.14: Added clkinfo here

apps/sched/clkinfo.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
})

apps/sched/metadata.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "sched",
33
"name": "Scheduler",
4-
"version": "0.13",
4+
"version": "0.14",
55
"description": "Scheduling library for alarms and timers",
66
"icon": "app.png",
77
"type": "scheduler",
@@ -13,7 +13,8 @@
1313
{"name":"sched.js","url":"sched.js"},
1414
{"name":"sched.img","url":"app-icon.js","evaluate":true},
1515
{"name":"sched","url":"lib.js"},
16-
{"name":"sched.settings.js","url":"settings.js"}
16+
{"name":"sched.settings.js","url":"settings.js"},
17+
{"name":"sched.clkinfo.js","url":"clkinfo.js"}
1718
],
1819
"data": [{"name":"sched.json"}, {"name":"sched.settings.json"}]
1920
}

0 commit comments

Comments
 (0)