Skip to content

Commit

Permalink
length from inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
p32929 committed Dec 25, 2019
1 parent 9492e9a commit 510a3d6
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 36 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="vert-menu-button">
<li class="mdl-menu__item" id="about">About</li>
<li class="mdl-menu__item" id="ti255">Reset</li>
<!-- <li class="mdl-menu__item" id="ti255">Reset</li> -->
</ul>


Expand Down
106 changes: 82 additions & 24 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -21,39 +26,35 @@ 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);
}
}
},
reset: function () {
// 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);

Expand All @@ -68,15 +69,15 @@ 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 () {
// This starts the timer.
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 () {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
62 changes: 51 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 510a3d6

Please sign in to comment.