✨ [Pomodoro] Save the last interval value
parent
624b53094d
commit
1f457ed9d1
|
|
@ -1,3 +1,5 @@
|
||||||
|
const storage = require("Storage");
|
||||||
|
|
||||||
const DEFAULT_TIME = 1500; // 25m
|
const DEFAULT_TIME = 1500; // 25m
|
||||||
const TIME_BREAK = 300;
|
const TIME_BREAK = 300;
|
||||||
const STATES = {
|
const STATES = {
|
||||||
|
|
@ -14,12 +16,6 @@ class State {
|
||||||
this.next = null;
|
this.next = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
goNext () {
|
|
||||||
if (this.next) {
|
|
||||||
this.next.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setNext (next) {
|
setNext (next) {
|
||||||
this.next = next;
|
this.next = next;
|
||||||
}
|
}
|
||||||
|
|
@ -56,10 +52,14 @@ class State {
|
||||||
}
|
}
|
||||||
|
|
||||||
class InitState extends State {
|
class InitState extends State {
|
||||||
constructor () {
|
constructor (time) {
|
||||||
super(STATES.INIT);
|
super(STATES.INIT);
|
||||||
|
|
||||||
this.timeCounter = DEFAULT_TIME;
|
this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveTime () {
|
||||||
|
storage.write('.pomodo', '' + this.timeCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
setButtons () {
|
setButtons () {
|
||||||
|
|
@ -100,6 +100,7 @@ class InitState extends State {
|
||||||
}, BTN5, { repeat: true });
|
}, BTN5, { repeat: true });
|
||||||
|
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
|
this.saveTime();
|
||||||
const startedState = new StartedState(this.timeCounter);
|
const startedState = new StartedState(this.timeCounter);
|
||||||
|
|
||||||
this.setNext(startedState);
|
this.setNext(startedState);
|
||||||
|
|
@ -119,7 +120,7 @@ class StartedState extends State {
|
||||||
constructor (timeCounter) {
|
constructor (timeCounter) {
|
||||||
super(STATES.STARTED);
|
super(STATES.STARTED);
|
||||||
|
|
||||||
this.timeCounter = timeCounter || DEFAULT_TIME;
|
this.timeCounter = timeCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw () {
|
draw () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue