Skip to content

Commit

Permalink
Added clkinfo to sched
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Monaco committed Nov 16, 2022
1 parent 581ec4d commit ae1bf1c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/sched/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
Improve timer message using formatDuration
Fix wrong fallback for buzz pattern
0.13: Ask to delete a timer after stopping it
0.14: Added clkinfo here
77 changes: 77 additions & 0 deletions apps/sched/clkinfo.js
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;
})
5 changes: 3 additions & 2 deletions apps/sched/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "sched",
"name": "Scheduler",
"version": "0.13",
"version": "0.14",
"description": "Scheduling library for alarms and timers",
"icon": "app.png",
"type": "scheduler",
Expand All @@ -13,7 +13,8 @@
{"name":"sched.js","url":"sched.js"},
{"name":"sched.img","url":"app-icon.js","evaluate":true},
{"name":"sched","url":"lib.js"},
{"name":"sched.settings.js","url":"settings.js"}
{"name":"sched.settings.js","url":"settings.js"},
{"name":"sched.clkinfo.js","url":"clkinfo.js"}
],
"data": [{"name":"sched.json"}, {"name":"sched.settings.json"}]
}

0 comments on commit ae1bf1c

Please sign in to comment.