Skip to content

Commit 3ece90b

Browse files
author
thyttan
committed
Merge branch 'app-history-from-fastload-utils' into app-loader
2 parents 17c3d73 + 8e1284b commit 3ece90b

File tree

13 files changed

+202
-10
lines changed

13 files changed

+202
-10
lines changed

apps/apphist/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/apphist/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# App history
2+
3+
* Lets you navigate back trough the series of apps since last you were on the clock face. Works with the software back button and hardware button.
4+
* Long press of hardware button clears the app history and loads the clock face (Sometimes triggered if your not very quickly releasing the button)
5+
6+
# Creator
7+
8+
[thyttan](https://github.com/thyttan)
9+
[halemmerich](https://github.com/halemmerich) (Fastload Utils)
10+
11+
# Contributors
12+

apps/apphist/boot.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
// Things that use `eval` instead of `load` or `Bangle.load` (e.g. auto displaying new messages - `messagegui.new.js`) can affect the app history record unexpectedly. They don't themselves get added to the history (since we don't override `eval`) and if they use one of the other two mentioned load functions they may remove the last recorded entry.
3+
4+
const s = require("Storage");
5+
const SETTINGS = s.readJSON("fastload.json") || {};
6+
7+
global._load = global.load;
8+
Bangle._load = Bangle.load;
9+
10+
let appHistory = s.readJSON("fastload.history.json",true)||[];
11+
const resetHistory = ()=>{appHistory=[];s.writeJSON("fastload.history.json",appHistory);};
12+
const recordHistory = ()=>{s.writeJSON("fastload.history.json",appHistory);};
13+
14+
const traverseHistory = (name)=>{
15+
if (name && name!=".bootcde" && !(name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch)) {
16+
// store the name of the app to launch
17+
appHistory.push(name);
18+
} else if (name==".bootcde") { // when Bangle.showClock is called
19+
resetHistory();
20+
} else if (name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch) {
21+
// do nothing with history
22+
} else {
23+
// go back in history
24+
appHistory.pop();
25+
name = appHistory[appHistory.length-1];
26+
}
27+
return name;
28+
}
29+
30+
const addHistoryTraversal = (loadFn => (name) => {
31+
name = traverseHistory(name);
32+
loadFn(name);
33+
})
34+
35+
const addHistoryTraversalFastload = (loadFn => (name) => {
36+
global.load = global._load; // Only run through traverseHistory once, not both for Bangle.load and global.load.
37+
name = traverseHistory(name);
38+
loadFn(name);
39+
global.load = globalLoadWithHistory;
40+
})
41+
42+
const globalLoadWithHistory = addHistoryTraversal(global.load);
43+
global.load = globalLoadWithHistory;
44+
Bangle.load = addHistoryTraversalFastload(Bangle._load);
45+
46+
E.on('kill', ()=>{
47+
// Usually record history, but reset it if long press of HW button was used. May be tricky to release button quick enough to not trigger resetHistory.
48+
if (!BTN.read()) recordHistory(); else resetHistory();
49+
})
50+
}

apps/apphist/icon.png

1.74 KB
Loading

apps/apphist/metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ "id": "apphist",
2+
"name": "App History",
3+
"version": "0.01",
4+
"icon": "icon.png",
5+
"description": "Lets you navigate back trough the series of apps since last you were on the clock face. Works with the software back button and hardware button.",
6+
"type":"bootloader",
7+
"tags": "system",
8+
"supports": ["BANGLEJS2"],
9+
"readme": "README.md",
10+
"storage": [
11+
{"name":"apphist.5.boot.js","url":"boot.js"},
12+
{"name":"apphist.settings.js","url":"settings.js"}
13+
],
14+
"data": [{"name":"apphist.json"}]
15+
}

apps/apphist/settings.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(function(back) {
2+
var FILE="appHist.json";
3+
var settings;
4+
var isQuicklaunchPresent = !!require('Storage').read("quicklaunch.app.js", 0, 1);
5+
6+
function writeSettings(key, value) {
7+
var s = require('Storage').readJSON(FILE, true) || {};
8+
s[key] = value;
9+
require('Storage').writeJSON(FILE, s);
10+
readSettings();
11+
}
12+
13+
function readSettings(){
14+
settings = require('Storage').readJSON(FILE, true) || {};
15+
}
16+
17+
readSettings();
18+
19+
function buildMainMenu(){
20+
var mainmenu = {};
21+
22+
mainmenu[''] = { 'title': 'App History', back: back };
23+
24+
if (isQuicklaunchPresent) {
25+
mainmenu['Exclude Quick Launch from history'] = {
26+
value: !!settings.disregardQuicklaunch,
27+
onchange: v => {
28+
writeSettings("disregardQuicklaunch",v);
29+
}
30+
};
31+
}
32+
return mainmenu;
33+
}
34+
35+
E.showMenu(buildMainMenu());
36+
})

apps/confthyttan/dtlaunch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"showClocks":true,"showLaunchers":true,"direct":false,"swipeExit":false,"timeOut":"15s"}
1+
{"showClocks":true,"showLaunchers":true,"direct":false,"swipeExit":false,"timeOut":"15s",rememberPage:true}

apps/fastload/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
# Fastload Utils
44

5-
Use this with caution. When you find something misbehaving please check if the problem actually persists when removing this app.
5+
**Use this with caution.** When you find something misbehaving please check if the problem actually persists without Fastload Utils
6+
before filing an issue.
67

78
This allows fast loading of all apps with two conditions:
89
* Loaded app contains `Bangle.loadWidgets`. This is needed to prevent problems with apps not expecting widgets to be already loaded.
910
* Current app can be removed completely from RAM.
1011

12+
**Fastload has no way of knowing whether an app can be removed completely from RAM, so if it can't your
13+
Bangle will just end up with a memory leak or undefined behaviour**
14+
1115
#### ⚠️ KNOWN ISSUES ⚠️
1216

1317
* Fastload currently does not play nice with the automatic reload option of the apploader. App installs and upgrades are unreliable since the fastload causes code to run after reset and interfere with the upload process.
@@ -25,14 +29,20 @@ This allows fast loading of all apps with two conditions:
2529
* Long press of hardware button clears the app history and loads the clock face
2630
* Installing the 'Fast Reset' app allows doing fastloads directly to the clock face by pressing the hardware button just a little longer than a click. Useful if there are many apps in the history and the user want to access the clock quickly.
2731

28-
## Technical infos
32+
## Technical Notes
33+
34+
Fastload uses the same mechanism as `.bootcde` does to check the app to be loaded for widget use and stores the result of that and a hash of the js in a cache.
35+
36+
Fastload calls `Bangle.load` to fast load an app, and this checks if `Bangle.uiRemove` exists and if so calls it to upload the app, and loads a new app using `eval`. `Bangle.uiRemove` is set when
37+
UI elements (`layout`, `Bangle.setUI`, scrollers, etc) are supplied with a `remove` callback - and so it's assumed that the remove callback will remove *everything* related to the app from RAM.
38+
39+
The problem is that apart from clocks, very few apps do actually completely remove themselves from RAM when the `remove` callback is called, so the possibility of memory leaks is very high.
2940

30-
This is still experimental but it uses the same mechanism as `.bootcde` does.
31-
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.
3241

3342
# Creator
3443

3544
[halemmerich](https://github.com/halemmerich)
3645

3746
# Contributors
47+
3848
[thyttan](https://github.com/thyttan)

apps/fastload/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"shortName" : "Fastload Utils",
44
"version": "0.06",
55
"icon": "icon.png",
6-
"description": "Enable experimental fastloading for more apps",
6+
"description": "Enable experimental fastloading for more apps. ⚠️ Use with extreme caution - many apps are not compatible with fastload and will cause memory leaks and instability.",
77
"type":"bootloader",
88
"tags": "system",
99
"supports": ["BANGLEJS2"],

apps/lcdclock/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
0.06: Minor code improvements
77
0.07: fix special characters in clockinfo menus
88
0.08: Allow - and . in clockinfo menus (fix #4007)
9-
Use slightly narrower clockinfo font
9+
Use slightly narrower clockinfo font
10+
0.09: Use custom 7 segment font

0 commit comments

Comments
 (0)