forked from FOSS/BangleApps
quicklaunch: do fewer storage interactions
parent
c519def208
commit
87ca15597c
|
@ -1,31 +1,40 @@
|
|||
{
|
||||
const R = Bangle.appRect;
|
||||
g.clearRect(R); // clear immediately to increase perceived snappiness.
|
||||
|
||||
const storage = require("Storage");
|
||||
let settings = storage.readJSON("quicklaunch.json", true) || {};
|
||||
let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature.
|
||||
|
||||
let reset = function(name){
|
||||
if (!settings[name]) settings[name] = {"name":"(none)"};
|
||||
if (!storage.read(settings[name].src)) settings[name] = {"name":"(none)"};
|
||||
storage.write("quicklaunch.json", settings);
|
||||
const draw = () => {
|
||||
// Draw app hints
|
||||
g.reset().clearRect(R).setFont("Vector", 11)
|
||||
.setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2)
|
||||
.setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2)
|
||||
.setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2)
|
||||
.setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y)
|
||||
.setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2);
|
||||
};
|
||||
draw(); // draw asap to increase perceived snappiness.
|
||||
|
||||
let leaveTrace = function(trace) {
|
||||
if (settings[trace+"app"].name != "") {
|
||||
settings.trace = trace;
|
||||
storage.writeJSON("quicklaunch.json", settings);
|
||||
} else { trace = trace.substring(0, trace.length-1); }
|
||||
return trace;
|
||||
};
|
||||
|
||||
let launchApp = function(trace) {
|
||||
if (settings[trace+"app"]) {
|
||||
if (settings[trace+"app"].src){
|
||||
if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) reset(trace+"app"); else load(settings[trace+"app"].src);
|
||||
}
|
||||
if (settings[trace+"app"] && settings[trace+"app"].src) {
|
||||
if (settings[trace+"app"].name == "Extension") draw();
|
||||
else if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher();
|
||||
else if (!storage.read(settings[trace+"app"].src)) {
|
||||
E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch");
|
||||
settings[trace+"app"] = {"name":"(none)"}; // reset entry.
|
||||
} else load(settings[trace+"app"].src);
|
||||
}
|
||||
};
|
||||
|
||||
let trace = (settings[settings.trace+"app"].src=="quicklaunch.app.js") ? settings.trace : settings.trace.substring(0, settings.trace.length-1); // If the stored trace leads beyond extension screens, walk back to the last extension screen. Compatibility with "Fastload Utils" App History feature.
|
||||
|
||||
let touchHandler = (_,e) => {
|
||||
if (e.type == 2) return;
|
||||
let R = Bangle.appRect;
|
||||
|
@ -47,15 +56,22 @@
|
|||
if (e.b == 0 && !timeoutToClock) updateTimeoutToClock();
|
||||
};
|
||||
|
||||
let saveAndClear = ()=> {
|
||||
storage.writeJSON("quicklaunch.json", settings);
|
||||
E.removeListener("kill", saveAndClear);
|
||||
if (timeoutToClock) clearTimeout(timeoutToClock); // Compatibility with Fastload Utils.
|
||||
}
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
touch: touchHandler,
|
||||
swipe : swipeHandler,
|
||||
drag : onLongTouchDoPause,
|
||||
remove: ()=>{if (timeoutToClock) clearTimeout(timeoutToClock);} // Compatibility with Fastload Utils.
|
||||
remove: saveAndClear
|
||||
});
|
||||
|
||||
g.clearRect(Bangle.appRect);
|
||||
E.on("kill", saveAndClear)
|
||||
|
||||
"Bangle.loadWidgets()"; // Hack: Fool Fastload Utils that we call Bangle.loadWidgets(). This way we get the fastest possibe loading in whichever environment we find ourselves.
|
||||
|
||||
// taken from Icon Launcher with some alterations
|
||||
|
@ -67,13 +83,4 @@
|
|||
};
|
||||
updateTimeoutToClock();
|
||||
|
||||
let R = Bangle.appRect;
|
||||
|
||||
// Draw app hints
|
||||
g.setFont("Vector", 11)
|
||||
.setFontAlign(0,1,3).drawString(settings[trace+"lapp"].name, R.x2, R.y+R.h/2)
|
||||
.setFontAlign(0,1,1).drawString(settings[trace+"rapp"].name, R.x, R.y+R.h/2)
|
||||
.setFontAlign(0,1,0).drawString(settings[trace+"uapp"].name, R.x+R.w/2, R.y2)
|
||||
.setFontAlign(0,-1,0).drawString(settings[trace+"dapp"].name, R.x+R.w/2, R.y)
|
||||
.setFontAlign(0,0,0).drawString(settings[trace+"tapp"].name, R.x+R.w/2, R.y+R.h/2);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
const storage = require("Storage");
|
||||
let settings = storage.readJSON("quicklaunch.json", true) || {};
|
||||
|
||||
let reset = function(name){
|
||||
if (!settings[name]) settings[name] = {"name":"(none)"};
|
||||
if (!storage.read(settings[name].src)) settings[name] = {"name":"(none)"};
|
||||
storage.write("quicklaunch.json", settings);
|
||||
};
|
||||
|
||||
let leaveTrace = function(trace) {
|
||||
settings.trace = trace;
|
||||
storage.writeJSON("quicklaunch.json", settings);
|
||||
|
@ -15,8 +9,14 @@
|
|||
};
|
||||
|
||||
let launchApp = function(trace) {
|
||||
if (settings[trace+"app"].src){
|
||||
if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher(); else if (!storage.read(settings[trace+"app"].src)) reset(trace+"app"); else load(settings[trace+"app"].src);
|
||||
if (settings[trace+"app"].src){
|
||||
if (settings[trace+"app"].name == "Show Launcher") Bangle.showLauncher();
|
||||
else if (!storage.read(settings[trace+"app"].src)) {
|
||||
E.showMessage(settings[trace+"app"].src+"\n"+/*LANG*/"was not found"+".", "Quick Launch");
|
||||
settings[trace+"app"] = {"name":"(none)"}; // reset entry.
|
||||
storage.write("quicklaunch.json", settings);
|
||||
setTimeout(load, 2000);
|
||||
} else load(settings[trace+"app"].src);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue