mirror of
https://github.com/slgobinath/SafeEyes.git
synced 2025-01-01 00:47:31 +01:00
Add override audible alert per break
This commit is contained in:
parent
b50cb4b8f7
commit
d5eca3c185
@ -63,28 +63,27 @@ class SafeEyesCore:
|
||||
|
||||
for short_break_config in config['short_breaks']:
|
||||
name = language['exercises'][short_break_config['name']]
|
||||
# break_time = short_break_config['time']
|
||||
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
|
||||
if not isinstance(break_time, int) or break_time <= 0:
|
||||
logging.error('Invalid time in short break: ' + str(short_break_config))
|
||||
continue
|
||||
|
||||
self.short_break_exercises.append([name, break_time])
|
||||
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']]
|
||||
break_time = long_break_config.get('time', self.short_break_duration)
|
||||
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 break_time:
|
||||
break_time = self.short_break_duration
|
||||
elif not isinstance(break_time, int) or break_time <= 0:
|
||||
if not isinstance(break_time, int) or break_time <= 0:
|
||||
logging.error('Invalid time in short break: ' + str(long_break_config))
|
||||
continue
|
||||
else:
|
||||
break_time = break_time * 60 # Convert to seconds
|
||||
|
||||
self.long_break_exercises.append([name, break_time])
|
||||
self.long_break_exercises.append([name, break_time, audible_alert])
|
||||
|
||||
|
||||
"""
|
||||
@ -213,16 +212,19 @@ class SafeEyesCore:
|
||||
if self.__is_running():
|
||||
message = ""
|
||||
seconds = 0
|
||||
audible_alert = None
|
||||
if self.__is_long_break():
|
||||
logging.info("Count is {}; get a long beak message".format(self.break_count))
|
||||
self.long_break_message_index = (self.long_break_message_index + 1) % len(self.long_break_exercises)
|
||||
message = self.long_break_exercises[self.long_break_message_index][0]
|
||||
seconds = self.long_break_exercises[self.long_break_message_index][1]
|
||||
audible_alert = self.long_break_exercises[self.long_break_message_index][2]
|
||||
else:
|
||||
logging.info("Count is {}; get a short beak message".format(self.break_count))
|
||||
self.short_break_message_index = (self.short_break_message_index + 1) % len(self.short_break_exercises)
|
||||
message = self.short_break_exercises[self.short_break_message_index][0]
|
||||
seconds = self.short_break_exercises[self.short_break_message_index][1]
|
||||
audible_alert = self.short_break_exercises[self.short_break_message_index][2]
|
||||
|
||||
# Show the break screen
|
||||
self.start_break(message)
|
||||
@ -238,7 +240,7 @@ class SafeEyesCore:
|
||||
# Loop terminated because of timeout (not skipped) -> Close the break alert
|
||||
if not self.skipped:
|
||||
logging.info("Break wasn't skipped. Automatically terminating the break")
|
||||
self.end_break()
|
||||
self.end_break(audible_alert)
|
||||
|
||||
# Resume
|
||||
if self.__is_running():
|
||||
|
@ -21,13 +21,16 @@ gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gdk, GLib
|
||||
import babel.dates, os, errno, subprocess, threading, logging, locale
|
||||
|
||||
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
home_directory = os.path.expanduser('~')
|
||||
|
||||
"""
|
||||
Play the alert.mp3
|
||||
"""
|
||||
def play_notification():
|
||||
logging.info("Playing audible alert")
|
||||
try:
|
||||
subprocess.Popen(['mpg123', '-q', os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resource/alert.mp3')])
|
||||
subprocess.Popen(['mpg123', '-q', os.path.join(bin_directory, 'resource/alert.mp3')])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -1,37 +1,37 @@
|
||||
{
|
||||
"meta": {
|
||||
"config_version": 3
|
||||
},
|
||||
"break_interval": 15,
|
||||
"meta": {
|
||||
"config_version": 3
|
||||
},
|
||||
"break_interval": 15,
|
||||
"long_break_duration": 60,
|
||||
"no_of_short_breaks_per_long_break": 5,
|
||||
"pre_break_warning_time": 10,
|
||||
"short_break_duration": 15,
|
||||
"no_of_short_breaks_per_long_break": 5,
|
||||
"pre_break_warning_time": 10,
|
||||
"short_break_duration": 15,
|
||||
"idle_time": 5,
|
||||
"strict_break": false,
|
||||
"audible_alert": false,
|
||||
"language": "en",
|
||||
"disable_options": [
|
||||
{
|
||||
"label": "for_x_minutes",
|
||||
"time": 30,
|
||||
"unit": "minute"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hour",
|
||||
"time": 1,
|
||||
"unit": "hour"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hours",
|
||||
"time": 2,
|
||||
"unit": "hour"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hours",
|
||||
"time": 3,
|
||||
"unit": "hour"
|
||||
}
|
||||
{
|
||||
"label": "for_x_minutes",
|
||||
"time": 30,
|
||||
"unit": "minute"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hour",
|
||||
"time": 1,
|
||||
"unit": "hour"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hours",
|
||||
"time": 2,
|
||||
"unit": "hour"
|
||||
},
|
||||
{
|
||||
"label": "for_x_hours",
|
||||
"time": 3,
|
||||
"unit": "hour"
|
||||
}
|
||||
],
|
||||
"short_breaks": [
|
||||
{
|
||||
|
@ -31,16 +31,15 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Define necessary paths
|
||||
bin_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
config_file_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/safeeyes.json')
|
||||
style_sheet_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/style/safeeyes_style.css')
|
||||
log_file_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/safeeyes.log')
|
||||
break_screen_glade = os.path.join(bin_directory, "glade/break_screen.glade")
|
||||
settings_dialog_glade = os.path.join(bin_directory, "glade/settings_dialog.glade")
|
||||
about_dialog_glade = os.path.join(bin_directory, "glade/about_dialog.glade")
|
||||
system_config_file_path = os.path.join(bin_directory, "config/safeeyes.json")
|
||||
system_style_sheet_path = os.path.join(bin_directory, "config/style/safeeyes_style.css")
|
||||
system_language_directory = os.path.join(bin_directory, "config/lang")
|
||||
config_file_path = os.path.join(Utility.home_directory, '.config/safeeyes/safeeyes.json')
|
||||
style_sheet_path = os.path.join(Utility.home_directory, '.config/safeeyes/style/safeeyes_style.css')
|
||||
log_file_path = os.path.join(Utility.home_directory, '.config/safeeyes/safeeyes.log')
|
||||
break_screen_glade = os.path.join(Utility.bin_directory, "glade/break_screen.glade")
|
||||
settings_dialog_glade = os.path.join(Utility.bin_directory, "glade/settings_dialog.glade")
|
||||
about_dialog_glade = os.path.join(Utility.bin_directory, "glade/about_dialog.glade")
|
||||
system_config_file_path = os.path.join(Utility.bin_directory, "config/safeeyes.json")
|
||||
system_style_sheet_path = os.path.join(Utility.bin_directory, "config/style/safeeyes_style.css")
|
||||
system_language_directory = os.path.join(Utility.bin_directory, "config/lang")
|
||||
|
||||
is_active = True
|
||||
CONFIGURATION_VERSION = 3
|
||||
@ -79,10 +78,10 @@ def show_alert(message):
|
||||
"""
|
||||
Receive the stop break signal from core and pass it to the break screen.
|
||||
"""
|
||||
def close_alert():
|
||||
def close_alert(audible_alert_on):
|
||||
logging.info("Close the break screen")
|
||||
break_screen.close()
|
||||
if config['audible_alert']:
|
||||
if audible_alert_on:
|
||||
Utility.play_notification()
|
||||
|
||||
"""
|
||||
@ -184,8 +183,8 @@ def disable_safeeyes():
|
||||
"""
|
||||
def initialize_config():
|
||||
global config
|
||||
config_dir_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/style')
|
||||
startup_dir_path = os.path.join(os.path.expanduser('~'), '.config/autostart')
|
||||
config_dir_path = os.path.join(Utility.home_directory, '.config/safeeyes/style')
|
||||
startup_dir_path = os.path.join(Utility.home_directory, '.config/autostart')
|
||||
|
||||
Utility.mkdir(config_dir_path)
|
||||
|
||||
@ -227,13 +226,13 @@ def validate_config():
|
||||
if version_mismatch:
|
||||
# Remove ~/.config/safeeyes directory
|
||||
try:
|
||||
shutil.rmtree(os.path.join(os.path.expanduser('~'), '.config/safeeyes'), ignore_errors=False)
|
||||
shutil.rmtree(os.path.join(Utility.home_directory, '.config/safeeyes'), ignore_errors=False)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Remove startup script
|
||||
try:
|
||||
os.remove(os.path.join(os.path.expanduser('~'), '.config/autostart/safeeyes.desktop'))
|
||||
os.remove(os.path.join(Utility.home_directory, '.config/autostart/safeeyes.desktop'))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user