Merge pull request #230 from rigrig/welcome

Move loading of welcome to boot.js
master
Gordon Williams 2020-04-07 09:02:09 +01:00 committed by GitHub
commit 858d979f00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 82 additions and 61 deletions

View File

@ -385,8 +385,6 @@ That way removing the app also cleans up `app.settings.json`.
- Need to save state? Use the `E.on('kill',...)` event to save JSON to a file called `7chname.json`, then load it at startup. - Need to save state? Use the `E.on('kill',...)` event to save JSON to a file called `7chname.json`, then load it at startup.
- 'Welcome' apps define a file called `welcome.js` which the booloader picks up. This then chain-loads the welcome app itself.
- 'Alarm' apps define a file called `alarm.js` which handles the actual alarm window. - 'Alarm' apps define a file called `alarm.js` which handles the actual alarm window.
- Locale is handled by `require("locale")`. An app may create a `locale` file in Storage which is - Locale is handled by `require("locale")`. An app may create a `locale` file in Storage which is

View File

@ -2,7 +2,7 @@
{ "id": "boot", { "id": "boot",
"name": "Bootloader", "name": "Bootloader",
"icon": "bootloader.png", "icon": "bootloader.png",
"version":"0.13", "version":"0.14",
"description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings", "description": "This is needed by Bangle.js to automatically load the clock, menu, widgets and settings",
"tags": "tool,system", "tags": "tool,system",
"type":"bootloader", "type":"bootloader",
@ -78,12 +78,12 @@
{ "id": "welcome", { "id": "welcome",
"name": "Welcome", "name": "Welcome",
"icon": "app.png", "icon": "app.png",
"version":"0.05", "version":"0.06",
"description": "Appears at first boot and explains how to use Bangle.js", "description": "Appears at first boot and explains how to use Bangle.js",
"tags": "start,welcome", "tags": "start,welcome",
"allow_emulator":true, "allow_emulator":true,
"storage": [ "storage": [
{"name":"welcome.js","url":"welcome.js"}, {"name":"welcome.boot.js","url":"boot.js"},
{"name":"welcome.app.js","url":"app.js"}, {"name":"welcome.app.js","url":"app.js"},
{"name":"welcome.settings.js","url":"settings.js"}, {"name":"welcome.settings.js","url":"settings.js"},
{"name":"welcome.img","url":"app-icon.js","evaluate":true} {"name":"welcome.img","url":"app-icon.js","evaluate":true}
@ -504,12 +504,13 @@
"id": "ncstart", "id": "ncstart",
"name": "NCEU Startup", "name": "NCEU Startup",
"icon": "start.png", "icon": "start.png",
"version":"0.02", "version":"0.03",
"description": "NodeConfEU 2019 'First Start' Sequence", "description": "NodeConfEU 2019 'First Start' Sequence",
"tags": "start,welcome", "tags": "start,welcome",
"storage": [ "storage": [
{"name":"welcome.js","url":"welcome.js"},
{"name":"ncstart.app.js","url":"start.js"}, {"name":"ncstart.app.js","url":"start.js"},
{"name":"ncstart.boot.js","url":"boot.js"},
{"name":"ncstart.settings.js","url":"settings.js"},
{"name":"ncstart.img","url":"start-icon.js","evaluate":true}, {"name":"ncstart.img","url":"start-icon.js","evaluate":true},
{"name":"nc-bangle.img","url":"start-bangle.js","evaluate":true}, {"name":"nc-bangle.img","url":"start-bangle.js","evaluate":true},
{"name":"nc-nceu.img","url":"start-nceu.js","evaluate":true}, {"name":"nc-nceu.img","url":"start-nceu.js","evaluate":true},

View File

@ -12,3 +12,4 @@
0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147) 0.12: Add an event on BTN2 to open launcher when no clock detected (fix #147)
0.13: Now automatically load *.boot.js at startup 0.13: Now automatically load *.boot.js at startup
Move alarm code into alarm.boot.js Move alarm code into alarm.boot.js
0.14: Move welcome loaders to *.boot.js

View File

@ -40,6 +40,6 @@ delete s;
// stop users doing bad things! // stop users doing bad things!
global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); } global.save = function() { throw new Error("You can't use save() on Bangle.js without overwriting the bootloader!"); }
// Load *.boot.js files // Load *.boot.js files
var clockApps = require('Storage').list(/\.boot\.js/).map(bootFile=>{ require('Storage').list(/\.boot\.js/).map(bootFile=>{
eval(require('Storage').read(bootFile)); eval(require('Storage').read(bootFile));
}); });

View File

@ -1,42 +1,38 @@
// This runs after a 'fresh' boot // This runs after a 'fresh' boot
var settings=require("Storage").readJSON('setting.json',1)||{}; var settings=require("Storage").readJSON('setting.json',1)||{};
if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) { // load clock if specified
setTimeout(()=>load("welcome.js")); var clockApp = settings.clock;
} else { if (clockApp) clockApp = require("Storage").read(clockApp)
// load clock if specified if (!clockApp) {
var clockApp = settings.clock; var clockApps = require("Storage").list(/\.info$/).map(app=>require("Storage").readJSON(app,1)||{}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder);
if (clockApp) clockApp = require("Storage").read(clockApp) if (clockApps && clockApps.length > 0)
if (!clockApp) { clockApp = require("Storage").read(clockApps[0].src);
var clockApps = require("Storage").list(/\.info$/).map(app=>require("Storage").readJSON(app,1)||{}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder); delete clockApps;
if (clockApps && clockApps.length > 0) }
clockApp = require("Storage").read(clockApps[0].src); if (!clockApp) clockApp=`E.showMessage("No Clock Found");
delete clockApps; setWatch(() => {
} Bangle.showLauncher();
if (!clockApp) clockApp=`E.showMessage("No Clock Found"); }, BTN2, {repeat:false,edge:"falling"});)
setWatch(() => { `;
Bangle.showLauncher(); delete settings;
}, BTN2, {repeat:false,edge:"falling"});) // check to see if our clock is wrong - if it is use GPS time
`; if ((new Date()).getFullYear()==1970) {
delete settings; E.showMessage("Searching for\nGPS time");
// check to see if our clock is wrong - if it is use GPS time Bangle.on('GPS',function cb(g) {
if ((new Date()).getFullYear()==1970) { Bangle.setGPSPower(0);
E.showMessage("Searching for\nGPS time"); Bangle.removeListener("GPS",cb);
Bangle.on('GPS',function cb(g) { if (!g.time || (g.time.getFullYear()<2000) ||
Bangle.setGPSPower(0); (g.time.getFullYear()==2250)) {
Bangle.removeListener("GPS",cb); // GPS receiver's time not set - just boot clock anyway
if (!g.time || (g.time.getFullYear()<2000) || eval(clockApp);delete clockApp;
(g.time.getFullYear()==2250)) { return;
// GPS receiver's time not set - just boot clock anyway }
eval(clockApp);delete clockApp; // We have a GPS time. Set time and reboot (to load alarms properly)
return; setTime(g.time.getTime()/1000);
} load();
// We have a GPS time. Set time and reboot (to load alarms properly) });
setTime(g.time.getTime()/1000); Bangle.setGPSPower(1);
load(); } else {
}); eval(clockApp);
Bangle.setGPSPower(1); delete clockApp;
} else {
eval(clockApp);
delete clockApp;
}
} }

View File

@ -1,2 +1,4 @@
0.02: Modified for use with new bootloader and firmware 0.02: Modified for use with new bootloader and firmware
Renamed as nodeconf-specific Renamed as nodeconf-specific
0.03: Move configuration into App/widget settings
Move loader into welcome.boot.js

10
apps/ncstart/boot.js Normal file
View File

@ -0,0 +1,10 @@
(function() {
let s = require('Storage').readJSON('setting.json', 1) || {}
if (!s.welcomed && require('Storage').read('ncstart.app.js')) {
setTimeout(() => {
s.welcomed = true
require('Storage').write('setting.json', s)
load('ncstart.app.js')
})
}
})()

16
apps/ncstart/settings.js Normal file
View File

@ -0,0 +1,16 @@
// The welcome app is special, and gets to use global settings
(function(back) {
let settings = require('Storage').readJSON('setting.json', 1) || {}
E.showMenu({
'': { 'title': 'NCEU Startup' },
'Run again': {
value: !settings.welcomed,
format: v => v ? 'Yes' : 'No',
onchange: v => {
settings.welcomed = v ? undefined : true
require('Storage').write('setting.json', settings)
},
},
'< Back': back,
})
})

View File

@ -114,15 +114,7 @@ function info() {
}); });
} }
function cleanup() {
var settings = require("Storage").readJSON('setting.json',1)||{};
settings.welcomed = true;
require("Storage").write('setting.json',settings);
return Promise.resolve();
}
welcome() welcome()
.then(logos) .then(logos)
.then(info) .then(info)
.then(cleanup)
.then(load); .then(load);

View File

@ -1 +0,0 @@
eval(require("Storage").read("ncstart.app.js"))

View File

@ -3,3 +3,4 @@
0.03: BTN3 now won't restart when at the end 0.03: BTN3 now won't restart when at the end
0.04: Fix regression after tweaks to Storage.readJSON 0.04: Fix regression after tweaks to Storage.readJSON
0.05: Move configuration into App/widget settings 0.05: Move configuration into App/widget settings
0.06: Move loader into welcome.boot.js

View File

@ -283,16 +283,12 @@ setWatch(()=>move(1), BTN3, {repeat:true});
setWatch(()=>{ setWatch(()=>{
// If we're on the last page // If we're on the last page
if (sceneNumber == scenes.length-1) { if (sceneNumber == scenes.length-1) {
var settings = require("Storage").readJSON('setting.json',1)||{};
settings.welcomed = true;
require("Storage").write('setting.json',settings);
load(); load();
} }
}, BTN2, {repeat:true,edge:"rising"}); }, BTN2, {repeat:true,edge:"rising"});
setWatch(()=>move(-1), BTN1, {repeat:true}); setWatch(()=>move(-1), BTN1, {repeat:true});
Bangle.setLCDTimeout(0); Bangle.setLCDTimeout(0);
Bangle.setLCDPower(1); Bangle.setLCDPower(1);
move(0); move(0);

10
apps/welcome/boot.js Normal file
View File

@ -0,0 +1,10 @@
(function() {
let s = require('Storage').readJSON('setting.json', 1) || {}
if (!s.welcomed && require('Storage').read('welcome.app.js')) {
setTimeout(() => {
s.welcomed = true
require('Storage').write('setting.json', s)
load('welcome.app.js')
})
}
})()

View File

@ -1 +0,0 @@
eval(require("Storage").read("welcome.app.js"))