Repository: hovancik/stretchly
Pull request #53 (2016-12-30 17:44:35)

Allows to enable/disable break idea and to add own ideas

codecov-io: ## [Current coverage](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) is 83.95% (diff: 100%)
> Merging [#53](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) into [master](https://codecov.io/gh/hovancik/stretchly/branch/master?src=pr) will decrease coverage by **5.23%**

```diff
@@             master        #53   diff @@
==========================================
  Files             4          5     +1   
  Lines            74         81     +7   
  Methods          13         15     +2   
  Messages          0          0          
  Branches         11         11          
==========================================
+ Hits             66         68     +2   
- Misses            8         13     +5   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [fae74d6...e7bbde0](https://codecov.io/gh/hovancik/stretchly/compare/fae74d628a5c2b5ebd835507c4a623147cf42da1...e7bbde05964abfbbcbf8b9316ad6114f00b30b50?src=pr)
codecov-io: ## [Current coverage](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) is 83.95% (diff: 100%)
> Merging [#53](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) into [master](https://codecov.io/gh/hovancik/stretchly/branch/master?src=pr) will decrease coverage by **5.23%**

```diff
@@             master        #53   diff @@
==========================================
  Files             4          5     +1   
  Lines            74         81     +7   
  Methods          13         15     +2   
  Messages          0          0          
  Branches         11         11          
==========================================
+ Hits             66         68     +2   
- Misses            8         13     +5   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [fae74d6...e7bbde0](https://codecov.io/gh/hovancik/stretchly/compare/fae74d628a5c2b5ebd835507c4a623147cf42da1...e7bbde05964abfbbcbf8b9316ad6114f00b30b50?src=pr)
codecov-io: ## [Current coverage](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) is 83.95% (diff: 100%)
> Merging [#53](https://codecov.io/gh/hovancik/stretchly/pull/53?src=pr) into [master](https://codecov.io/gh/hovancik/stretchly/branch/master?src=pr) will decrease coverage by **5.23%**

```diff
@@             master        #53   diff @@
==========================================
  Files             4          5     +1   
  Lines            74         81     +7   
  Methods          13         15     +2   
  Messages          0          0          
  Branches         11         11          
==========================================
+ Hits             66         68     +2   
- Misses            8         13     +5   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [fae74d6...47314e4](https://codecov.io/gh/hovancik/stretchly/compare/fae74d628a5c2b5ebd835507c4a623147cf42da1...47314e40c4988b107fb81fdf0c553160dbfb5387?src=pr)

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c582754..d3979ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
+## [Unreleased]
+### Added
+- possibility to change break/microbreak ideas via editing config file
+
 ## [0.5.1] - 2016-12-05
 ### Fixed
 - some grammar
diff --git a/README.md b/README.md
index 77faccc..fb2d532 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,21 @@ Microbreaks and breaks can be customized:
 
 All settings can be reset to defaults.
 
+### Advanced settings
+All settings are saved in JSON file. To learn more about how to find it, read [this](https://github.com/electron/electron/blob/master/docs/api/app.md#appgetpathname).
+Related code looks like this:
+
+```
+const dir = app.getPath('userData')
+const settingsFile = `${dir}/config.json`
+```
+
+#### Editing break/microbreak ideas
+In config file, change `useIdeasFromSettings: false,` to `useIdeasFromSettings: true,` and edit
+`breakIdeas` and `microbreakIdeas`.
+
+
+
 ## Install [![Github All Releases](https://img.shields.io/github/downloads/hovancik/stretchly/total.svg)](https://github.com/hovancik/stretchly/releases/latest)
 
 Latest installers for macOS, Windows, Linux and FreeBSD can be found [here](https://github.com/hovancik/stretchly/releases).
@@ -103,8 +118,3 @@ Sounds used in this application are listed [here](http://freesound.org/people/ho
 
 ## License
 See LICENSE file.
-
-## Support on Beerpay
-Hey dude! Help me out for a couple of :beers:!
-
-[![Beerpay](https://beerpay.io/hovancik/stretchly/badge.svg?style=beer-square)](https://beerpay.io/hovancik/stretchly)  [![Beerpay](https://beerpay.io/hovancik/stretchly/make-wish.svg?style=flat-square)](https://beerpay.io/hovancik/stretchly?focus=wish)
\ No newline at end of file
diff --git a/app/breakIdeas.js b/app/breakIdeas.js
deleted file mode 100644
index ddaf272..0000000
--- a/app/breakIdeas.js
+++ /dev/null
@@ -1,19 +0,0 @@
-const Shuffled = require('./utils/shuffled')
-module.exports = new Shuffled([
-  ['Not alone', 'Do you find it hard to take a break alone? Try to do it with a co-worker. Aside from making it easier to stick to breaks, you will have a chance to get to know them better. Taking breaks together increases productivity.'],
-  ['Step away', 'Do you ever notice how your brain can figure things out by itself? All it takes is to step away from the computer and take a break to think about something totally unrelated.'],
-  ['Microbreaks', 'Rest is a key component in ensuring the performance of the musculoskeletal system. Frequent breaks can decrease the duration of a task and help lower the exposure to ergonomic injury risk.'],
-  ['Meditation', 'Research studies suggest that mindfulness-based excercises help decrease anxiety, depression, stress, and pain, and help improve general health, mental health, and quality of life. Not sure how to start? There are numerous apps to help you out.'],
-  ['Blink', 'Looking at screens for a long time causes you to blink less, thus exposing your eyes to the air. Blink rapidly for a few seconds to refresh the tear film and clear dust from the eye surface.'],
-  ['Ergonomics', 'Improper height and angle of the keyboard, mouse, monitor or working surface can cause health problems. Take some time to read about desk ergonomics.'],
-  ['Move', 'There are a lot of ways you can exercise within your office. Try marching in place or doing desk push-ups.'],
-  ['Change', 'Do you have a stability ball or standing work desk? Consider replacing your desk chair with them for a while.'],
-  ['Notice', 'Are you daydreaming or having trouble focusing? It is a sign that you need to take a break.'],
-  ['Tech', 'How about taking a no-tech walk?'],
-  ['Metabolism', 'Emerging research shows that sitting for long periods of time contributes to risk of metabolic syndrome, heart attack and stroke risk and overall death risk, among others. Taking regular walking breaks can help your circulation, working to counteract some of those problems.'],
-  ['Active Meetings', 'How about moving meetings from the conference room to the concourse? Walking not only burns calories but it may even foster a sense of collaboration.'],
-  ['Fruit', 'Take your time and eat some fruit. Slowly. Notice the flavor, the texture, the freshness.'],
-  ['Bathrooms', 'Walk to the farthest bathroom in the worksite facility when going to the restroom.'],
-  ['Coffee break', 'Going on coffee break? Consider doing a 5-minute walk every time you go for one.'],
-  ['Colleagues', 'Do not email or message office colleagues, walk to their desks to communicate with them.']
-])
diff --git a/app/main.js b/app/main.js
index 00ea4e8..efef0a2 100644
--- a/app/main.js
+++ b/app/main.js
@@ -3,10 +3,11 @@ const {app, BrowserWindow, Tray, Menu, ipcMain, shell, dialog} = require('electr
 const path = require('path')
 const AppSettings = require('./utils/settings')
 const defaultSettings = require('./utils/defaultSettings')
-let microbreakIdeas = require('./microbreakIdeas')
-let breakIdeas = require('./breakIdeas')
-let BreaksPlanner = require('./breaksPlanner')
+const IdeasLoader = require('./utils/ideasLoader')
+const BreaksPlanner = require('./breaksPlanner')
 
+let microbreakIdeas
+let breakIdeas
 let breakPlanner
 let appIcon = null
 let processWin = null
@@ -108,6 +109,9 @@ function showStartUpWindow () {
 }
 
 function startMicrobreak () {
+  if (!microbreakIdeas) {
+    loadIdeas()
+  }
   // don't start another break if break running
   if (microbreakWin) {
     console.log('microbreak already running')
@@ -132,6 +136,9 @@ function startMicrobreak () {
 }
 
 function startBreak () {
+  if (!breakIdeas) {
+    loadIdeas()
+  }
   // don't start another break if break running
   if (breakWin) {
     console.log('break already running')
@@ -186,6 +193,20 @@ function loadSettings () {
   breakPlanner = new BreaksPlanner(settings, startMicrobreak, startBreak)
 }
 
+function loadIdeas () {
+  let breakIdeasData
+  let microbreakIdeasData
+  if (settings.get('useIdeasFromSettings')) {
+    breakIdeasData = settings.get('breakIdeas')
+    microbreakIdeasData = settings.get('microbreakIdeas')
+  } else {
+    breakIdeasData = require('./utils/defaultBreakIdeas')
+    microbreakIdeasData = require('./utils/defaultmicrobreakIdeas')
+  }
+  breakIdeas = new IdeasLoader(breakIdeasData).ideas()
+  microbreakIdeas = new IdeasLoader(microbreakIdeasData).ideas()
+}
+
 function pauseBreaks (seconds) {
   if (microbreakWin) {
     clearTimeout(finishMicrobreakTimer)
diff --git a/app/microbreakIdeas.js b/app/microbreakIdeas.js
deleted file mode 100644
index 8b6ece7..0000000
--- a/app/microbreakIdeas.js
+++ /dev/null
@@ -1,16 +0,0 @@
-const Shuffled = require('./utils/shuffled')
-module.exports = new Shuffled([
-  'Go grab a glass of water.',
-  'Slowly look all the way left, then right.',
-  'Slowly look all the way up, then down.',
-  'Close your eyes and take few deep breaths.',
-  'Close your eyes and relax.',
-  'Stretch your legs.',
-  'Stretch your arms.',
-  'Is your sitting pose correct?',
-  'Slowly turn head to side and hold for 10 seconds.',
-  'Slowly tilt head to side and hold for 5-10 seconds.',
-  'Stand from chair and stretch.',
-  'Refocus eyes on an object at least 20 meters away.',
-  'Take a moment to think about something you appreciate.'
-])
diff --git a/app/utils/defaultBreakIdeas.js b/app/utils/defaultBreakIdeas.js
new file mode 100644
index 0000000..62b2fe3
--- /dev/null
+++ b/app/utils/defaultBreakIdeas.js
@@ -0,0 +1,18 @@
+module.exports = [
+  {data: ['Not alone', 'Do you find it hard to take a break alone? Try to do it with a co-worker. Aside from making it easier to stick to breaks, you will have a chance to get to know them better. Taking breaks together increases productivity.'], enabled: true},
+  {data: ['Step away', 'Do you ever notice how your brain can figure things out by itself? All it takes is to step away from the computer and take a break to think about something totally unrelated.'], enabled: true},
+  {data: ['Microbreaks', 'Rest is a key component in ensuring the performance of the musculoskeletal system. Frequent breaks can decrease the duration of a task and help lower the exposure to ergonomic injury risk.'], enabled: true},
+  {data: ['Meditation', 'Research studies suggest that mindfulness-based excercises help decrease anxiety, depression, stress, and pain, and help improve general health, mental health, and quality of life. Not sure how to start? There are numerous apps to help you out.'], enabled: true},
+  {data: ['Blink', 'Looking at screens for a long time causes you to blink less, thus exposing your eyes to the air. Blink rapidly for a few seconds to refresh the tear film and clear dust from the eye surface.'], enabled: true},
+  {data: ['Ergonomics', 'Improper height and angle of the keyboard, mouse, monitor or working surface can cause health problems. Take some time to read about desk ergonomics.'], enabled: true},
+  {data: ['Move', 'There are a lot of ways you can exercise within your office. Try marching in place or doing desk push-ups.'], enabled: true},
+  {data: ['Change', 'Do you have a stability ball or standing work desk? Consider replacing your desk chair with them for a while.'], enabled: true},
+  {data: ['Notice', 'Are you daydreaming or having trouble focusing? It is a sign that you need to take a break.'], enabled: true},
+  {data: ['Tech', 'How about taking a no-tech walk?'], enabled: true},
+  {data: ['Metabolism', 'Emerging research shows that sitting for long periods of time contributes to risk of metabolic syndrome, heart attack and stroke risk and overall death risk, among others. Taking regular walking breaks can help your circulation, working to counteract some of those problems.'], enabled: true},
+  {data: ['Active Meetings', 'How about moving meetings from the conference room to the concourse? Walking not only burns calories but it may even foster a sense of collaboration.'], enabled: true},
+  {data: ['Fruit', 'Take your time and eat some fruit. Slowly. Notice the flavor, the texture, the freshness.'], enabled: true},
+  {data: ['Bathrooms', 'Walk to the farthest bathroom in the worksite facility when going to the restroom.'], enabled: true},
+  {data: ['Coffee break', 'Going on coffee break? Consider doing a 5-minute walk every time you go for one.'], enabled: true},
+  {data: ['Colleagues', 'Do not email or message office colleagues, walk to their desks to communicate with them.'], enabled: true}
+]
diff --git a/app/utils/defaultMicrobreakIdeas.js b/app/utils/defaultMicrobreakIdeas.js
new file mode 100644
index 0000000..b5b2728
--- /dev/null
+++ b/app/utils/defaultMicrobreakIdeas.js
@@ -0,0 +1,15 @@
+module.exports = [
+  { data: 'Go grab a glass of water.', enabled: true },
+  { data: 'Slowly look all the way left, then right.', enabled: true },
+  { data: 'Slowly look all the way up, then down.', enabled: true },
+  { data: 'Close your eyes and take few deep breaths.', enabled: true },
+  { data: 'Close your eyes and relax.', enabled: true },
+  { data: 'Stretch your legs.', enabled: true },
+  { data: 'Stretch your arms.', enabled: true },
+  { data: 'Is your sitting pose correct?', enabled: true },
+  { data: 'Slowly turn head to side and hold for 10 seconds.', enabled: true },
+  { data: 'Slowly tilt head to side and hold for 5-10 seconds.', enabled: true },
+  { data: 'Stand from chair and stretch.', enabled: true },
+  { data: 'Refocus eyes on an object at least 20 meters away.', enabled: true },
+  { data: 'Take a moment to think about something you appreciate.', enabled: true }
+]
diff --git a/app/utils/defaultSettings.js b/app/utils/defaultSettings.js
index 1d5157d..9c86555 100644
--- a/app/utils/defaultSettings.js
+++ b/app/utils/defaultSettings.js
@@ -8,5 +8,39 @@ module.exports = {
   microbreakStrictMode: false,
   breakStrictMode: false,
   mainColor: '#478484',
-  audio: 'crystal-glass'
+  audio: 'crystal-glass',
+  useIdeasFromSettings: false,
+  breakIdeas: [
+    {data: ['Not alone', 'Do you find it hard to take a break alone? Try to do it with a co-worker. Aside from making it easier to stick to breaks, you will have a chance to get to know them better. Taking breaks together increases productivity.'], enabled: true},
+    {data: ['Step away', 'Do you ever notice how your brain can figure things out by itself? All it takes is to step away from the computer and take a break to think about something totally unrelated.'], enabled: true},
+    {data: ['Microbreaks', 'Rest is a key component in ensuring the performance of the musculoskeletal system. Frequent breaks can decrease the duration of a task and help lower the exposure to ergonomic injury risk.'], enabled: true},
+    {data: ['Meditation', 'Research studies suggest that mindfulness-based excercises help decrease anxiety, depression, stress, and pain, and help improve general health, mental health, and quality of life. Not sure how to start? There are numerous apps to help you out.'], enabled: true},
+    {data: ['Blink', 'Looking at screens for a long time causes you to blink less, thus exposing your eyes to the air. Blink rapidly for a few seconds to refresh the tear film and clear dust from the eye surface.'], enabled: true},
+    {data: ['Ergonomics', 'Improper height and angle of the keyboard, mouse, monitor or working surface can cause health problems. Take some time to read about desk ergonomics.'], enabled: true},
+    {data: ['Move', 'There are a lot of ways you can exercise within your office. Try marching in place or doing desk push-ups.'], enabled: true},
+    {data: ['Change', 'Do you have a stability ball or standing work desk? Consider replacing your desk chair with them for a while.'], enabled: true},
+    {data: ['Notice', 'Are you daydreaming or having trouble focusing? It is a sign that you need to take a break.'], enabled: true},
+    {data: ['Tech', 'How about taking a no-tech walk?'], enabled: true},
+    {data: ['Metabolism', 'Emerging research shows that sitting for long periods of time contributes to risk of metabolic syndrome, heart attack and stroke risk and overall death risk, among others. Taking regular walking breaks can help your circulation, working to counteract some of those problems.'], enabled: true},
+    {data: ['Active Meetings', 'How about moving meetings from the conference room to the concourse? Walking not only burns calories but it may even foster a sense of collaboration.'], enabled: true},
+    {data: ['Fruit', 'Take your time and eat some fruit. Slowly. Notice the flavor, the texture, the freshness.'], enabled: true},
+    {data: ['Bathrooms', 'Walk to the farthest bathroom in the worksite facility when going to the restroom.'], enabled: true},
+    {data: ['Coffee break', 'Going on coffee break? Consider doing a 5-minute walk every time you go for one.'], enabled: true},
+    {data: ['Colleagues', 'Do not email or message office colleagues, walk to their desks to communicate with them.'], enabled: true}
+  ],
+  microbreakIdeas: [
+    { data: 'Go grab a glass of water.', enabled: true },
+    { data: 'Slowly look all the way left, then right.', enabled: true },
+    { data: 'Slowly look all the way up, then down.', enabled: true },
+    { data: 'Close your eyes and take few deep breaths.', enabled: true },
+    { data: 'Close your eyes and relax.', enabled: true },
+    { data: 'Stretch your legs.', enabled: true },
+    { data: 'Stretch your arms.', enabled: true },
+    { data: 'Is your sitting pose correct?', enabled: true },
+    { data: 'Slowly turn head to side and hold for 10 seconds.', enabled: true },
+    { data: 'Slowly tilt head to side and hold for 5-10 seconds.', enabled: true },
+    { data: 'Stand from chair and stretch.', enabled: true },
+    { data: 'Refocus eyes on an object at least 20 meters away.', enabled: true },
+    { data: 'Take a moment to think about something you appreciate.', enabled: true }
+  ]
 }
diff --git a/app/utils/ideasLoader.js b/app/utils/ideasLoader.js
new file mode 100644
index 0000000..2c494ad
--- /dev/null
+++ b/app/utils/ideasLoader.js
@@ -0,0 +1,14 @@
+let Shuffled = require('./shuffled')
+
+class IdeasLoader {
+  constructor (data) {
+    this.data = data
+  }
+
+  ideas () {
+    return new Shuffled(
+      this.data.filter(item => item.enabled).map(item => item.data)
+    )
+  }
+}
+module.exports = IdeasLoader


Test patch:
diff --git a/test/ideasLoader.js b/test/ideasLoader.js
new file mode 100644
index 0000000..6766548
--- /dev/null
+++ b/test/ideasLoader.js
@@ -0,0 +1,20 @@
+const chai = require('chai')
+const IdeasLoader = require('../app/utils/ideasLoader')
+const Shuffled = require('../app/utils/shuffled')
+
+chai.should()
+
+describe('ideasLoader', function () {
+  beforeEach(function () {
+    this.ideas = new IdeasLoader([
+      {data: 'a', enabled: true},
+      {data: 'b', enabled: false},
+      {data: 'c', enabled: true}
+    ])
+  })
+
+  it('returns enabled ideas', function () {
+    let enabled = new Shuffled(['a', 'c'])
+    this.ideas.ideas().should.be.deep.equal(enabled)
+  })
+})