mirror of https://github.com/espruino/BangleApps
Merge pull request #3224 from bobrippling/feat/multitimer-initial
multitimer: add setting for initial screenpull/3228/head
commit
0aff4409a8
|
@ -6,3 +6,4 @@
|
||||||
0.06: Support fastloading
|
0.06: Support fastloading
|
||||||
0.07: Fix fastloading support - ensure drag handler's restored after
|
0.07: Fix fastloading support - ensure drag handler's restored after
|
||||||
menu display/fastload removes it
|
menu display/fastload removes it
|
||||||
|
0.08: Add setting for initial page to display
|
||||||
|
|
|
@ -78,7 +78,7 @@ function drawTimers() {
|
||||||
}, 1000 - (timers[idx].t % 1000));
|
}, 1000 - (timers[idx].t % 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
E.showScroller({
|
const s = E.showScroller({
|
||||||
h : 40, c : timers.length+2,
|
h : 40, c : timers.length+2,
|
||||||
back : function() {load();},
|
back : function() {load();},
|
||||||
draw : (idx, r) => {
|
draw : (idx, r) => {
|
||||||
|
@ -138,7 +138,7 @@ function timerMenu(idx) {
|
||||||
}, 1000 - (a.t % 1000));
|
}, 1000 - (a.t % 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
E.showScroller({
|
const s = E.showScroller({
|
||||||
h : 40, c : 5,
|
h : 40, c : 5,
|
||||||
back : function() {
|
back : function() {
|
||||||
clearInt();
|
clearInt();
|
||||||
|
@ -328,9 +328,22 @@ function editTimer(idx, a) {
|
||||||
setUI();
|
setUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readJson() {
|
||||||
|
let json = require("Storage").readJSON("multitimer.json", true) || {};
|
||||||
|
|
||||||
|
if (Array.isArray(json)) {
|
||||||
|
// old format, convert
|
||||||
|
json = { sw: json };
|
||||||
|
require("Storage").writeJSON("multitimer.json", json);
|
||||||
|
}
|
||||||
|
if (!json.sw) json.sw = [];
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
function drawSw() {
|
function drawSw() {
|
||||||
layer = 1;
|
layer = 1;
|
||||||
const sw = require("Storage").readJSON("multitimer.json", true) || [];
|
const sw = readJson().sw;
|
||||||
|
|
||||||
function updateTimers(idx) {
|
function updateTimers(idx) {
|
||||||
if (!timerInt1[idx]) timerInt1[idx] = setTimeout(function() {
|
if (!timerInt1[idx]) timerInt1[idx] = setTimeout(function() {
|
||||||
|
@ -341,7 +354,7 @@ function drawSw() {
|
||||||
}, 1000 - (sw[idx].t % 1000));
|
}, 1000 - (sw[idx].t % 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
E.showScroller({
|
const s = E.showScroller({
|
||||||
h : 40, c : sw.length+2,
|
h : 40, c : sw.length+2,
|
||||||
back : function() {load();},
|
back : function() {load();},
|
||||||
draw : (idx, r) => {
|
draw : (idx, r) => {
|
||||||
|
@ -382,12 +395,13 @@ function drawSw() {
|
||||||
|
|
||||||
function swMenu(idx, a) {
|
function swMenu(idx, a) {
|
||||||
layer = -1;
|
layer = -1;
|
||||||
const sw = require("Storage").readJSON("multitimer.json", true) || [];
|
const json = readJson();
|
||||||
|
const sw = json.sw;
|
||||||
if (sw[idx]) a = sw[idx];
|
if (sw[idx]) a = sw[idx];
|
||||||
else {
|
else {
|
||||||
a = {"t" : 0, "on" : false, "msg" : ""};
|
a = {"t" : 0, "on" : false, "msg" : ""};
|
||||||
sw[idx] = a;
|
sw[idx] = a;
|
||||||
require("Storage").writeJSON("multitimer.json", sw);
|
require("Storage").writeJSON("multitimer.json", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTimer() {
|
function updateTimer() {
|
||||||
|
@ -408,7 +422,7 @@ function swMenu(idx, a) {
|
||||||
}
|
}
|
||||||
else delete a.msg;
|
else delete a.msg;
|
||||||
sw[idx] = a;
|
sw[idx] = a;
|
||||||
require("Storage").writeJSON("multitimer.json", sw);
|
require("Storage").writeJSON("multitimer.json", json);
|
||||||
swMenu(idx, a);
|
swMenu(idx, a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -420,7 +434,7 @@ function swMenu(idx, a) {
|
||||||
setUI();
|
setUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
E.showScroller({
|
const s = E.showScroller({
|
||||||
h : 40, c : 5,
|
h : 40, c : 5,
|
||||||
back : function() {
|
back : function() {
|
||||||
clearInt();
|
clearInt();
|
||||||
|
@ -458,7 +472,7 @@ function swMenu(idx, a) {
|
||||||
select : (i) => {
|
select : (i) => {
|
||||||
|
|
||||||
function saveAndReload() {
|
function saveAndReload() {
|
||||||
require("Storage").writeJSON("multitimer.json", sw);
|
require("Storage").writeJSON("multitimer.json", json);
|
||||||
s.draw();
|
s.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,5 +721,17 @@ function onDrag(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTimers();
|
switch (readJson().initialScreen) {
|
||||||
|
case 1:
|
||||||
|
drawSw();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
drawAlarms();
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
case undefined:
|
||||||
|
default:
|
||||||
|
drawTimers();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "multitimer",
|
"id": "multitimer",
|
||||||
"name": "Multi Timer",
|
"name": "Multi Timer",
|
||||||
"version": "0.07",
|
"version": "0.08",
|
||||||
"description": "Set timers and chronographs (stopwatches) and watch them count down in real time. Pause, create, edit, and delete timers and chronos, and add custom labels/messages. Also sets alarms.",
|
"description": "Set timers and chronographs (stopwatches) and watch them count down in real time. Pause, create, edit, and delete timers and chronos, and add custom labels/messages. Also sets alarms.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"screenshots": [
|
"screenshots": [
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
{"name":"multitimer.app.js","url":"app.js"},
|
{"name":"multitimer.app.js","url":"app.js"},
|
||||||
{"name":"multitimer.boot.js","url":"boot.js"},
|
{"name":"multitimer.boot.js","url":"boot.js"},
|
||||||
{"name":"multitimer.alarm.js","url":"alarm.js"},
|
{"name":"multitimer.alarm.js","url":"alarm.js"},
|
||||||
|
{"name":"multitimer.settings.js","url":"settings.js"},
|
||||||
{"name":"multitimer.img","url":"app-icon.js","evaluate":true}
|
{"name":"multitimer.img","url":"app-icon.js","evaluate":true}
|
||||||
],
|
],
|
||||||
"data": [{"name":"multitimer.json"}],
|
"data": [{"name":"multitimer.json"}],
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
(function(back) {
|
||||||
|
const file = "multitimer.json";
|
||||||
|
let json = require('Storage').readJSON(file, true);
|
||||||
|
if (Array.isArray(json)) {
|
||||||
|
// old format, convert
|
||||||
|
json = { sw: json };
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeSettings() {
|
||||||
|
require('Storage').writeJSON(file, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
const screens = ["Timers", "Chronos", "Alarms"];
|
||||||
|
|
||||||
|
E.showMenu({
|
||||||
|
"": {
|
||||||
|
"title": "multitimer"
|
||||||
|
},
|
||||||
|
"< Back": back,
|
||||||
|
"Initial screen": {
|
||||||
|
value: json.initialScreen || 0,
|
||||||
|
min: 0,
|
||||||
|
max: screens.length - 1,
|
||||||
|
format: v => screens[v],
|
||||||
|
onchange: v => {
|
||||||
|
json.initialScreen = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue