From 4c43de8fff2dbf856fe77e73922530b119f5f8ee Mon Sep 17 00:00:00 2001 From: deltragon Date: Wed, 19 Jun 2024 02:15:47 +0200 Subject: [PATCH] Fix crash in smartpause (#582) * smartpause: fix calling disable_safeeyes on main thread by adding missing parameter This was missed in 903d407faf58871fd84756ec76d6b5c2543f6540 * fix forwarding arguments in execute_main_thread This broke when the first parameter was None, but the second wasn't (the second parameter wasn't passed at all.) Use *args/**kwargs to make it behave properly in all cases. --- safeeyes/safeeyes.py | 4 ++-- safeeyes/utility.py | 20 ++++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/safeeyes/safeeyes.py b/safeeyes/safeeyes.py index 1345e9c..bf1ddb4 100644 --- a/safeeyes/safeeyes.py +++ b/safeeyes/safeeyes.py @@ -71,8 +71,8 @@ class SafeEyes: self.show_about) self.context['api']['enable_safeeyes'] = lambda next_break_time=-1, reset_breaks=False: \ utility.execute_main_thread(self.enable_safeeyes, next_break_time, reset_breaks) - self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread( - self.disable_safeeyes, status) + self.context['api']['disable_safeeyes'] = lambda status=None, is_resting=False: utility.execute_main_thread( + self.disable_safeeyes, status, is_resting) self.context['api']['status'] = self.status self.context['api']['quit'] = lambda: utility.execute_main_thread( self.quit) diff --git a/safeeyes/utility.py b/safeeyes/utility.py index 3976140..ea25088 100644 --- a/safeeyes/utility.py +++ b/safeeyes/utility.py @@ -94,28 +94,16 @@ def start_thread(target_function, **args): thread.start() -# def execute_main_thread(target_function, args=None): +# def execute_main_thread(target_function, *args, **kwargs): # """ -# Execute the given function in main thread. +# Execute the given function in main thread, forwarding positional and keyword arguments. # """ -# if args: -# GLib.idle_add(lambda: target_function(args)) -# else: -# GLib.idle_add(target_function) -def execute_main_thread(target_function, arg1=None, arg2=None): +def execute_main_thread(target_function, *args, **kwargs): """ Execute the given function in main thread. """ - if arg1 is not None and arg2 is not None: - GLib.idle_add(lambda: target_function(arg1, arg2)) - elif arg1 is not None: - GLib.idle_add(lambda: target_function(arg1)) - elif arg2 is not None: - GLib.idle_add(lambda: target_function(arg2)) - else: - GLib.idle_add(target_function) - + GLib.idle_add(lambda: target_function(*args, **kwargs)) def system_locale(category=locale.LC_MESSAGES): """