Add user defined lock command
This commit is contained in:
parent
692a6688b0
commit
382cc5ffb1
|
@ -75,9 +75,15 @@ class SettingsDialog:
|
|||
self.spin_postpone_duration.set_value(config['postpone_duration'])
|
||||
self.switch_strict_break.set_active(config['strict_break'])
|
||||
self.switch_audible_alert.set_active(config['audible_alert'])
|
||||
self.switch_screen_lock.set_sensitive(Utility.is_desktop_lock_supported())
|
||||
self.switch_screen_lock.set_active(Utility.is_desktop_lock_supported() and config['enable_screen_lock'])
|
||||
self.spin_time_to_screen_lock.set_value(config['time_to_screen_lock'])
|
||||
|
||||
# Check lock screen command
|
||||
able_to_lock_screen = False
|
||||
if config['lock_screen_command'] or Utility.lock_screen_command():
|
||||
able_to_lock_screen = True
|
||||
|
||||
self.switch_screen_lock.set_sensitive(able_to_lock_screen)
|
||||
self.switch_screen_lock.set_active(able_to_lock_screen and config['enable_screen_lock'])
|
||||
self.on_switch_screen_lock_activate(self.switch_screen_lock, self.switch_screen_lock.get_active())
|
||||
|
||||
# Initialize the language combobox
|
||||
|
|
|
@ -282,14 +282,15 @@ def lock_screen_command():
|
|||
return ['gnome-screensaver-command', '--lock']
|
||||
return None
|
||||
|
||||
def is_desktop_lock_supported():
|
||||
return lock_screen_command() is not None
|
||||
|
||||
def lock_desktop():
|
||||
def lock_desktop(user_defined_command):
|
||||
"""
|
||||
Lock the screen using the predefined commands
|
||||
"""
|
||||
command = lock_screen_command()
|
||||
if user_defined_command:
|
||||
command = user_defined_command
|
||||
else:
|
||||
command = lock_screen_command()
|
||||
if command is not None:
|
||||
try:
|
||||
subprocess.Popen(command)
|
||||
|
|
|
@ -89,17 +89,12 @@ def close_alert(audible_alert_on):
|
|||
logging.info("Close the break screen")
|
||||
if config['enable_screen_lock'] and context['break_type'] == 'long':
|
||||
# Lock the screen before closing the break screen
|
||||
Utility.lock_desktop()
|
||||
Utility.lock_desktop(config['lock_screen_command'])
|
||||
break_screen.close()
|
||||
if audible_alert_on:
|
||||
Utility.play_notification()
|
||||
plugins.post_break(context)
|
||||
|
||||
"""
|
||||
Receive the count from core and pass it to the break screen.
|
||||
"""
|
||||
def on_countdown(count):
|
||||
break_screen.show_count_down(count)
|
||||
|
||||
"""
|
||||
Listen to the tray menu quit action and stop the core, notification and the app itself.
|
||||
|
@ -142,7 +137,7 @@ def on_skipped():
|
|||
logging.info("User skipped the break")
|
||||
if config['enable_screen_lock'] and context['break_type'] == 'long' and context.get('count_down', 0) >= config['time_to_screen_lock']:
|
||||
# Lock the screen before closing the break screen
|
||||
Utility.lock_desktop()
|
||||
Utility.lock_desktop(config['lock_screen_command'])
|
||||
core.skip_break()
|
||||
|
||||
"""
|
||||
|
@ -152,7 +147,7 @@ def on_postponed():
|
|||
logging.info("User postponed the break")
|
||||
if config['enable_screen_lock'] and context['break_type'] == 'long' and context.get('count_down', 0) >= config['time_to_screen_lock']:
|
||||
# Lock the screen before closing the break screen
|
||||
Utility.lock_desktop()
|
||||
Utility.lock_desktop(config['lock_screen_command'])
|
||||
core.postpone_break()
|
||||
|
||||
"""
|
||||
|
@ -212,16 +207,18 @@ def initialize_config():
|
|||
Utility.mkdir(config_dir_path)
|
||||
|
||||
if not os.path.isfile(config_file_path):
|
||||
# Copy the safeeyes.json
|
||||
shutil.copy2(system_config_file_path, config_file_path)
|
||||
|
||||
# Overwrite the startup file only if config file is replaced
|
||||
Utility.mkdir(startup_dir_path)
|
||||
|
||||
# Add to startup for the first time only
|
||||
try:
|
||||
os.symlink("/usr/share/applications/safeeyes.desktop", os.path.join(startup_dir_path, "safeeyes.desktop"))
|
||||
except OSError as exc:
|
||||
pass
|
||||
|
||||
# Copy the safeeyes_style.css
|
||||
if not os.path.isfile(style_sheet_path):
|
||||
shutil.copy2(system_style_sheet_path, style_sheet_path)
|
||||
|
||||
|
@ -247,9 +244,15 @@ def validate_config():
|
|||
version_mismatch = True
|
||||
|
||||
if version_mismatch:
|
||||
# Remove ~/.config/safeeyes directory
|
||||
# Remove ~/.config/safeeyes/safeeyes.json file
|
||||
try:
|
||||
shutil.rmtree(os.path.join(Utility.home_directory, '.config/safeeyes'), ignore_errors=False)
|
||||
os.remove(config_file_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Remove ~/.config/safeeyes/style/safeeyes_style.css file
|
||||
try:
|
||||
os.remove(style_sheet_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
@ -277,7 +280,6 @@ def running():
|
|||
if process_count > 1:
|
||||
return True
|
||||
|
||||
|
||||
# Ignore if process does not exist or does not have command line args
|
||||
except (IndexError, psutil.NoSuchProcess):
|
||||
pass
|
||||
|
@ -313,7 +315,7 @@ def main():
|
|||
break_screen.initialize(config, language)
|
||||
notification = Notification(language)
|
||||
plugins = Plugins(config)
|
||||
core = SafeEyesCore(context, show_notification, show_alert, close_alert, on_countdown, tray_icon.next_break_time)
|
||||
core = SafeEyesCore(context, show_notification, show_alert, close_alert, break_screen.show_count_down, tray_icon.next_break_time)
|
||||
core.initialize(config, language)
|
||||
plugins.start(context) # Call the start method of all plugins
|
||||
core.start()
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
},
|
||||
"break_interval": 15,
|
||||
"enable_screen_lock": true,
|
||||
"enable_statistic": false,
|
||||
"long_break_duration": 60,
|
||||
"no_of_short_breaks_per_long_break": 5,
|
||||
"pre_break_warning_time": 10,
|
||||
|
@ -14,6 +15,7 @@
|
|||
"audible_alert": false,
|
||||
"language": "system",
|
||||
"time_to_screen_lock": 5,
|
||||
"lock_screen_command": [],
|
||||
"active_window_class": {
|
||||
"skip_break": [],
|
||||
"take_break": []
|
||||
|
|
Loading…
Reference in New Issue