diff --git a/index.html b/index.html index 31c29ee..74e7044 100644 --- a/index.html +++ b/index.html @@ -69,7 +69,7 @@
diff --git a/js/script.js b/js/script.js index bc00b5b..bca98b5 100644 --- a/js/script.js +++ b/js/script.js @@ -1,14 +1,19 @@ const currentWindow = require('electron').remote.getCurrentWindow(); +const prompt = require('electron-prompt'); const Store = require('electron-store'); const store = new Store(); -var workTime = 50; -var breakTime = 10; +var workTime = 25; +var breakTime = 5; -document.getElementById('counter').innerHTML = workTime + ":00"; -document.getElementById('session-length').innerHTML = workTime; -document.getElementById('break-length').innerHTML = breakTime; +var counterDOM = document.getElementById('counter') +var sessionLengthDOM = document.getElementById('session-length') +var breakLengthDOM = document.getElementById('break-length') + +counterDOM.innerHTML = workTime + ":00"; +sessionLengthDOM.innerHTML = workTime; +breakLengthDOM.innerHTML = breakTime; var ding = new Audio("audio/ding.mp3"), pomodoro = { @@ -21,30 +26,28 @@ var ding = new Audio("audio/ding.mp3"), // is stored here because it was annoying // evaluating the button text directly. sessionLength: { - value: workTime, increase: function () { - this.value++; - $("#session-length").text(this.value); - $("#counter").text(this.value.toString() + ":00"); + workTime++; + $("#session-length").text(workTime); + $("#counter").text(workTime.toString() + ":00"); }, decrease: function () { - if (this.value > 1) { - this.value--; - $("#session-length").text(this.value); - $("#counter").text(this.value.toString() + ":00"); + if (workTime > 1) { + workTime--; + $("#session-length").text(workTime); + $("#counter").text(workTime.toString() + ":00"); } } }, breakLength: { - value: breakTime, increase: function () { - this.value++; - $("#break-length").text(this.value); + breakTime++; + $("#break-length").text(breakTime); }, decrease: function () { - if (this.value > 1) { - this.value--; - $("#break-length").text(this.value); + if (breakTime > 1) { + breakTime--; + $("#break-length").text(breakTime); } } }, @@ -52,8 +55,6 @@ var ding = new Audio("audio/ding.mp3"), // This resets the pomodoro object // and the DOM to its original state. - this.sessionLength.value = workTime; - this.breakLength.value = breakTime; $("#session-length").text(workTime); $("#break-length").text(breakTime); @@ -68,7 +69,7 @@ var ding = new Audio("audio/ding.mp3"), toggleVisible("show"); this.startTime = 0; this.endTime = 0; - $("#counter").text(this.sessionLength.value.toString() + ":00"); + $("#counter").text(workTime.toString() + ":00"); makeFullscreen(false) }, start: function () { @@ -76,7 +77,7 @@ var ding = new Audio("audio/ding.mp3"), store.set('isStarted', true); this.startTime = new Date().getTime(); - this.endTime = this.startTime + (this.sessionLength.value * 60 * 1000) + 1000; // I added an extra second so that the time the counter displays will start with the inputted breaktime/endtime (start with 18:00 instead of 17:59) + this.endTime = this.startTime + (workTime * 60 * 1000) + 1000; // I added an extra second so that the time the counter displays will start with the inputted breaktime/endtime (start with 18:00 instead of 17:59) makeFullscreen(false) }, stop: function () { @@ -186,7 +187,7 @@ window.setInterval(function () { playDing(); }); }) - pomodoro.endTime = now + (pomodoro.breakLength.value * 60 * 1000) + 1000; + pomodoro.endTime = now + (breakTime * 60 * 1000) + 1000; makeFullscreen(true) } else if (pomodoro.timeRemaining < 0 && pomodoro.isBreak === true) { @@ -260,6 +261,13 @@ $(document).ready(function () { $("#overlay").click(function () { modal.hide(); }); + $("#session-length").click(function () { + setWorkLength() + }) + $("#break-length").click(function () { + setBreakLength() + }) + }) function makeFullscreen(b) { @@ -272,4 +280,54 @@ function makeFullscreen(b) { currentWindow.setFullScreen(b) currentWindow.unmaximize() } +} + +function setWorkLength() { + prompt({ + title: 'Enter Session Length', + label: 'Session length:', + value: workTime, + inputAttrs: { + type: 'number', required: true + }, + type: 'input' + }) + .then((r) => { + if (r === null) { + console.log('user cancelled'); + } else { + if (r !== '') { + workTime = parseInt(r); + counterDOM.innerHTML = workTime + ":00"; + sessionLengthDOM.innerHTML = workTime; + breakLengthDOM.innerHTML = breakTime; + } + } + }) + .catch(console.error); +} + +function setBreakLength() { + prompt({ + title: 'Enter Break Length', + label: 'Break length:', + value: breakTime, + inputAttrs: { + type: 'number', required: true + }, + type: 'input' + }) + .then((r) => { + if (r === null) { + console.log('user cancelled'); + } else { + if (r !== '') { + breakTime = parseInt(r); + counterDOM.innerHTML = workTime + ":00"; + sessionLengthDOM.innerHTML = workTime; + breakLengthDOM.innerHTML = breakTime; + } + } + }) + .catch(console.error); } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6e1797f..29e6dd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -970,6 +970,14 @@ "sanitize-filename": "^1.6.1" } }, + "doc-ready": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/doc-ready/-/doc-ready-1.0.4.tgz", + "integrity": "sha1-N/U5GWnP+ZQwP9/vLl1QNX+BZNM=", + "requires": { + "eventie": "^1" + } + }, "dot-prop": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", @@ -1104,6 +1112,14 @@ } } }, + "electron-prompt": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/electron-prompt/-/electron-prompt-1.4.0.tgz", + "integrity": "sha512-z7AHMrixiUArHn/8i9tDC7UlRRLoM50gtREScGASmG67hcI5A5I5paPZsLLgrMoyC5aV9RZ3YsJXHyDI48rM5g==", + "requires": { + "doc-ready": "^1.0.4" + } + }, "electron-publish": { "version": "20.40.0", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-20.40.0.tgz", @@ -1178,6 +1194,11 @@ "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, + "eventie": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/eventie/-/eventie-1.0.6.tgz", + "integrity": "sha1-1P/IsMK15JPCqhsiy+kY067nRDc=" + }, "execa": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", @@ -1469,7 +1490,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -1487,11 +1509,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1504,15 +1528,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1615,7 +1642,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1625,6 +1653,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1637,17 +1666,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -1664,6 +1696,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -1736,7 +1769,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -1746,6 +1780,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -1821,7 +1856,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -1851,6 +1887,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -1868,6 +1905,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -1906,11 +1944,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", - "bundled": true + "bundled": true, + "optional": true } } }, diff --git a/package.json b/package.json index b32e5df..0f7cb02 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "electron-builder": "^20.39.0" }, "dependencies": { + "electron-prompt": "^1.4.0", "electron-reload": "^1.4.0", "electron-store": "^3.3.0", "jquery": "^3.3.1"