Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravchl committed Apr 29, 2017
1 parent 162d79e commit 995ca8c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 45 deletions.
85 changes: 51 additions & 34 deletions care.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,37 @@ screen.key(['r', 'C-r'], function(ch, key) {
});

screen.key(['s', 'C-s'], function(ch, key) {
if (!inPomodoroMode) return;
if (pomodoro.isStopped()) return pomodoro.start();
if (pomodoro.isPaused()) return pomodoro.resume();
pomodoro.pause();
pomodoroHandlers.onTick()
if (!inPomodoroMode) {
return;
} else if (pomodoro.isStopped()) {
pomodoro.start();
} else if (pomodoro.isPaused()) {
pomodoro.resume();
} else {
pomodoro.pause();
pomodoroHandlers.onTick();
}
});

screen.key(['e', 'C-e'], function(ch, key) {
if (!inPomodoroMode) return;
pomodoro.stop();
pomodoroHandlers.onTick()
if (inPomodoroMode) {
pomodoro.stop();
pomodoroHandlers.onTick();
}
});

screen.key(['u', 'C-u'], function(ch, key) {
if (!inPomodoroMode) return;
pomodoro.updateRunningDuration();
pomodoroHandlers.onTick()
if (inPomodoroMode) {
pomodoro.updateRunningDuration();
pomodoroHandlers.onTick();
}
});

screen.key(['b', 'C-b'], function(ch, key) {
if (!inPomodoroMode) return;
pomodoro.updateBreakDuration();
pomodoroHandlers.onTick()
if (inPomodoroMode) {
pomodoro.updateBreakDuration();
pomodoroHandlers.onTick()
}
});

screen.key(['p', 'C-p'], function(ch, key) {
Expand Down Expand Up @@ -118,7 +127,9 @@ function doTheTweets() {
for (var which in config.twitter) {
// Gigantor hack: first twitter account gets spoken by the party parrot.
if (which == 0) {
if (inPomodoroMode) return;
if (inPomodoroMode) {
return;
}
twitterbot.getTweet(config.twitter[which]).then(function(tweet) {
if (config.say === 'bunny') {
parrotBox.content = bunnySay(tweet.text);
Expand Down Expand Up @@ -287,11 +298,15 @@ var pomodoroHandlers = {
onTick: function() {
if (!inPomodoroMode) return;
var remainingTime = pomodoro.getRemainingTime();
var statusText = ''
if (pomodoro.isInBreak()) statusText = ' (Break Started) ';
if (pomodoro.isStopped()) statusText = ' (Press "s" to start) ';
if (pomodoro.isRunning()) statusText = '';
if (pomodoro.isPaused()) statusText = ' (Press "s" to resume) ';

var statusText = '';
if (pomodoro.isInBreak()) {
statusText = ' (Break Started) ';
} else if (pomodoro.isStopped()) {
statusText = ' (Press "s" to start) ';
} else if (pomodoro.isPaused()) {
statusText = ' (Press "s" to resume) ';
}

var content = `In Pomodoro Mode: ${remainingTime} ${statusText}`;
var metaData = `Duration: ${pomodoro.getRunningDuration()} Minutes, Break Time: ${pomodoro.getBreakDuration()} Minutes\n`;
Expand All @@ -304,23 +319,25 @@ var pomodoroHandlers = {
},

onBreakStarts: function() {
if (!inPomodoroMode) return;
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time!',
sound: true,
timeout: 30,
});
if (inPomodoroMode) {
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time!',
sound: true,
timeout: 30,
});
}
},

onBreakEnds: function() {
if (!inPomodoroMode) return;
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time Ends!',
sound: true,
timeout: 30,
});
if (inPomodoroMode) {
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time Ends!',
sound: true,
timeout: 30,
});
}
},
}

Expand Down
13 changes: 2 additions & 11 deletions pomodoro.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ var States = {
// options.onTick (function) - Runs on every tick
// options.onBreakStarts (function) - Runs when break starts
// options.onBreakEnds (function) - Runs when break ends
var Pomodoro = function(options) {
var pomodoro = function(options) {
var _setIntervalId = null;
var _runningDuration = 20; // Default pomodoro duration: 20 Min
var _breakDuration = 5; // Default break duration: 5 Min
var _runningDurationRemaining = 0; // In seconds
var _breakDurationRemaining = 0; // In seconds
var _currentState = States.STOPPED;


var _onTick = function() {
switch (_currentState) {
case States.RUNNING: _handleTickOnRunning(); break;
Expand All @@ -29,7 +28,6 @@ var Pomodoro = function(options) {
}
}


var _handleTickOnRunning = function() {
if (_runningDurationRemaining < 1) {
_runningDurationRemaining = 0;
Expand All @@ -42,8 +40,6 @@ var Pomodoro = function(options) {
}
};



var _handleTickOnBreak = function() {
if (_breakDurationRemaining < 1) {
_breakDurationRemaining = 0;
Expand All @@ -56,17 +52,13 @@ var Pomodoro = function(options) {
}
};



var _handleTickOnStopped = function() {
clearInterval(_setIntervalId)
_runningDurationRemaining = 0;
_breakDurationRemaining = 0;
_setIntervalId = null;
};



var exports = {
start: function() {
if (_setIntervalId !== null) clearInterval(_setIntervalId);
Expand Down Expand Up @@ -137,5 +129,4 @@ var Pomodoro = function(options) {
}



module.exports = Pomodoro;
module.exports = pomodoro;

0 comments on commit 995ca8c

Please sign in to comment.