BangleApps/apps/fastload/boot.js

100 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2022-10-29 12:17:40 +00:00
{
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
const s = require("Storage");
const SETTINGS = s.readJSON("fastload.json") || {};
2022-10-29 12:17:40 +00:00
let loadingScreen = function(){
g.reset();
let x = g.getWidth()/2;
let y = g.getHeight()/2;
g.setColor(g.theme.bg);
g.fillRect(x-49, y-19, x+49, y+19);
g.setColor(g.theme.fg);
g.drawRect(x-50, y-20, x+50, y+20);
g.setFont("6x8");
g.setFontAlign(0,0);
g.drawString("Fastloading...", x, y);
g.flip(true);
};
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
let cache = s.readJSON("fastload.cache") || {};
const SYS_SETTINGS="setting.json";
let appFastloadPossible = function(n){
if(SETTINGS.detectSettingsChange && (!cache[SYS_SETTINGS] || s.hash(SYS_SETTINGS) != cache[SYS_SETTINGS])){
cache[SYS_SETTINGS] = s.hash(SYS_SETTINGS);
s.writeJSON("fastload.cache", cache);
return false;
}
// no widgets, no problem
if (!global.WIDGETS) return true;
let hash = s.hash(n);
if (cache[n] && hash == cache[n].hash)
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
return cache[n].fast;
let app = s.read(n);
cache[n] = {};
cache[n].fast = app.includes("Bangle.loadWidgets");
cache[n].hash = hash;
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
s.writeJSON("fastload.cache", cache);
return cache[n].fast;
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
};
global._load = load;
2022-11-28 19:26:46 +00:00
let slowload = function(n){
global._load(n);
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
};
2022-11-28 19:26:46 +00:00
let fastload = function(n){
if (!n || appFastloadPossible(n)){
// Bangle.load can call load, to prevent recursion this must be the system load
global.load = slowload;
Bangle.load(n);
// if fastloading worked, we need to set load back to this method
global.load = fastload;
}
else
slowload(n);
};
global.load = fastload;
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
let appHistory, resetHistory, recordHistory;
if (SETTINGS.useAppHistory){
appHistory = s.readJSON("fastload.history.json",true)||[];
resetHistory = ()=>{appHistory=[];s.writeJSON("fastload.history.json",appHistory);};
recordHistory = ()=>{s.writeJSON("fastload.history.json",appHistory);};
}
2022-10-29 12:17:40 +00:00
Bangle.load = (o => (name) => {
if (Bangle.uiRemove && !SETTINGS.hideLoading) loadingScreen();
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
if (SETTINGS.useAppHistory){
if (name && name!=".bootcde" && !(name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch)) {
// store the name of the app to launch
appHistory.push(name);
} else if (name==".bootcde") { // when Bangle.showClock is called
resetHistory();
} else if (name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch) {
// do nothing with history
} else {
// go back in history
appHistory.pop();
name = appHistory[appHistory.length-1];
}
}
if (SETTINGS.autoloadLauncher && !name){
let orig = Bangle.load;
Bangle.load = (n)=>{
Bangle.load = orig;
fastload(n);
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
};
Bangle.showLauncher();
Bangle.load = orig;
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
} else
o(name);
2022-10-29 12:17:40 +00:00
})(Bangle.load);
fastload: Add app history functionality Add app history functionality add semicolons that were missing according to Web IDE fix intendtation in if statement fewer storage manipulations, tweak some logic comment regarding resetting history undo `const SETTINGS` -> `let settings` describe app history in readme In settings, don't allow app history and load to launcher to be active at the same time change `launchedApps` -> `appHistory` (somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected add to comment re loading `.bootcde` an extra time on init Revert "add to comment re loading `.bootcde` an extra time on init" This reverts commit b4aaccf35c820a1c7e7a22040c3958b4fc92e5c6. Revert "(somewhat unstable commit) tweaking logic around loading `.bootcde` at system initiation to make the history and resetting of history work as expected" This reverts commit 51dddfc30ac65572891efee1daf6099f7a3b19f4. tweak when settings page is autoupdated Change description for app history. Add contributor. quicklaunch shall not be recorded in the history Add setting to exclude quicklaunch from history, if it is present remove print statements If long press HW button do reset history. Set some variables to null if app history is disabled. add info re long press HW button resets history remove check for 'fastload.5.boot.js'. it would show up in the app history during development because the web ide said to load the uploaded app. it should not be needed in normal operations of the app for users. fewer checks for if useAppHistory is true, by first declaring some variables and then defining them inside an if-statement add recommendation of 'Fast Reset' app in readme
2023-03-25 12:56:53 +00:00
if (SETTINGS.useAppHistory) E.on('kill', ()=>{if (!BTN.read()) recordHistory(); else resetHistory();}); // Usually record history, but reset it if long press of HW button was used.
2022-10-29 12:17:40 +00:00
}