Skip to content

Commit

Permalink
settings 0.54: If setting.json is corrupt, ensure it gets re-written
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 4, 2022
1 parent e03c8c8 commit 1b1f1d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions apps/setting/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@
0.51: Add setting for configuring a launcher
0.52: Add option for left-handed users
0.53: Ensure that when clock is set, clockHasWidgets is set correctly too
0.54: If setting.json is corrupt, ensure it gets re-written
2 changes: 1 addition & 1 deletion apps/setting/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "setting",
"name": "Settings",
"version": "0.53",
"version": "0.54",
"description": "A menu for setting up Bangle.js",
"icon": "settings.png",
"tags": "tool,system",
Expand Down
26 changes: 14 additions & 12 deletions apps/setting/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function resetSettings() {
}

settings = storage.readJSON('setting.json', 1);
if (!settings) resetSettings();
if (("object" != typeof settings) ||
("object" != typeof settings.options))
resetSettings();

const boolFormat = v => v ? /*LANG*/"On" : /*LANG*/"Off";

Expand Down Expand Up @@ -237,9 +239,9 @@ function showThemeMenu() {
}
};

require("Storage").list(/^.*\.theme$/).forEach(
storage.list(/^.*\.theme$/).forEach(
n => {
let newTheme = require("Storage").readJSON(n);
let newTheme = storage.readJSON(n);
themesMenu[newTheme.name ? newTheme.name : n] = () => {
upd({
fg:cl(newTheme.fg), bg:cl(newTheme.bg),
Expand Down Expand Up @@ -567,11 +569,11 @@ function showUtilMenu() {
},
/*LANG*/'Compact Storage': () => {
E.showMessage(/*LANG*/"Compacting...\nTakes approx\n1 minute",{title:/*LANG*/"Storage"});
require("Storage").compact();
storage.compact();
showUtilMenu();
},
/*LANG*/'Rewrite Settings': () => {
require("Storage").write(".boot0","eval(require('Storage').read('bootupdate.js'));");
storage.write(".boot0","eval(require('Storage').read('bootupdate.js'));");
load("setting.app.js");
},
/*LANG*/'Flatten Battery': () => {
Expand All @@ -592,9 +594,9 @@ function showUtilMenu() {
menu[/*LANG*/'Calibrate Battery'] = () => {
E.showPrompt(/*LANG*/"Is the battery fully charged?",{title:/*LANG*/"Calibrate"}).then(ok => {
if (ok) {
var s=require("Storage").readJSON("setting.json");
var s=storage.readJSON("setting.json");
s.batFullVoltage = (analogRead(D3)+analogRead(D3)+analogRead(D3)+analogRead(D3))/4;
require("Storage").writeJSON("setting.json",s);
storage.writeJSON("setting.json",s);
E.showAlert(/*LANG*/"Calibrated!").then(() => load("setting.app.js"));
} else {
E.showAlert(/*LANG*/"Please charge Bangle.js for 3 hours and try again").then(() => load("settings.app.js"));
Expand Down Expand Up @@ -659,7 +661,7 @@ function makeConnectable() {
});
}
function showClockMenu() {
var clockApps = require("Storage").list(/\.info$/)
var clockApps = storage.list(/\.info$/)
.map(app => {var a=storage.readJSON(app, 1);return (a&&a.type == "clock")?a:undefined})
.filter(app => app) // filter out any undefined apps
.sort((a, b) => a.sortorder - b.sortorder);
Expand All @@ -676,7 +678,7 @@ function showClockMenu() {
}
clockMenu[label] = () => {
settings.clock = app.src;
settings.clockHasWidgets = require("Storage").read(app.src).includes("Bangle.loadWidgets");
settings.clockHasWidgets = storage.read(app.src).includes("Bangle.loadWidgets");
updateSettings();
showMainMenu();
};
Expand All @@ -687,7 +689,7 @@ function showClockMenu() {
return E.showMenu(clockMenu);
}
function showLauncherMenu() {
var launcherApps = require("Storage").list(/\.info$/)
var launcherApps = storage.list(/\.info$/)
.map(app => {var a=storage.readJSON(app, 1);return (a&&a.type == "launch")?a:undefined})
.filter(app => app) // filter out any undefined apps
.sort((a, b) => a.sortorder - b.sortorder);
Expand Down Expand Up @@ -865,9 +867,9 @@ function showTouchscreenCalibration() {
Bangle.setOptions({
touchX1: calib.x1, touchY1: calib.y1, touchX2: calib.x2, touchY2: calib.y2
});
var s = require("Storage").readJSON("setting.json",1)||{};
var s = storage.readJSON("setting.json",1)||{};
s.touch = calib;
require("Storage").writeJSON("setting.json",s);
storage.writeJSON("setting.json",s);
g.setFont("6x8:2").setFontAlign(0,0).drawString("Calibrated!", g.getWidth()/2, g.getHeight()/2);
// now load the main menu again
setTimeout(showLCDMenu, 500);
Expand Down

0 comments on commit 1b1f1d7

Please sign in to comment.