mirror of https://github.com/espruino/BangleApps
Added Utils.readStorageJSON and relaxed JSON parser, and swap all interface.html over
to using it. This allows Bangle.js 2v20 (or cutting edge) and later to store a relaxed 'JSON' on internal storage which (while still normal JS) is smaller and faster (and preserves unicode better) See https://github.com/espruino/Espruino/issues/2429pull/3110/head
parent
0e4fa182eb
commit
fcebbf3ef4
|
@ -178,9 +178,8 @@ function getData() {
|
||||||
})()\n`, contents => {
|
})()\n`, contents => {
|
||||||
const fileNames = JSON.parse(contents);
|
const fileNames = JSON.parse(contents);
|
||||||
if (fileNames.length > 0) {
|
if (fileNames.length > 0) {
|
||||||
Util.readStorage('calendar.days.json',data=>{
|
Util.readStorageJSON('calendar.days.json',data=>{
|
||||||
holidays = JSON.parse(data || "[]") || [];
|
holidays = data || [];
|
||||||
|
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
|
|
|
@ -83,11 +83,8 @@
|
||||||
|
|
||||||
function onInit() {
|
function onInit() {
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
Util.readStorage("espruinoterm.json", function(j) {
|
Util.readStorageJSON("espruinoterm.json", function(options) {
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
try {
|
|
||||||
options = JSON.parse(j);
|
|
||||||
} catch (e) {}
|
|
||||||
if (!Array.isArray(options)) setDefaults();
|
if (!Array.isArray(options)) setDefaults();
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,11 +76,11 @@
|
||||||
function getData() {
|
function getData() {
|
||||||
// show loading window
|
// show loading window
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
Util.readStorage('grocery_list.json', data=>{
|
Util.readStorageJSON('grocery_list.json', data=>{
|
||||||
// remove window
|
// remove window
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
|
|
||||||
settings = JSON.parse(data || '{"products": []}');
|
settings = data || {"products": []};
|
||||||
products = settings.products;
|
products = settings.products;
|
||||||
renderProducts();
|
renderProducts();
|
||||||
});
|
});
|
||||||
|
|
|
@ -211,9 +211,9 @@
|
||||||
this.editSong = song;
|
this.editSong = song;
|
||||||
},
|
},
|
||||||
loadSongs: function () {
|
loadSongs: function () {
|
||||||
Util.readStorage('guitar_songs.json', (contents) => {
|
Util.readStorageJSON('guitar_songs.json', (contents) => {
|
||||||
this.songsState = 'loaded';
|
this.songsState = 'loaded';
|
||||||
this.localSongs = JSON.parse(contents) || [];
|
this.localSongs = contents || [];
|
||||||
this.watchSongs = JSON.parse(JSON.stringify(this.localSongs));
|
this.watchSongs = JSON.parse(JSON.stringify(this.localSongs));
|
||||||
});
|
});
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
|
|
|
@ -98,11 +98,10 @@
|
||||||
|
|
||||||
function onInit() {
|
function onInit() {
|
||||||
// read existing location
|
// read existing location
|
||||||
Util.readStorage("mylocation.json", function(data) {
|
Util.readStorageJSON("mylocation.json", function(data) {
|
||||||
if (data===undefined) return; // no file
|
if (data===undefined) return; // no file
|
||||||
try {
|
try {
|
||||||
var j = JSON.parse(data);
|
setPosition(data);
|
||||||
setPosition(j);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ function disableFormInput() {
|
||||||
function getData() {
|
function getData() {
|
||||||
// show loading window
|
// show loading window
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
Util.readStorage(`noteify.json`,data=>{
|
Util.readStorageJSON(`noteify.json`,data=>{
|
||||||
notes = JSON.parse(data || "[]");
|
notes = data || [];
|
||||||
|
|
||||||
// remove window
|
// remove window
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
|
|
|
@ -150,15 +150,9 @@ TODO:
|
||||||
files.trim().split(",").forEach(filename => {
|
files.trim().split(",").forEach(filename => {
|
||||||
if (filename=="") return;
|
if (filename=="") return;
|
||||||
promise = promise.then(() => new Promise(resolve => {
|
promise = promise.then(() => new Promise(resolve => {
|
||||||
Util.readStorage(filename, fileContents => {
|
Util.readStorageJSON(filename, mapInfo => {
|
||||||
console.log(filename + " => " + fileContents);
|
console.log(filename + " => " + mapInfo);
|
||||||
let mapNumber = filename.match(/\d+/)[0]; // figure out what map number we are
|
let mapNumber = filename.match(/\d+/)[0]; // figure out what map number we are
|
||||||
let mapInfo;
|
|
||||||
try {
|
|
||||||
mapInfo = JSON.parse(fileContents);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
loadedMaps[mapNumber] = mapInfo;
|
loadedMaps[mapNumber] = mapInfo;
|
||||||
if (mapInfo!==undefined) {
|
if (mapInfo!==undefined) {
|
||||||
let latlon = L.latLng(mapInfo.lat, mapInfo.lon);
|
let latlon = L.latLng(mapInfo.lat, mapInfo.lon);
|
||||||
|
|
|
@ -28,9 +28,8 @@
|
||||||
function onInit(){
|
function onInit(){
|
||||||
console.log("Loading settings from BangleJs...");
|
console.log("Loading settings from BangleJs...");
|
||||||
try {
|
try {
|
||||||
Util.readStorage("owmweather.json", data=>{
|
Util.readStorageJSON("owmweather.json", settings=>{
|
||||||
if(data.length > 0){
|
if("settings){
|
||||||
settings = JSON.parse(data);
|
|
||||||
console.log("Got settings", settings);
|
console.log("Got settings", settings);
|
||||||
document.getElementById("apikey").value = settings.apikey;
|
document.getElementById("apikey").value = settings.apikey;
|
||||||
console.log("Loaded apikey from BangleJs.");
|
console.log("Loaded apikey from BangleJs.");
|
||||||
|
|
|
@ -101,11 +101,9 @@ function viewDeferredTable(filename) {
|
||||||
Puck.eval(`require("Storage").list("powermanager.def.json").length > 0`, (f)=>{
|
Puck.eval(`require("Storage").list("powermanager.def.json").length > 0`, (f)=>{
|
||||||
if (f) {
|
if (f) {
|
||||||
Util.showModal("Reading summarized info...");
|
Util.showModal("Reading summarized info...");
|
||||||
Util.readStorage(
|
Util.readStorageJSON(
|
||||||
filename, data => {
|
filename, parsed => {
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
let parsed = JSON.parse(data);
|
|
||||||
|
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
let rows = [];
|
let rows = [];
|
||||||
for (var i in parsed.deferred) {
|
for (var i in parsed.deferred) {
|
||||||
|
@ -181,10 +179,9 @@ function viewHardwareTable(filename) {
|
||||||
Puck.eval(`require("Storage").list("powermanager.hw.json").length > 0`, (f)=>{
|
Puck.eval(`require("Storage").list("powermanager.hw.json").length > 0`, (f)=>{
|
||||||
if (f) {
|
if (f) {
|
||||||
Util.showModal("Reading hardware info...");
|
Util.showModal("Reading hardware info...");
|
||||||
Util.readStorage(
|
Util.readStorageJSON(
|
||||||
filename, data => {
|
filename, parsed => {
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
let parsed = JSON.parse(data);
|
|
||||||
console.log("Hardware", parsed);
|
console.log("Hardware", parsed);
|
||||||
let duration = parsed.saved - parsed.start;
|
let duration = parsed.saved - parsed.start;
|
||||||
|
|
||||||
|
|
|
@ -101,10 +101,8 @@ function getData() {
|
||||||
uploadBtn.disabled = true;
|
uploadBtn.disabled = true;
|
||||||
|
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
Util.readStorage(repJson, data => {
|
Util.readStorageJSON(repJson, reps => {
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
|
|
||||||
reps = JSON.parse(data);
|
|
||||||
for(const rep of reps){
|
for(const rep of reps){
|
||||||
renderRep(rep);
|
renderRep(rep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,11 +265,11 @@ function addTimer() {
|
||||||
|
|
||||||
function getData() {
|
function getData() {
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
Util.readStorage('sched.json',data=>{
|
Util.readStorageJSON('sched.json',data=>{
|
||||||
alarms = JSON.parse(data || "[]") || [];
|
alarms = data || [];
|
||||||
|
|
||||||
Util.readStorage('sched.settings.json',data=>{
|
Util.readStorageJSON('sched.settings.json',data=>{
|
||||||
schedSettings = JSON.parse(data || "{}") || {};
|
schedSettings = data || {};
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
alarms.sort((a, b) => {
|
alarms.sort((a, b) => {
|
||||||
let x;
|
let x;
|
||||||
|
|
|
@ -25,8 +25,8 @@ function getData() {
|
||||||
// show loading window
|
// show loading window
|
||||||
Util.showModal("Loading...");
|
Util.showModal("Loading...");
|
||||||
// get the data
|
// get the data
|
||||||
Util.readStorage('sleepphasealarm.json',data=>{
|
Util.readStorageJSON('sleepphasealarm.json',data=>{
|
||||||
let logs = JSON.parse(data || "{}")?.logs || [];
|
let logs = (data || {})?.logs || [];
|
||||||
// remove window
|
// remove window
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
function onInit(){
|
function onInit(){
|
||||||
console.log("Loading settings from BangleJs...");
|
console.log("Loading settings from BangleJs...");
|
||||||
try {
|
try {
|
||||||
Util.readStorage("tinycmc.json", data=>{
|
Util.readStorageJSON("tinycmc.json", data=>{
|
||||||
if(data.length > 0){
|
if(data){
|
||||||
settings = JSON.parse(data);
|
settings = data;
|
||||||
console.log("Got settings", settings);
|
console.log("Got settings", settings);
|
||||||
document.getElementById("apikey").value = settings.apikey;
|
document.getElementById("apikey").value = settings.apikey;
|
||||||
console.log("Loaded apikey from BangleJs.");
|
console.log("Loaded apikey from BangleJs.");
|
||||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 4422e4a3e808c99e540dc86ac1e3cab0ccb23a82
|
Subproject commit c97b7851f50cfff4e898c2264a337a17085ce463
|
Loading…
Reference in New Issue