Merge pull request #89 from JesseTG/jtg/custom-exercises

Support for custom exercises
This commit is contained in:
Gobinath 2017-03-09 04:46:39 -08:00 committed by GitHub
commit 84a5b8d686
3 changed files with 59 additions and 4 deletions

View File

@ -79,6 +79,42 @@ Optional Features:
## CONFIGURING SAFE EYES
Just install and forget; Safe Eyes will take care of your eyes. To customize the basic preferences, go to Settings from Safe Eyes tray icon. If you need advanced features, you can manually edit the `~/.config/safeeyes/safeeyes.json` for the following requirements:
### Adding custom exercises
We're not going to pretend that the built-in list of exercises will be enough for everybody. So you can add your own! First, modify the `custom_exercises` property (which is an empty object by default) like so:
```
...
"custom_exercises": {
"deep_breath": "Take a deep breath",
"pushups": "Do ten push-ups",
"other": "Other small things you should do on a regular basis"
}
...
```
Then add them to the `short_breaks` or `long_breaks` property as you see fit:
```
...
"short_breaks": [
...
{
"name": "deep_breath"
},
...
],
...
"long_breaks": [
...
{
"name": "pushups"
},
...
],
...
```
### Override individual break time
Add the optional `time` property to the desired break with the required time parameter. The time unit is seconds.

View File

@ -62,9 +62,18 @@ class SafeEyesCore:
self.idle_time = config['idle_time']
self.skip_break_window_classes = [x.lower() for x in config['active_window_class']['skip_break']]
self.take_break_window_classes = [x.lower() for x in config['active_window_class']['take_break']]
self.custom_exercises = config['custom_exercises']
exercises = language['exercises']
for short_break_config in config['short_breaks']:
name = language['exercises'][short_break_config['name']]
exercise_name = short_break_config['name']
name = None
if exercise_name in self.custom_exercises:
name = self.custom_exercises[exercise_name]
else:
name = exercises[exercise_name]
break_time = short_break_config.get('time', self.short_break_duration)
audible_alert = short_break_config.get('audible_alert', config['audible_alert'])
# Validate time value
@ -75,13 +84,20 @@ class SafeEyesCore:
self.short_break_exercises.append([name, break_time, audible_alert])
for long_break_config in config['long_breaks']:
name = language['exercises'][long_break_config['name']]
exercise_name = long_break_config['name']
name = None
if exercise_name in self.custom_exercises:
name = self.custom_exercises[exercise_name]
else:
name = exercises[exercise_name]
break_time = long_break_config.get('time', self.long_break_duration)
audible_alert = long_break_config.get('audible_alert', config['audible_alert'])
# Validate time value
if not isinstance(break_time, int) or break_time <= 0:
logging.error('Invalid time in long break: ' + str(short_break_config))
logging.error('Invalid time in long break: ' + str(long_break_config))
continue
self.long_break_exercises.append([name, break_time, audible_alert])

View File

@ -67,5 +67,8 @@
{
"name": "long_break_lean_back"
}
]
],
"custom_exercises": {
}
}