Skip to content

Commit f042201

Browse files
author
thyttan
committed
Merge branch 'app-history-from-fastload-utils' into app-loader
2 parents ec07543 + 9138494 commit f042201

File tree

11 files changed

+124
-56
lines changed

11 files changed

+124
-56
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
5+
TODO:
6+
* Long press of hardware button clears the app history and loads the clock face (Sometimes triggered if your not very quickly releasing the button. Commented out for now.)
7+
8+
# Creator
9+
10+
[thyttan](https://github.com/thyttan)
11+
[halemmerich](https://github.com/halemmerich) (Fastload Utils)
12+
13+
# Contributors
14+

apps/apphist/boot.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
// Seems like `apphist` must be placed before `Fastload Utils` in execution order at boot for compatibility. Otherwise the Bangle.js 2 craps out, freezed up and soon reboots extra hard before loading the clock face again. This is ensured by metadata placing apphist at order 4 and Fastload Utils at order 5 in the boot sequence.
4+
5+
const s = require("Storage");
6+
const SETTINGS = s.readJSON("apphist.settings.json") || {};
7+
8+
global._load = global.load;
9+
Bangle._load = Bangle.load;
10+
11+
let appHistory = s.readJSON("apphist.json",true)||[];
12+
const resetHistory = ()=>{appHistory=[];s.writeJSON("apphist.json",appHistory);};
13+
const recordHistory = ()=>{s.writeJSON("apphist.json",appHistory);};
14+
15+
const traverseHistory = (name)=>{
16+
if (name && name!=".bootcde" && !(name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch)) {
17+
// store the name of the app to launch
18+
appHistory.push(name);
19+
} else if (name==".bootcde") { // when Bangle.showClock is called
20+
resetHistory();
21+
} else if (name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch) {
22+
// do nothing with history
23+
} else {
24+
// go back in history
25+
appHistory.pop();
26+
name = appHistory[appHistory.length-1];
27+
}
28+
return name;
29+
};
30+
31+
const addHistoryTraversal = (loadFn => (name) => {
32+
name = traverseHistory(name);
33+
loadFn(name);
34+
});
35+
36+
const addHistoryTraversalFastload = (loadFn => (name) => {
37+
global.load = global._load; // Only run through traverseHistory once, not both for Bangle.load and global.load.
38+
name = traverseHistory(name);
39+
loadFn(name);
40+
global.load = globalLoadWithHistory;
41+
});
42+
43+
const globalLoadWithHistory = addHistoryTraversal(global.load);
44+
global.load = globalLoadWithHistory;
45+
Bangle.load = addHistoryTraversalFastload(Bangle._load);
46+
47+
E.on('kill', ()=>{
48+
// Usually record history, but reset it if long press of HW button was used.
49+
// FIXME: May be tricky for user to release button quickly enough to not trigger resetHistory. Commented out for now.
50+
// if (!BTN.read()) recordHistory(); else resetHistory();
51+
recordHistory();
52+
});
53+
}

apps/apphist/icon.png

1.74 KB
Loading

apps/apphist/metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.4.boot.js","url":"boot.js"},
12+
{"name":"apphist.settings.js","url":"settings.js"}
13+
],
14+
"data": [
15+
{"name":"apphist.json"},
16+
{"name":"apphist.settings.json"}
17+
]
18+
}

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.settings.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/fastload/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
0.04: (WIP) Allow use of app history when going back (`load()` or `Bangle.load()` calls without specified app).
55
0.05: Check for changes in setting.js and force real reload if needed
66
0.06: Fix caching whether an app is fastloadable
7+
0.07: Break out app history to a separate app: App History, `apphist`.

apps/fastload/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,10 @@ Bangle will just end up with a memory leak or undefined behaviour**
1818

1919
## Settings
2020

21-
* Activate app history and navigate back through recent apps instead of immediately loading the clock face
22-
* If Quick Launch is installed it can be excluded from app history
2321
* Allows to redirect all loads usually loading the clock to the launcher instead
2422
* The "Fastloading..." screen can be switched off
2523
* Enable checking `setting.json` and force a complete load on changes
2624

27-
## App history
28-
29-
* Long press of hardware button clears the app history and loads the clock face
30-
* 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.
31-
3225
## Technical Notes
3326

3427
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.

apps/fastload/boot.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,8 @@ let fastload = function(n){
6060
};
6161
global.load = fastload;
6262

63-
let appHistory, resetHistory, recordHistory;
64-
if (SETTINGS.useAppHistory){
65-
appHistory = s.readJSON("fastload.history.json",true)||[];
66-
resetHistory = ()=>{appHistory=[];s.writeJSON("fastload.history.json",appHistory);};
67-
recordHistory = ()=>{s.writeJSON("fastload.history.json",appHistory);};
68-
}
69-
7063
Bangle.load = (o => (name) => {
7164
if (Bangle.uiRemove && !SETTINGS.hideLoading) loadingScreen();
72-
if (SETTINGS.useAppHistory){
73-
if (name && name!=".bootcde" && !(name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch)) {
74-
// store the name of the app to launch
75-
appHistory.push(name);
76-
} else if (name==".bootcde") { // when Bangle.showClock is called
77-
resetHistory();
78-
} else if (name=="quicklaunch.app.js" && SETTINGS.disregardQuicklaunch) {
79-
// do nothing with history
80-
} else {
81-
// go back in history
82-
appHistory.pop();
83-
name = appHistory[appHistory.length-1];
84-
}
85-
}
8665
if (SETTINGS.autoloadLauncher && !name){
8766
let orig = Bangle.load;
8867
Bangle.load = (n)=>{
@@ -94,6 +73,4 @@ Bangle.load = (o => (name) => {
9473
} else
9574
o(name);
9675
})(Bangle.load);
97-
98-
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.
9976
}

apps/fastload/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ "id": "fastload",
22
"name": "Fastload Utils",
33
"shortName" : "Fastload Utils",
4-
"version": "0.06",
4+
"version": "0.07",
55
"icon": "icon.png",
66
"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",

0 commit comments

Comments
 (0)