Skip to content

Commit

Permalink
sched: Fix readStorage when files do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nxdefiant committed Sep 4, 2023
1 parent 5213110 commit e9e2d2e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/sched/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,25 @@
alarms.push(timer);
}

function readStorageIfExists(filename, cb) {
Puck.write(`\x10(function() {
Bluetooth.print(JSON.stringify(require("Storage").list("${filename}").sort()));
})()\n`, contents => {
const fileNames = JSON.parse(contents);
if (fileNames.length > 0) {
Util.readStorage(filename,cb);
} else {
cb();
}
});
}

function getData() {
Util.showModal("Loading...");
Util.readStorage('sched.json',data=>{
readStorageIfExists('sched.json',data=>{
alarms = JSON.parse(data || "[]") || [];

Util.readStorage('sched.settings.json',data=>{
readStorageIfExists('sched.settings.json',data=>{
schedSettings = JSON.parse(data || "{}") || {};
Util.hideModal();
alarms.sort((a, b) => {
Expand Down

0 comments on commit e9e2d2e

Please sign in to comment.