Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
config constructor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vernon committed Oct 27, 2016
1 parent 372bf49 commit aa8e7fd
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 130 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Command Palette ➔ Settings View: Install Packages ➔ Break

- [x] Customizable micro and macro break schedule. Micro are shorter breaks that occur more often. Macro are longer breaks that occur less.
- [x] Full screen break message that prevents you from further coding.
- [x] Optional notifications 30s before each break starts.
- [x] Optional notifications 1 minute before each break starts.
- [x] Displays the current micro break count and remaining break time in the status bar. ![Status Bar Screenshot](https://github.com/Frozenfire92/break/raw/master/screenshot1.png)

## Package Settings
Expand All @@ -34,14 +34,14 @@ Command Palette ➔ Settings View: Install Packages ➔ Break
Enable the micro break functionality
- **Macro Break Configuration**
- *Enable Notifications* - boolean :
Get a notification 30 seconds before each macro break
Get a notification 1 minute before each macro break
- *Duration* - integer :
Duration in minites of each macro break
- *Interval* - integer :
Time in minites between each macro break
- **Micro Break Configuration**
- *Enable Notifications* - boolean :
Get a notification 30 seconds before each micro break
Get a notification 1 minute before each micro break
- *Duration* - integer :
Duration in minites of each micro break
- *Interval* - integer :
Expand Down
5 changes: 1 addition & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export default breakPackage;
socket.on('connect', function(){

// constructor event
socket.emit('client-connected', {});

// config event
socket.emit('set-config-data', {
socket.emit('client-connected', {
config: atom.config.get('break')
});

Expand Down
27 changes: 9 additions & 18 deletions lib/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ setInterval(function () {
*/
io.on('connection', function (socket) {

// had first client
socketClientHandler.firstClient();

/**
* Called on client connection
*
* @param {Object} data
*/
socket.on('client-connected', function (data) {
socket.on('client-connected', function (dataObject) {

// set config
if (!socketClientHandler.hadFirstClient) {
stateController.setConfig(dataObject.config);
}

// had client
socketClientHandler.firstClient();

// state constructors
switch (stateController.currentState.constructor.name) {
Expand Down Expand Up @@ -127,18 +132,4 @@ io.on('connection', function (socket) {
io.emit('set-status-bar-tile', { type: 'Null' });
io.emit('set-break-panel', { type: 'Null' });
});

/**
* Sets the config information and state only once.
*
* @param {Object} dataObject break's config object
*/
socket.on('set-config-data', function (dataObject) {

// @TODO test this function
// first client only
if (socketClientHandler.clientCount == 0) {
stateController.setConfig(dataObject.config);
}
});
});
22 changes: 2 additions & 20 deletions lib/server/states/macroState.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,15 @@ var MacroState = function () {
});

if (stateController.config.macroBreak.enableNotifications) {
if (this.interval - this.secondCounter == 30) {
if (this.interval - this.secondCounter === 60) {
_nodeNotifier2.default.notify({
title: 'Break;',
message: 'Macro break will start in 30s'
message: 'Macro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'macro break');
}
}
}
}

/**
* Sends a notification out 30s before break time
*
* @param {string} message a message to display
*/

}, {
key: '_notify',
value: function _notify(message) {
if (this.interval - this.secondCounter == 30) {
_nodeNotifier2.default.notify({
'title': 'Break;',
'message': message
});
}
}
}]);

return MacroState;
Expand Down
29 changes: 5 additions & 24 deletions lib/server/states/microState.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,20 @@ var MicroState = function () {
});

if (stateController.config.microBreak.enableNotifications && !this._onlastMicroBreak()) {
if (this.interval - this.secondCounter == 30) {
if (this.interval - this.secondCounter === 60) {
_nodeNotifier2.default.notify({
title: 'Break;',
message: 'Micro break will start in 30s'
message: 'Micro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'micro break');
}
}

if (stateController.config.macroBreak.enableNotifications && this._onlastMicroBreak()) {
if (this.interval - this.secondCounter == 30) {
if (this.interval - this.secondCounter === 60) {
_nodeNotifier2.default.notify({
title: 'Break;',
message: 'Macro break will start in 30s'
message: 'Macro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'macro break');
}
}
}
Expand All @@ -96,31 +94,14 @@ var MicroState = function () {
}
}

/**
* Sends a notification out 30s before break time
*
* @param {string} message a message to display
*/

}, {
key: '_notify',
value: function _notify(message) {
if (this.interval - this.secondCounter == 30) {
_nodeNotifier2.default.notify({
'title': 'Break;',
'message': message
});
}
}

/**
* Returns true if on the last micro break
*/

}, {
key: '_onlastMicroBreak',
value: function _onlastMicroBreak() {
if (this.amount == this.currentAmount + 1) {
if (this.amount === this.currentAmount + 1) {
return true;
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
properties: {
enableNotifications: {
title: 'Enable Notifications',
description: 'Get a notification 30 seconds before each macro break',
description: 'Get a notification 1 minute before each macro break',
type: 'boolean',
default: true,
order: 1
Expand All @@ -39,7 +39,7 @@ export default {
description: 'Time in minites between each macro break',
type: 'integer',
default: 60,
minimum: 1,
minimum: 2,
order: 3
}
}
Expand All @@ -53,7 +53,7 @@ export default {
properties: {
enableNotifications: {
title: 'Enable Notifications',
description: 'Get a notification 30s before each micro break',
description: 'Get a notification 1 minute before each micro break',
type: 'boolean',
default: true,
order: 1
Expand All @@ -72,7 +72,7 @@ export default {
description: 'Time in minites between each mico break',
type: 'integer',
default: 30,
minimum: 1,
minimum: 2,
maximum: 1439,
order: 3
},
Expand Down
28 changes: 9 additions & 19 deletions lib/src/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ setInterval(function() {
*/
io.on('connection', function (socket) {

// had first client
socketClientHandler.firstClient();

/**
* Called on client connection
*
* @param {Object} data
*/
socket.on('client-connected', function(data){
socket.on('client-connected', function(dataObject){

// set config
if(!socketClientHandler.hadFirstClient){
stateController.setConfig(dataObject.config);
}

// had client
socketClientHandler.firstClient();

// state constructors
switch(stateController.currentState.constructor.name){
Expand Down Expand Up @@ -117,19 +122,4 @@ io.on('connection', function (socket) {
io.emit('set-break-panel', {type: 'Null'});
});

/**
* Sets the config information and state only once.
*
* @param {Object} dataObject break's config object
*/
socket.on('set-config-data', function(dataObject){

// @TODO test this function
// first client only
if(socketClientHandler.clientCount == 0){
stateController.setConfig(dataObject.config);
}

});

});
19 changes: 2 additions & 17 deletions lib/src/server/states/macroState.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,15 @@ export default class MacroState{
});

if(stateController.config.macroBreak.enableNotifications){
if((this.interval - this.secondCounter) == 30){
if((this.interval - this.secondCounter) === 60){
notifier.notify({
title: 'Break;',
message: 'Macro break will start in 30s'
message: 'Macro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'macro break');
}
}

}
}

/**
* Sends a notification out 30s before break time
*
* @param {string} message a message to display
*/
_notify(message){
if((this.interval - this.secondCounter) == 30){
notifier.notify({
'title': 'Break;',
'message': message
});
}
}

}
26 changes: 5 additions & 21 deletions lib/src/server/states/microState.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,20 @@ export default class MicroState{


if(stateController.config.microBreak.enableNotifications && !this._onlastMicroBreak()){
if((this.interval - this.secondCounter) == 30){
if((this.interval - this.secondCounter) === 60){
notifier.notify({
title: 'Break;',
message: 'Micro break will start in 30s'
message: 'Micro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'micro break');
}
}

if(stateController.config.macroBreak.enableNotifications && this._onlastMicroBreak()){
if((this.interval - this.secondCounter) == 30){
if((this.interval - this.secondCounter) === 60){
notifier.notify({
title: 'Break;',
message: 'Macro break will start in 30s'
message: 'Macro break will start in 1 minute'
});
this.socketEvent.emit('debug', 'macro break');
}
}

Expand All @@ -77,25 +75,11 @@ export default class MicroState{
}
}

/**
* Sends a notification out 30s before break time
*
* @param {string} message a message to display
*/
_notify(message){
if((this.interval - this.secondCounter) == 30){
notifier.notify({
'title': 'Break;',
'message': message
});
}
}

/**
* Returns true if on the last micro break
*/
_onlastMicroBreak(){
if(this.amount == this.currentAmount + 1){
if(this.amount === this.currentAmount + 1){
return true;
}
return false;
Expand Down

0 comments on commit aa8e7fd

Please sign in to comment.