mirror of https://github.com/espruino/BangleApps
Merge pull request #3110 from espruino/relaxed_json
Added Utils.readStorageJSON with relaxed JSON parserpull/3119/head
commit
c7efd4fc10
|
@ -178,9 +178,8 @@ function getData() {
|
|||
})()\n`, contents => {
|
||||
const fileNames = JSON.parse(contents);
|
||||
if (fileNames.length > 0) {
|
||||
Util.readStorage('calendar.days.json',data=>{
|
||||
holidays = JSON.parse(data || "[]") || [];
|
||||
|
||||
Util.readStorageJSON('calendar.days.json',data=>{
|
||||
holidays = data || [];
|
||||
Util.hideModal();
|
||||
render();
|
||||
});
|
||||
|
|
|
@ -83,11 +83,8 @@
|
|||
|
||||
function onInit() {
|
||||
Util.showModal("Loading...");
|
||||
Util.readStorage("espruinoterm.json", function(j) {
|
||||
Util.readStorageJSON("espruinoterm.json", function(options) {
|
||||
Util.hideModal();
|
||||
try {
|
||||
options = JSON.parse(j);
|
||||
} catch (e) {}
|
||||
if (!Array.isArray(options)) setDefaults();
|
||||
refresh();
|
||||
});
|
||||
|
|
|
@ -76,11 +76,11 @@
|
|||
function getData() {
|
||||
// show loading window
|
||||
Util.showModal("Loading...");
|
||||
Util.readStorage('grocery_list.json', data=>{
|
||||
Util.readStorageJSON('grocery_list.json', data=>{
|
||||
// remove window
|
||||
Util.hideModal();
|
||||
|
||||
settings = JSON.parse(data || '{"products": []}');
|
||||
settings = data || {"products": []};
|
||||
products = settings.products;
|
||||
renderProducts();
|
||||
});
|
||||
|
|
|
@ -211,9 +211,9 @@
|
|||
this.editSong = song;
|
||||
},
|
||||
loadSongs: function () {
|
||||
Util.readStorage('guitar_songs.json', (contents) => {
|
||||
Util.readStorageJSON('guitar_songs.json', (contents) => {
|
||||
this.songsState = 'loaded';
|
||||
this.localSongs = JSON.parse(contents) || [];
|
||||
this.localSongs = contents || [];
|
||||
this.watchSongs = JSON.parse(JSON.stringify(this.localSongs));
|
||||
});
|
||||
window.setTimeout(() => {
|
||||
|
|
|
@ -98,11 +98,10 @@
|
|||
|
||||
function onInit() {
|
||||
// read existing location
|
||||
Util.readStorage("mylocation.json", function(data) {
|
||||
Util.readStorageJSON("mylocation.json", function(data) {
|
||||
if (data===undefined) return; // no file
|
||||
try {
|
||||
var j = JSON.parse(data);
|
||||
setPosition(j);
|
||||
setPosition(data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ function disableFormInput() {
|
|||
function getData() {
|
||||
// show loading window
|
||||
Util.showModal("Loading...");
|
||||
Util.readStorage(`noteify.json`,data=>{
|
||||
notes = JSON.parse(data || "[]");
|
||||
Util.readStorageJSON(`noteify.json`,data=>{
|
||||
notes = data || [];
|
||||
|
||||
// remove window
|
||||
Util.hideModal();
|
||||
|
|
|
@ -150,15 +150,9 @@ TODO:
|
|||
files.trim().split(",").forEach(filename => {
|
||||
if (filename=="") return;
|
||||
promise = promise.then(() => new Promise(resolve => {
|
||||
Util.readStorage(filename, fileContents => {
|
||||
console.log(filename + " => " + fileContents);
|
||||
Util.readStorageJSON(filename, mapInfo => {
|
||||
console.log(filename + " => " + JSON.stringify(mapInfo));
|
||||
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;
|
||||
if (mapInfo!==undefined) {
|
||||
let latlon = L.latLng(mapInfo.lat, mapInfo.lon);
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
function onInit(){
|
||||
console.log("Loading settings from BangleJs...");
|
||||
try {
|
||||
Util.readStorage("owmweather.json", data=>{
|
||||
if(data.length > 0){
|
||||
settings = JSON.parse(data);
|
||||
Util.readStorageJSON("owmweather.json", data=>{
|
||||
if(data){
|
||||
settings = data;
|
||||
console.log("Got settings", settings);
|
||||
document.getElementById("apikey").value = settings.apikey;
|
||||
console.log("Loaded apikey from BangleJs.");
|
||||
|
|
|
@ -101,11 +101,9 @@ function viewDeferredTable(filename) {
|
|||
Puck.eval(`require("Storage").list("powermanager.def.json").length > 0`, (f)=>{
|
||||
if (f) {
|
||||
Util.showModal("Reading summarized info...");
|
||||
Util.readStorage(
|
||||
filename, data => {
|
||||
Util.readStorageJSON(
|
||||
filename, parsed => {
|
||||
Util.hideModal();
|
||||
let parsed = JSON.parse(data);
|
||||
|
||||
let sum = 0;
|
||||
let rows = [];
|
||||
for (var i in parsed.deferred) {
|
||||
|
@ -181,10 +179,9 @@ function viewHardwareTable(filename) {
|
|||
Puck.eval(`require("Storage").list("powermanager.hw.json").length > 0`, (f)=>{
|
||||
if (f) {
|
||||
Util.showModal("Reading hardware info...");
|
||||
Util.readStorage(
|
||||
filename, data => {
|
||||
Util.readStorageJSON(
|
||||
filename, parsed => {
|
||||
Util.hideModal();
|
||||
let parsed = JSON.parse(data);
|
||||
console.log("Hardware", parsed);
|
||||
let duration = parsed.saved - parsed.start;
|
||||
|
||||
|
|
|
@ -101,10 +101,8 @@ function getData() {
|
|||
uploadBtn.disabled = true;
|
||||
|
||||
Util.showModal("Loading...");
|
||||
Util.readStorage(repJson, data => {
|
||||
Util.readStorageJSON(repJson, reps => {
|
||||
Util.hideModal();
|
||||
|
||||
reps = JSON.parse(data);
|
||||
for(const rep of reps){
|
||||
renderRep(rep);
|
||||
}
|
||||
|
|
|
@ -265,11 +265,11 @@ function addTimer() {
|
|||
|
||||
function getData() {
|
||||
Util.showModal("Loading...");
|
||||
Util.readStorage('sched.json',data=>{
|
||||
alarms = JSON.parse(data || "[]") || [];
|
||||
Util.readStorageJSON('sched.json',data=>{
|
||||
alarms = data || [];
|
||||
|
||||
Util.readStorage('sched.settings.json',data=>{
|
||||
schedSettings = JSON.parse(data || "{}") || {};
|
||||
Util.readStorageJSON('sched.settings.json',data=>{
|
||||
schedSettings = data || {};
|
||||
Util.hideModal();
|
||||
alarms.sort((a, b) => {
|
||||
let x;
|
||||
|
|
|
@ -25,8 +25,8 @@ function getData() {
|
|||
// show loading window
|
||||
Util.showModal("Loading...");
|
||||
// get the data
|
||||
Util.readStorage('sleepphasealarm.json',data=>{
|
||||
let logs = JSON.parse(data || "{}")?.logs || [];
|
||||
Util.readStorageJSON('sleepphasealarm.json',data=>{
|
||||
let logs = (data || {})?.logs || [];
|
||||
// remove window
|
||||
Util.hideModal();
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
function onInit(){
|
||||
console.log("Loading settings from BangleJs...");
|
||||
try {
|
||||
Util.readStorage("tinycmc.json", data=>{
|
||||
if(data.length > 0){
|
||||
settings = JSON.parse(data);
|
||||
Util.readStorageJSON("tinycmc.json", data=>{
|
||||
if(data){
|
||||
settings = data;
|
||||
console.log("Got settings", settings);
|
||||
document.getElementById("apikey").value = settings.apikey;
|
||||
console.log("Loaded apikey from BangleJs.");
|
||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit 4422e4a3e808c99e540dc86ac1e3cab0ccb23a82
|
||||
Subproject commit c97b7851f50cfff4e898c2264a337a17085ce463
|
Loading…
Reference in New Issue