From 1f457ed9d1defb61209f06a287ef6350d563e21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A6=91Svarba=2C=20Rastislav?= Date: Wed, 27 Nov 2019 09:14:48 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[Pomodoro]=20Save=20the=20last=20in?= =?UTF-8?q?terval=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/pomodo/pomodoro.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/pomodo/pomodoro.js b/apps/pomodo/pomodoro.js index 5570d9b47..c376d9a06 100644 --- a/apps/pomodo/pomodoro.js +++ b/apps/pomodo/pomodoro.js @@ -1,3 +1,5 @@ +const storage = require("Storage"); + const DEFAULT_TIME = 1500; // 25m const TIME_BREAK = 300; const STATES = { @@ -14,12 +16,6 @@ class State { this.next = null; } - goNext () { - if (this.next) { - this.next.run(); - } - } - setNext (next) { this.next = next; } @@ -56,10 +52,14 @@ class State { } class InitState extends State { - constructor () { + constructor (time) { super(STATES.INIT); - this.timeCounter = DEFAULT_TIME; + this.timeCounter = parseInt(storage.read(".pomodo") || DEFAULT_TIME, 10); + } + + saveTime () { + storage.write('.pomodo', '' + this.timeCounter); } setButtons () { @@ -100,6 +100,7 @@ class InitState extends State { }, BTN5, { repeat: true }); setWatch(() => { + this.saveTime(); const startedState = new StartedState(this.timeCounter); this.setNext(startedState); @@ -119,7 +120,7 @@ class StartedState extends State { constructor (timeCounter) { super(STATES.STARTED); - this.timeCounter = timeCounter || DEFAULT_TIME; + this.timeCounter = timeCounter; } draw () {