Storage
parent
98974f3fe7
commit
7bf24582fa
17
src/app.js
17
src/app.js
|
|
@ -8,6 +8,9 @@ var BLACK_COLOR = "#000";
|
|||
var ICON_SCALE = g.getWidth() / 178;
|
||||
var ICON_SIZE_IN_PIXELS = 24;
|
||||
var UPDATE_DELAY_MS = 100;
|
||||
function zeroPadded(n) {
|
||||
return ("0" + n).substr(-2);
|
||||
}
|
||||
function convertTimeToText(time) {
|
||||
var hours = Math.floor(time / 3600000);
|
||||
var minutes = Math.floor(time / 60000) % 60;
|
||||
|
|
@ -17,7 +20,7 @@ function convertTimeToText(time) {
|
|||
return ("0" + minutes).substr(-2) + ":" + ("0" + seconds).substr(-2) + "." + tenthsOfASecond;
|
||||
}
|
||||
else {
|
||||
return "0" + hours + ":" + ("0" + minutes).substr(-2) + ":" + ("0" + seconds).substr(-2);
|
||||
return zeroPadded(hours) + ":" + zeroPadded(minutes) + ":" + zeroPadded(seconds);
|
||||
}
|
||||
}
|
||||
var Button = /** @class */ (function () {
|
||||
|
|
@ -198,7 +201,11 @@ var TimerApp = /** @class */ (function () {
|
|||
});
|
||||
};
|
||||
TimerApp.prototype.loadStateOrDefault = function () {
|
||||
this.timers = [
|
||||
var state = require("Storage").readJSON(STORAGE_FILE, 1);
|
||||
if (state == undefined) {
|
||||
state = {
|
||||
displayedTimerIndex: 0,
|
||||
timers: [
|
||||
{
|
||||
elapsedTime: 0.0,
|
||||
running: false
|
||||
|
|
@ -215,7 +222,11 @@ var TimerApp = /** @class */ (function () {
|
|||
elapsedTime: 0.0,
|
||||
running: false
|
||||
},
|
||||
];
|
||||
]
|
||||
};
|
||||
}
|
||||
this.displayedTimerIndex = state.displayedTimerIndex;
|
||||
this.timers = state.timers;
|
||||
};
|
||||
TimerApp.prototype.drawButtons = function () {
|
||||
console.log("DRAW BUTTONS", JSON.stringify(this.timers));
|
||||
|
|
|
|||
18
src/app.ts
18
src/app.ts
|
|
@ -18,6 +18,10 @@ const ICON_SCALE = g.getWidth() / 178
|
|||
const ICON_SIZE_IN_PIXELS = 24
|
||||
const UPDATE_DELAY_MS = 100
|
||||
|
||||
function zeroPadded(n: number): string {
|
||||
return ("0" + n).substr(-2)
|
||||
}
|
||||
|
||||
function convertTimeToText(time: number): string {
|
||||
let hours = Math.floor(time / 3600000)
|
||||
let minutes = Math.floor(time / 60000) % 60
|
||||
|
|
@ -27,7 +31,7 @@ function convertTimeToText(time: number): string {
|
|||
if (hours == 0) {
|
||||
return ("0" + minutes).substr(-2) + ":" + ("0" + seconds).substr(-2) + "." + tenthsOfASecond
|
||||
} else {
|
||||
return "0" + hours + ":" + ("0" + minutes).substr(-2) + ":" + ("0" + seconds).substr(-2)
|
||||
return `${zeroPadded(hours)}:${zeroPadded(minutes)}:${zeroPadded(seconds)}`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -294,7 +298,11 @@ class TimerApp {
|
|||
}
|
||||
|
||||
loadStateOrDefault() {
|
||||
this.timers = [
|
||||
let state = require("Storage").readJSON(STORAGE_FILE, 1)
|
||||
if (state == undefined) {
|
||||
state = {
|
||||
displayedTimerIndex: 0,
|
||||
timers: [
|
||||
{
|
||||
elapsedTime: 0.0,
|
||||
running: false,
|
||||
|
|
@ -311,7 +319,11 @@ class TimerApp {
|
|||
elapsedTime: 0.0,
|
||||
running: false,
|
||||
},
|
||||
]
|
||||
],
|
||||
}
|
||||
}
|
||||
this.displayedTimerIndex = state.displayedTimerIndex
|
||||
this.timers = state.timers
|
||||
}
|
||||
|
||||
drawButtons() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue