mirror of https://github.com/espruino/BangleApps
Merge pull request #2320 from halemmerich/fastload
Fastload - Allows fast loading on more loadspull/2333/head
commit
3ac52c6d21
|
@ -0,0 +1,3 @@
|
|||
0.01: New App!
|
||||
0.02: Allow redirection of loads to the launcher
|
||||
0.03: Allow hiding the fastloading info screen
|
|
@ -0,0 +1,21 @@
|
|||
# Fastload Utils
|
||||
|
||||
*EXPERIMENTAL* Use this with caution. When you find something misbehaving please check if the problem actually persists when removing this app.
|
||||
|
||||
This allows fast loading of all apps with two conditions:
|
||||
* Loaded app contains `Bangle.loadWidgets`. This is needed to prevent problems with apps not expecting widgets to be already loaded.
|
||||
* Current app can be removed completely from RAM.
|
||||
|
||||
## Settings
|
||||
|
||||
* Allows to redirect all loads usually loading the clock to the launcher instead
|
||||
* The "Fastloading..." screen can be switched off
|
||||
|
||||
## Technical infos
|
||||
|
||||
This is still experimental but it uses the same mechanism as `.bootcde` does.
|
||||
It checks the app to be loaded for widget use and stores the result of that and a hash of the js in a cache.
|
||||
|
||||
# Creator
|
||||
|
||||
[halemmerich](https://github.com/halemmerich)
|
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
const SETTINGS = require("Storage").readJSON("fastload.json") || {};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
let cache = require("Storage").readJSON("fastload.cache") || {};
|
||||
|
||||
let checkApp = function(n){
|
||||
// no widgets, no problem
|
||||
if (!global.WIDGETS) return true;
|
||||
let app = require("Storage").read(n);
|
||||
if (cache[n] && E.CRC32(app) == cache[n].crc)
|
||||
return cache[n].fast
|
||||
cache[n] = {};
|
||||
cache[n].fast = app.includes("Bangle.loadWidgets");
|
||||
cache[n].crc = E.CRC32(app);
|
||||
require("Storage").writeJSON("fastload.cache", cache);
|
||||
return cache[n].fast;
|
||||
}
|
||||
|
||||
global._load = load;
|
||||
|
||||
let slowload = function(n){
|
||||
global._load(n);
|
||||
}
|
||||
|
||||
let fastload = function(n){
|
||||
if (!n || checkApp(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;
|
||||
|
||||
Bangle.load = (o => (name) => {
|
||||
if (Bangle.uiRemove && !SETTINGS.hideLoading) loadingScreen();
|
||||
if (SETTINGS.autoloadLauncher && !name){
|
||||
let orig = Bangle.load;
|
||||
Bangle.load = (n)=>{
|
||||
Bangle.load = orig;
|
||||
fastload(n);
|
||||
}
|
||||
Bangle.showLauncher();
|
||||
Bangle.load = orig;
|
||||
} else
|
||||
o(name);
|
||||
})(Bangle.load);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,16 @@
|
|||
{ "id": "fastload",
|
||||
"name": "Fastload Utils",
|
||||
"shortName" : "Fastload Utils",
|
||||
"version": "0.03",
|
||||
"icon": "icon.png",
|
||||
"description": "Enable experimental fastloading for more apps",
|
||||
"type":"bootloader",
|
||||
"tags": "system",
|
||||
"supports": ["BANGLEJS2"],
|
||||
"readme": "README.md",
|
||||
"storage": [
|
||||
{"name":"fastload.5.boot.js","url":"boot.js"},
|
||||
{"name":"fastload.settings.js","url":"settings.js"}
|
||||
],
|
||||
"data": [{"name":"fastload.json"}]
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
(function(back) {
|
||||
var FILE="fastload.json";
|
||||
var settings;
|
||||
|
||||
function writeSettings(key, value) {
|
||||
var s = require('Storage').readJSON(FILE, true) || {};
|
||||
s[key] = value;
|
||||
require('Storage').writeJSON(FILE, s);
|
||||
readSettings();
|
||||
}
|
||||
|
||||
function readSettings(){
|
||||
settings = require('Storage').readJSON(FILE, true) || {};
|
||||
}
|
||||
|
||||
readSettings();
|
||||
|
||||
function buildMainMenu(){
|
||||
var mainmenu = {
|
||||
'': { 'title': 'Fastload', back: back },
|
||||
'Force load to launcher': {
|
||||
value: !!settings.autoloadLauncher,
|
||||
onchange: v => {
|
||||
writeSettings("autoloadLauncher",v);
|
||||
}
|
||||
},
|
||||
'Hide "Fastloading..."': {
|
||||
value: !!settings.hideLoading,
|
||||
onchange: v => {
|
||||
writeSettings("hideLoading",v);
|
||||
}
|
||||
}
|
||||
};
|
||||
return mainmenu;
|
||||
}
|
||||
|
||||
E.showMenu(buildMainMenu());
|
||||
})
|
Loading…
Reference in New Issue