1
0
mirror of https://github.com/slgobinath/SafeEyes.git synced 2024-12-24 23:50:46 +01:00

Fix crash in smartpause (#582)

* smartpause: fix calling disable_safeeyes on main thread

by adding missing parameter
This was missed in 903d407faf

* 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.
This commit is contained in:
deltragon 2024-06-19 02:15:47 +02:00 committed by GitHub
parent ba14a6831e
commit 4c43de8fff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 18 deletions

View File

@ -71,8 +71,8 @@ class SafeEyes:
self.show_about) self.show_about)
self.context['api']['enable_safeeyes'] = lambda next_break_time=-1, reset_breaks=False: \ 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) utility.execute_main_thread(self.enable_safeeyes, next_break_time, reset_breaks)
self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread( self.context['api']['disable_safeeyes'] = lambda status=None, is_resting=False: utility.execute_main_thread(
self.disable_safeeyes, status) self.disable_safeeyes, status, is_resting)
self.context['api']['status'] = self.status self.context['api']['status'] = self.status
self.context['api']['quit'] = lambda: utility.execute_main_thread( self.context['api']['quit'] = lambda: utility.execute_main_thread(
self.quit) self.quit)

View File

@ -94,28 +94,16 @@ def start_thread(target_function, **args):
thread.start() 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. Execute the given function in main thread.
""" """
if arg1 is not None and arg2 is not None: GLib.idle_add(lambda: target_function(*args, **kwargs))
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)
def system_locale(category=locale.LC_MESSAGES): def system_locale(category=locale.LC_MESSAGES):
""" """