forked from FOSS/BangleApps
Take advantage of recent nonbreaking change that stops readJSON from causing errors
parent
3998688179
commit
6cfe9c340b
|
@ -306,6 +306,11 @@ See [apps/gpsrec/interface.html](the GPS Recorder) for a full example.
|
||||||
|
|
||||||
- 'Welcome' apps define a file called `welcome.js` which the booloader picks up. This then chain-loads the welcome app itself.
|
- '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.
|
||||||
|
|
||||||
|
- Locale is handled by `require("locale")`. An app may create a `locale` file in Storage which is
|
||||||
|
a module that overwrites Bangle.js's default locale.
|
||||||
|
|
||||||
|
|
||||||
### Graphic areas
|
### Graphic areas
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ g.drawString("Powered by Espruino",0,y+=4+h);
|
||||||
g.drawString("Version "+ENV.VERSION,0,y+=h);
|
g.drawString("Version "+ENV.VERSION,0,y+=h);
|
||||||
g.drawString("Commit "+ENV.GIT_COMMIT,0,y+=h);
|
g.drawString("Commit "+ENV.GIT_COMMIT,0,y+=h);
|
||||||
function getVersion(name,file) {
|
function getVersion(name,file) {
|
||||||
var j = s.readJSON(file);
|
var j = s.readJSON(file,1);
|
||||||
var v = ("object"==typeof j)?j.version:false;
|
var v = ("object"==typeof j)?j.version:false;
|
||||||
g.drawString(v?(name+" "+(v?"v"+v:"Unknown")):"NO "+name,0,y+=h);
|
g.drawString(v?(name+" "+(v?"v"+v:"Unknown")):"NO "+name,0,y+=h);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ function showAlarm(alarm) {
|
||||||
// Check for alarms
|
// Check for alarms
|
||||||
var day = (new Date()).getDate();
|
var day = (new Date()).getDate();
|
||||||
var hr = getCurrentHr();
|
var hr = getCurrentHr();
|
||||||
var alarms = require("Storage").readJSON("alarm.json")||[];
|
var alarms = require("Storage").readJSON("alarm.json",1)||[];
|
||||||
var active = alarms.filter(a=>a.on&&(a.hr<hr)&&(a.last!=day));
|
var active = alarms.filter(a=>a.on&&(a.hr<hr)&&(a.last!=day));
|
||||||
if (active.length) {
|
if (active.length) {
|
||||||
// if there's an alarm, show it
|
// if there's an alarm, show it
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
var alarms = require("Storage").readJSON("alarm.json")||[];
|
var alarms = require("Storage").readJSON("alarm.json",1)||[];
|
||||||
/*alarms = [
|
/*alarms = [
|
||||||
{ on : true,
|
{ on : true,
|
||||||
hr : 6.5, // hours + minutes/60
|
hr : 6.5, // hours + minutes/60
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(() => {
|
(() => {
|
||||||
var alarms = require('Storage').readJSON('alarm.json')||[];
|
var alarms = require('Storage').readJSON('alarm.json',1)||[];
|
||||||
alarms = alarms.filter(alarm=>alarm.on);
|
alarms = alarms.filter(alarm=>alarm.on);
|
||||||
if (!alarms.length) return;
|
if (!alarms.length) return;
|
||||||
delete alarms;
|
delete alarms;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// This ALWAYS runs at boot
|
// This ALWAYS runs at boot
|
||||||
E.setFlags({pretokenise:1});
|
E.setFlags({pretokenise:1});
|
||||||
// Load settings...
|
// Load settings...
|
||||||
var s = require('Storage').readJSON('setting.json')||{};
|
var s = require('Storage').readJSON('setting.json',1)||{};
|
||||||
if (s.ble!==false) {
|
if (s.ble!==false) {
|
||||||
if (s.HID) { // Human interface device
|
if (s.HID) { // Human interface device
|
||||||
Bangle.HID = E.toUint8Array(atob("BQEJBqEBhQIFBxngKecVACUBdQGVCIEClQF1CIEBlQV1AQUIGQEpBZEClQF1A5EBlQZ1CBUAJXMFBxkAKXOBAAkFFQAm/wB1CJUCsQLABQwJAaEBhQEVACUBdQGVAQm1gQIJtoECCbeBAgm4gQIJzYECCeKBAgnpgQIJ6oECwA=="));
|
Bangle.HID = E.toUint8Array(atob("BQEJBqEBhQIFBxngKecVACUBdQGVCIEClQF1CIEBlQV1AQUIGQEpBZEClQF1A5EBlQZ1CBUAJXMFBxkAKXOBAAkFFQAm/wB1CJUCsQLABQwJAaEBhQEVACUBdQGVAQm1gQIJtoECCbeBAgm4gQIJzYECCeKBAgnpgQIJ6oECwA=="));
|
||||||
|
@ -26,7 +26,7 @@ E.setTimeZone(s.timezone);
|
||||||
delete s;
|
delete s;
|
||||||
// check for alarms
|
// check for alarms
|
||||||
function checkAlarm() {
|
function checkAlarm() {
|
||||||
var alarms = require('Storage').readJSON('alarm.json')||[];
|
var alarms = require('Storage').readJSON('alarm.json',1)||[];
|
||||||
var time = new Date();
|
var time = new Date();
|
||||||
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate()));
|
var active = alarms.filter(a=>a.on&&(a.last!=time.getDate()));
|
||||||
if (active.length) {
|
if (active.length) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// This runs after a 'fresh' boot
|
// This runs after a 'fresh' boot
|
||||||
var settings={};
|
var settings=require("Storage").readJSON('setting.json',1)||{};
|
||||||
try { settings = require("Storage").readJSON('setting.json'); } catch (e) {}
|
|
||||||
if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) {
|
if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) {
|
||||||
setTimeout(()=>load("welcome.js"));
|
setTimeout(()=>load("welcome.js"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,10 +7,7 @@ if (!settings.welcomed && require("Storage").read("welcome.js")!==undefined) {
|
||||||
var clockApp = settings.clock;
|
var clockApp = settings.clock;
|
||||||
if (clockApp) clockApp = require("Storage").read(clockApp)
|
if (clockApp) clockApp = require("Storage").read(clockApp)
|
||||||
if (!clockApp) {
|
if (!clockApp) {
|
||||||
var clockApps = require("Storage").list(/\.info$/).map(app=>{
|
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);
|
||||||
try { return require("Storage").readJSON(app); }
|
|
||||||
catch (e) {}
|
|
||||||
}).filter(app=>app.type=="clock").sort((a, b) => a.sortorder - b.sortorder);
|
|
||||||
if (clockApps && clockApps.length > 0)
|
if (clockApps && clockApps.length > 0)
|
||||||
clockApp = require("Storage").read(clockApps[0].src);
|
clockApp = require("Storage").read(clockApps[0].src);
|
||||||
delete clockApps;
|
delete clockApps;
|
||||||
|
|
|
@ -69,7 +69,7 @@ function showApps() {
|
||||||
var list = storage.list(/\.info$/).filter((a)=> {
|
var list = storage.list(/\.info$/).filter((a)=> {
|
||||||
return a !== 'setting.info';
|
return a !== 'setting.info';
|
||||||
}).sort().map((app) => {
|
}).sort().map((app) => {
|
||||||
var ret = storage.readJSON(app);
|
var ret = storage.readJSON(app,1)||{};
|
||||||
ret[''] = app;
|
ret[''] = app;
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
var settings = require("Storage").readJSON("gpsrec.json")||{};
|
var settings = require("Storage").readJSON("gpsrec.json",1)||{};
|
||||||
|
|
||||||
function getFN(n) {
|
function getFN(n) {
|
||||||
return ".gpsrc"+n.toString(36);
|
return ".gpsrc"+n.toString(36);
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
|
|
||||||
// Called by the GPS app to reload settings and decide what's
|
// Called by the GPS app to reload settings and decide what's
|
||||||
function reload() {
|
function reload() {
|
||||||
settings = require("Storage").readJSON("gpsrec.json")||{};
|
settings = require("Storage").readJSON("gpsrec.json",1)||{};
|
||||||
settings.period = settings.period||1;
|
settings.period = settings.period||1;
|
||||||
settings.file |= 0;
|
settings.file |= 0;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ the touchscreen
|
||||||
|
|
||||||
var storage = require('Storage');
|
var storage = require('Storage');
|
||||||
|
|
||||||
const settings = storage.readJSON('setting.json') || { HID: false };
|
const settings = storage.readJSON('setting.json',1) || { HID: false };
|
||||||
const KEY = {
|
const KEY = {
|
||||||
A : 4 ,
|
A : 4 ,
|
||||||
B : 5 ,
|
B : 5 ,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var storage = require('Storage');
|
var storage = require('Storage');
|
||||||
|
|
||||||
const settings = storage.readJSON('setting.json') || { HID: false };
|
const settings = storage.readJSON('setting.json',1) || { HID: false };
|
||||||
|
|
||||||
var sendHid, next, prev, toggle, up, down, profile;
|
var sendHid, next, prev, toggle, up, down, profile;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
var storage = require('Storage');
|
var storage = require('Storage');
|
||||||
|
|
||||||
const settings = storage.readJSON('setting.json') || { HID: false };
|
const settings = storage.readJSON('setting.json',1) || { HID: false };
|
||||||
|
|
||||||
var sendHid, next, prev, toggle, up, down, profile;
|
var sendHid, next, prev, toggle, up, down, profile;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
var s = require("Storage");
|
var s = require("Storage");
|
||||||
var apps = s.list(/\.info$/).map(app=>{
|
var apps = s.list(/\.info$/).map(app=>s.readJSON(app,1)||{name:"DEAD: "+app.substr(1)}).filter(app=>app.type=="app" || app.type=="clock" || !app.type);
|
||||||
try { return s.readJSON(app); }
|
|
||||||
catch (e) { return {name:"DEAD: "+app.substr(1)} }
|
|
||||||
}).filter(app=>app.type=="app" || app.type=="clock" || !app.type);
|
|
||||||
apps.sort((a,b)=>{
|
apps.sort((a,b)=>{
|
||||||
var n=(0|a.sortorder)-(0|b.sortorder);
|
var n=(0|a.sortorder)-(0|b.sortorder);
|
||||||
if (n) return n; // do sortorder first
|
if (n) return n; // do sortorder first
|
||||||
|
|
|
@ -115,11 +115,9 @@ function info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
try {
|
var settings = require("Storage").readJSON('setting.json',1)||{};
|
||||||
var settings = require("Storage").readJSON('setting.json');
|
|
||||||
settings.welcomed = true;
|
settings.welcomed = true;
|
||||||
require("Storage").write('setting.json',settings);
|
require("Storage").write('setting.json',settings);
|
||||||
} catch (e) {}
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ const yposYear = 175;
|
||||||
const yposGMT = 220;
|
const yposGMT = 220;
|
||||||
|
|
||||||
// Check settings for what type our clock should be
|
// Check settings for what type our clock should be
|
||||||
var is12Hour = (require("Storage").readJSON("setting.json")||{})["12hour"];
|
var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"];
|
||||||
|
|
||||||
function drawSimpleClock() {
|
function drawSimpleClock() {
|
||||||
// get date
|
// get date
|
||||||
|
|
|
@ -27,9 +27,7 @@ function resetSettings() {
|
||||||
updateSettings();
|
updateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
settings = storage.readJSON('setting.json',1);
|
||||||
settings = storage.readJSON('setting.json');
|
|
||||||
} catch (e) {}
|
|
||||||
if (!settings) resetSettings();
|
if (!settings) resetSettings();
|
||||||
|
|
||||||
const boolFormat = v => v ? "On" : "Off";
|
const boolFormat = v => v ? "On" : "Off";
|
||||||
|
|
|
@ -283,11 +283,9 @@ 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) {
|
||||||
try {
|
|
||||||
var settings = require("Storage").readJSON('setting.json');
|
var settings = require("Storage").readJSON('setting.json');
|
||||||
settings.welcomed = true;
|
settings.welcomed = true;
|
||||||
require("Storage").write('setting.json',settings);
|
require("Storage").write('setting.json',settings);
|
||||||
} catch (e) {}
|
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
}, BTN2, {repeat:true,edge:"rising"});
|
}, BTN2, {repeat:true,edge:"rising"});
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
// add your widget
|
// add your widget
|
||||||
WIDGETS["wpedom"]={draw:draw};
|
WIDGETS["wpedom"]={draw:draw};
|
||||||
// Load data at startup
|
// Load data at startup
|
||||||
let pedomData = require("Storage").readJSON(PEDOMFILE);
|
let pedomData = require("Storage").readJSON(PEDOMFILE,1);
|
||||||
if (pedomData) {
|
if (pedomData) {
|
||||||
if (pedomData.lastUpdate)
|
if (pedomData.lastUpdate)
|
||||||
lastUpdate = new Date(pedomData.lastUpdate);
|
lastUpdate = new Date(pedomData.lastUpdate);
|
||||||
|
|
4
comms.js
4
comms.js
|
@ -32,7 +32,7 @@ getInstalledApps : () => {
|
||||||
return new Promise((resolve,reject) => {
|
return new Promise((resolve,reject) => {
|
||||||
Puck.write("\x03",(result) => {
|
Puck.write("\x03",(result) => {
|
||||||
if (result===null) return reject("");
|
if (result===null) return reject("");
|
||||||
Puck.eval('require("Storage").list(/\.info$/).map(f=>{var j=require("Storage").readJSON(f)||{};j.id=f.slice(0,-5);return j})', (appList,err) => {
|
Puck.eval('require("Storage").list(/\.info$/).map(f=>{var j=require("Storage").readJSON(f,1)||{};j.id=f.slice(0,-5);return j})', (appList,err) => {
|
||||||
if (appList===null) return reject(err || "");
|
if (appList===null) return reject(err || "");
|
||||||
console.log("getInstalledApps", appList);
|
console.log("getInstalledApps", appList);
|
||||||
resolve(appList);
|
resolve(appList);
|
||||||
|
@ -68,7 +68,7 @@ setTime : () => {
|
||||||
var cmd = '\x03\x10setTime('+(d.getTime()/1000)+');';
|
var cmd = '\x03\x10setTime('+(d.getTime()/1000)+');';
|
||||||
// in 1v93 we have timezones too
|
// in 1v93 we have timezones too
|
||||||
cmd += 'E.setTimeZone('+tz+');';
|
cmd += 'E.setTimeZone('+tz+');';
|
||||||
cmd += "(s=>{s&&(s.timezone="+tz+")&&require('Storage').write('setting.json',s);})(require('Storage').readJSON('setting.json'))\n";
|
cmd += "(s=>{s&&(s.timezone="+tz+")&&require('Storage').write('setting.json',s);})(require('Storage').readJSON('setting.json',1))\n";
|
||||||
Puck.write(cmd, (result) => {
|
Puck.write(cmd, (result) => {
|
||||||
if (result===null) return reject("");
|
if (result===null) return reject("");
|
||||||
resolve();
|
resolve();
|
||||||
|
|
Loading…
Reference in New Issue