diff --git a/apps/apphist/ChangeLog b/apps/apphist/ChangeLog new file mode 100644 index 0000000000..4113605ff2 --- /dev/null +++ b/apps/apphist/ChangeLog @@ -0,0 +1,2 @@ +0.01: New App! (Break out from Fastload Utils app) +0.02: Don't use settings. diff --git a/apps/apphist/README.md b/apps/apphist/README.md new file mode 100644 index 0000000000..9fe5173c22 --- /dev/null +++ b/apps/apphist/README.md @@ -0,0 +1,18 @@ +# App history + +* 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. + +# Notes + +* Quick Launch app does not get remarked in history. + +TODO: +* 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.) + +# Creator + +[thyttan](https://github.com/thyttan) +[halemmerich](https://github.com/halemmerich) (Fastload Utils) + +# Contributors + diff --git a/apps/apphist/boot.js b/apps/apphist/boot.js new file mode 100644 index 0000000000..fe12683bc0 --- /dev/null +++ b/apps/apphist/boot.js @@ -0,0 +1,56 @@ +{ +// 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. + +// 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. + +//Commented out calling the settings object. Seemed like a waste of resources. + +const s = require("Storage"); +//const SETTINGS = s.readJSON("apphist.settings.json") || {}; + +global._load = global.load; +Bangle._load = Bangle.load; + +let appHistory = s.readJSON("apphist.json",true)||[]; +const resetHistory = ()=>{appHistory=[];s.writeJSON("apphist.json",appHistory);}; +const recordHistory = ()=>{s.writeJSON("apphist.json",appHistory);}; + +const traverseHistory = (name)=>{ + 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]; + } + return name; +}; + +const addHistoryTraversal = (loadFn => (name) => { + name = traverseHistory(name); + loadFn(name); +}); + +const addHistoryTraversalFastload = (loadFn => (name) => { + global.load = global._load; // Only run through traverseHistory once, not both for Bangle.load and global.load. + name = traverseHistory(name); + loadFn(name); + global.load = globalLoadWithHistory; +}); + +const globalLoadWithHistory = addHistoryTraversal(global.load); +global.load = globalLoadWithHistory; +Bangle.load = addHistoryTraversalFastload(Bangle._load); + +E.on('kill', ()=>{ + // Usually record history, but reset it if long press of HW button was used. + // FIXME: May be tricky for user to release button quickly enough to not trigger resetHistory. Commented out for now. + // if (!BTN.read()) recordHistory(); else resetHistory(); + recordHistory(); +}); +} diff --git a/apps/apphist/icon.png b/apps/apphist/icon.png new file mode 100644 index 0000000000..2ae70f71b6 Binary files /dev/null and b/apps/apphist/icon.png differ diff --git a/apps/apphist/metadata.json b/apps/apphist/metadata.json new file mode 100644 index 0000000000..0054036b02 --- /dev/null +++ b/apps/apphist/metadata.json @@ -0,0 +1,16 @@ +{ "id": "apphist", + "name": "App History", + "version": "0.02", + "icon": "icon.png", + "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.", + "type":"bootloader", + "tags": "system", + "supports": ["BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"apphist.4.boot.js","url":"boot.js"} + ], + "data": [ + {"name":"apphist.json"} + ] +} diff --git a/apps/apphist/settings.js b/apps/apphist/settings.js new file mode 100644 index 0000000000..a40f38a5a1 --- /dev/null +++ b/apps/apphist/settings.js @@ -0,0 +1,38 @@ +//Settings has been disabled for apphist. But we leave this file for potential future use. + +(function(back) { + var FILE="apphist.settings.json"; + var settings; + var isQuicklaunchPresent = !!require('Storage').read("quicklaunch.app.js", 0, 1); + + 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 = {}; + + mainmenu[''] = { 'title': 'App History', back: back }; + + if (isQuicklaunchPresent) { + mainmenu['Exclude Quick Launch from history'] = { + value: !!settings.disregardQuicklaunch, + onchange: v => { + writeSettings("disregardQuicklaunch",v); + } + }; + } + return mainmenu; + } + + E.showMenu(buildMainMenu()); +}) diff --git a/apps/confthyttan/ChangeLog b/apps/confthyttan/ChangeLog index 392b10aa3c..6c12e94c64 100644 --- a/apps/confthyttan/ChangeLog +++ b/apps/confthyttan/ChangeLog @@ -9,3 +9,5 @@ 0.08: hide bt indicator when connected (`widbt_notify`). Add "Message Twist to Scroll". Add "Big Clock Info app". Auto open messages if locked. +0.09: remove fastload utils as it's functionality is more or less included in + firmware now. Fix to handle the new widget theme colors. diff --git a/apps/confthyttan/metadata.json b/apps/confthyttan/metadata.json index e9886afa49..327a0f7bfc 100644 --- a/apps/confthyttan/metadata.json +++ b/apps/confthyttan/metadata.json @@ -1,6 +1,6 @@ { "id": "confthyttan", "name": "Thyttan's Default Config", - "version":"0.08", + "version":"0.09", "author": "thyttan", "description": "A different default set of apps and configurations. Makes many quality of life changes. Opinionated based on the creators taste. Read more below before installing.", "icon": "app.png", @@ -39,10 +39,10 @@ "autoreset":"app", "chargent":"app", "setting":"app", - "fastload":"app", "boot":"app", "ateatimer":"app", "bigclkinfo":"app", + "apphist":"app", "drained":"app" }, "storage": [ @@ -52,8 +52,6 @@ "url":"autoreset.json"}, {"name":"dtlaunch.json", "url":"dtlaunch.json"}, - {"name":"fastload.json", - "url":"fastload.json"}, {"name":"quicklaunch.json", "url":"quicklaunch.json"}, {"name":"messages.settings.json", diff --git a/apps/confthyttan/setting.json b/apps/confthyttan/setting.json index ece0c87edf..5905e4ec39 100644 --- a/apps/confthyttan/setting.json +++ b/apps/confthyttan/setting.json @@ -1 +1 @@ -{ble:true,blerepl:true,log:false,quiet:0,timeout:10,vibrate:true,beep:true,timezone:2,HID:false,clock:"edgeclk.app.js","12hour":false,firstDayOfWeek:1,brightness:0.5,options:{wakeOnBTN1:true,wakeOnBTN2:true,wakeOnBTN3:true,wakeOnFaceUp:false,wakeOnTouch:false,wakeOnTwist:false,twistThreshold:819.2,twistMaxY:-800,twistTimeout:1000,btnLoadTimeout:700},theme:{fg:65535,bg:0,fg2:65535,bg2:8,fgH:65535,bgH:31,dark:true},clockHasWidgets:true,launcher:"dtlaunch.app.js",touch:{x1:6,y1:14,x2:197,y2:178}} +{ble:true,blerepl:true,log:false,quiet:0,timeout:10,vibrate:true,beep:true,timezone:2,HID:false,clock:"edgeclk.app.js","12hour":false,firstDayOfWeek:1,brightness:0.5,options:{wakeOnBTN1:true,wakeOnBTN2:true,wakeOnBTN3:true,wakeOnFaceUp:false,wakeOnTouch:false,wakeOnTwist:false,twistThreshold:819.2,twistMaxY:-800,twistTimeout:1000,btnLoadTimeout:700},theme:{fg:65535,bg:0,fg2:65535,bg2:8,fgH:65535,bgH:31,fgW:65535,bgW:0,dark:true},clockHasWidgets:true,launcher:"dtlaunch.app.js",touch:{x1:6,y1:14,x2:197,y2:178}} diff --git a/apps/fastload/ChangeLog b/apps/fastload/ChangeLog index 6581e51889..cdbf62ec08 100644 --- a/apps/fastload/ChangeLog +++ b/apps/fastload/ChangeLog @@ -4,3 +4,4 @@ 0.04: (WIP) Allow use of app history when going back (`load()` or `Bangle.load()` calls without specified app). 0.05: Check for changes in setting.js and force real reload if needed 0.06: Fix caching whether an app is fastloadable +0.07: Break out app history to a separate app: App History, `apphist`. diff --git a/apps/fastload/README.md b/apps/fastload/README.md index e32ec50825..3e658d6eb6 100644 --- a/apps/fastload/README.md +++ b/apps/fastload/README.md @@ -1,7 +1,9 @@ -#### ⚠️EXPERIMENTAL⚠️ +#### ⚠️DEPRECATED⚠️ ⚠️EXPERIMENTAL⚠️ # Fastload Utils +**Deprecated.** This app's functionality has to a large extent been integrated into firmware, with slight adjustments. + **Use this with caution.** When you find something misbehaving please check if the problem actually persists without Fastload Utils before filing an issue. @@ -18,17 +20,10 @@ Bangle will just end up with a memory leak or undefined behaviour** ## Settings -* Activate app history and navigate back through recent apps instead of immediately loading the clock face -* If Quick Launch is installed it can be excluded from app history * Allows to redirect all loads usually loading the clock to the launcher instead * The "Fastloading..." screen can be switched off * Enable checking `setting.json` and force a complete load on changes -## App history - -* Long press of hardware button clears the app history and loads the clock face -* 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. - ## Technical Notes 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. diff --git a/apps/fastload/boot.js b/apps/fastload/boot.js index 57bc8ea949..eaa7906470 100644 --- a/apps/fastload/boot.js +++ b/apps/fastload/boot.js @@ -60,29 +60,8 @@ let fastload = function(n){ }; global.load = fastload; -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);}; -} - Bangle.load = (o => (name) => { if (Bangle.uiRemove && !SETTINGS.hideLoading) loadingScreen(); - 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)=>{ @@ -94,6 +73,4 @@ Bangle.load = (o => (name) => { } else o(name); })(Bangle.load); - -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. } diff --git a/apps/fastload/metadata.json b/apps/fastload/metadata.json index 77d29dbe0d..eed264633c 100644 --- a/apps/fastload/metadata.json +++ b/apps/fastload/metadata.json @@ -1,9 +1,9 @@ { "id": "fastload", "name": "Fastload Utils", "shortName" : "Fastload Utils", - "version": "0.06", + "version": "0.07", "icon": "icon.png", - "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.", + "description": "Deprecated. Enable experimental fastloading for more apps. ⚠️ Use with extreme caution - many apps are not compatible with fastload and will cause memory leaks and instability.", "type":"bootloader", "tags": "system", "supports": ["BANGLEJS2"], diff --git a/apps/fastload/settings.js b/apps/fastload/settings.js index 15c135fe41..f07f649c62 100644 --- a/apps/fastload/settings.js +++ b/apps/fastload/settings.js @@ -1,7 +1,6 @@ (function(back) { var FILE="fastload.json"; var settings; - var isQuicklaunchPresent = !!require('Storage').read("quicklaunch.app.js", 0, 1); function writeSettings(key, value) { var s = require('Storage').readJSON(FILE, true) || {}; @@ -21,34 +20,10 @@ mainmenu[''] = { 'title': 'Fastload', back: back }; - mainmenu['Activate app history'] = { - value: !!settings.useAppHistory, - onchange: v => { - writeSettings("useAppHistory",v); - if (v && settings.autoloadLauncher) { - writeSettings("autoloadLauncher",!v); // Don't use app history and load to launcher together. - setTimeout(()=>E.showMenu(buildMainMenu()), 0); // Update the menu so it can be seen if a value was automatically set to false (app history vs load launcher). - } - } - }; - - if (isQuicklaunchPresent) { - mainmenu['Exclude Quick Launch from history'] = { - value: !!settings.disregardQuicklaunch, - onchange: v => { - writeSettings("disregardQuicklaunch",v); - } - }; - } - mainmenu['Force load to launcher'] = { value: !!settings.autoloadLauncher, onchange: v => { writeSettings("autoloadLauncher",v); - if (v && settings.useAppHistory) { - writeSettings("useAppHistory",!v); - setTimeout(()=>E.showMenu(buildMainMenu()), 0); // Update the menu so it can be seen if a value was automatically set to false (app history vs load launcher). - } // Don't use app history and load to launcher together. } };