sched 0.29: Improve clkinfo startup time by 10ms

master
Gordon Williams 2024-10-25 09:36:51 +01:00
parent 527a3c10b8
commit e00cba4094
4 changed files with 21 additions and 28 deletions

View File

@ -29,3 +29,4 @@
0.26: Fix hitting snooze on an alarm after when the snooze would've fired 0.26: Fix hitting snooze on an alarm after when the snooze would've fired
0.27: Tapping clkinfo enables/disables the selected alarm 0.27: Tapping clkinfo enables/disables the selected alarm
0.28: Added an icon for disabled events 0.28: Added an icon for disabled events
0.29: Improve clkinfo startup time by 10ms

View File

@ -1,15 +1,7 @@
(function() { (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 = 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 iconEventOn = atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B/++B/8+B/5+B8z+B+H+B/P+B//+B//+B//+A//8AAAAAAAAAAAAA==");
const iconEventOff = atob("GBgBAAAAAAAAAAAAD//wH//4GAAYGAAYGAAYH//4H//4H//4H/74H/wAH/gAHzB4H4H+H8m2H/MDH/OHH/OHD/MDAAG2AAH+AAB4");
//from 0 to max, the higher the closer to fire (as in a progress bar) //from 0 to max, the higher the closer to fire (as in a progress bar)
function getAlarmValue(a){ function getAlarmValue(a) {
let min = Math.round(alarm.getTimeToAlarm(a)/(60*1000)); let min = Math.round(require('sched').getTimeToAlarm(a)/(60*1000));
if(!min) return 0; //not active or more than a day if(!min) return 0; //not active or more than a day
return getAlarmMax(a)-min; return getAlarmMax(a)-min;
} }
@ -23,20 +15,20 @@
function getAlarmIcon(a) { function getAlarmIcon(a) {
if(a.on) { if(a.on) {
if(a.timer) return iconTimerOn; if(a.timer) return atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADnAADDAAGBgAGBgAGBgAf/4Af/4AAAAAAAAAAAAA==");
if(a.date) return iconEventOn; if(a.date) return atob("GBiBAAAAAAAAAAAAAA//8B//+BgAGBgAGBgAGB//+B//+B//+B/++B/8+B/5+B8z+B+H+B/P+B//+B//+B//+A//8AAAAAAAAAAAAA==");
return iconAlarmOn; return 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==");
} else { } else {
if(a.timer) return iconTimerOff; if(a.timer) return atob("GBiBAAAAAAAAAAAAAAf/4Af/4AGBgAGBgAGBgAD/AAD/AAB+AAA8AAA8AAB+AADkeADB/gGBtgGDAwGDhwfzhwfzAwABtgAB/gAAeA==");
if(a.date) return iconEventOff; if(a.date) return atob("GBgBAAAAAAAAAAAAD//wH//4GAAYGAAYGAAYH//4H//4H//4H/74H/wAH/gAHzB4H4H+H8m2H/MDH/OHH/OHD/MDAAG2AAH+AAB4");
return iconAlarmOff; return atob("GBiBAAAAAAAAAAYAYA4AcBx+ODn/nAP/wAf/4A/n8A/n8B/n+B/n+B/nAB/mAB/geB/5/g/5tg/zAwfzhwPzhwHzAwB5tgAB/gAAeA==");
} }
} }
function getAlarmText(a){ function getAlarmText(a){
if(a.timer) { if(a.timer) {
if(!a.on) return /*LANG*/"off"; if(!a.on) return /*LANG*/"off";
let time = Math.round(alarm.getTimeToAlarm(a)/(60*1000)); let time = Math.round(require('sched').getTimeToAlarm(a)/(60*1000));
if(time > 60) if(time > 60)
time = Math.round(time / 60) + "h"; time = Math.round(time / 60) + "h";
else else
@ -52,7 +44,7 @@
//workaround for sorting undefined values //workaround for sorting undefined values
function getAlarmOrder(a) { function getAlarmOrder(a) {
let val = alarm.getTimeToAlarm(a); let val = require('sched').getTimeToAlarm(a);
if(typeof val == "undefined") return 86400*1000; if(typeof val == "undefined") return 86400*1000;
return val; return val;
} }
@ -66,7 +58,7 @@
const minute = 60 * 1000; const minute = 60 * 1000;
const halfhour = 30 * minute; const halfhour = 30 * minute;
const hour = 2 * halfhour; const hour = 2 * halfhour;
let msecs = alarm.getTimeToAlarm(a); let msecs = require('sched').getTimeToAlarm(a);
if(typeof msecs == "undefined" || msecs == 0) if(typeof msecs == "undefined" || msecs == 0)
return []; return [];
if(msecs > hour) { //refresh every half an hour if(msecs > hour) { //refresh every half an hour
@ -103,15 +95,15 @@
}, switchTimeout); }, switchTimeout);
} }
var img = iconAlarmOn; // read the file direct here to avoid loading sched library (saves 10ms!)
var all = alarm.getAlarms(); var all = /*require('sched').getAlarms()*/require("Storage").readJSON("sched.json",1)||[];
//get only alarms not created by other apps //get only alarms not created by other apps
var alarmItems = { var alarmItems = {
name: /*LANG*/"Alarms", name: /*LANG*/"Alarms",
img: img, img: getAlarmIcon({on:1}),
dynamic: true, dynamic: true,
items: all.filter(a=>!a.appid) items: all.filter(a=>!a.appid)
//.sort((a,b)=>alarm.getTimeToAlarm(a)-alarm.getTimeToAlarm(b)) //.sort((a,b)=>require('sched').getTimeToAlarm(a)-require('sched').getTimeToAlarm(b))
.sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b)) .sort((a,b)=>getAlarmOrder(a)-getAlarmOrder(b))
.map(a => ({ .map(a => ({
name: null, name: null,
@ -135,13 +127,12 @@
run: function() { run: function() {
if (a.date) return; // ignore events if (a.date) return; // ignore events
a.on = !a.on; a.on = !a.on;
if(a.on && a.timer) alarm.resetTimer(a); if(a.on && a.timer) require('sched').resetTimer(a);
this.emit("redraw"); this.emit("redraw");
alarm.setAlarms(all); require('sched').setAlarms(all);
alarm.reload(); // schedule/unschedule the alarm require('sched').reload(); // schedule/unschedule the alarm
} }
})), })),
}; };
return alarmItems; return alarmItems;
}) })

View File

@ -1,5 +1,6 @@
// Return an array of all alarms // Return an array of all alarms
exports.getAlarms = function() { exports.getAlarms = function() {
// we do this direct in clkinfo.js to avoid loading the library
return require("Storage").readJSON("sched.json",1)||[]; return require("Storage").readJSON("sched.json",1)||[];
}; };
// Write a list of alarms back to storage // Write a list of alarms back to storage

View File

@ -1,7 +1,7 @@
{ {
"id": "sched", "id": "sched",
"name": "Scheduler", "name": "Scheduler",
"version": "0.28", "version": "0.29",
"description": "Scheduling library for alarms and timers", "description": "Scheduling library for alarms and timers",
"icon": "app.png", "icon": "app.png",
"type": "scheduler", "type": "scheduler",