Skip to content

Commit

Permalink
Fix crash in smartpause (#582)
Browse files Browse the repository at this point in the history
* smartpause: fix calling disable_safeeyes on main thread

by adding missing parameter
This was missed in 903d407

* 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.
  • Loading branch information
deltragon authored Jun 19, 2024
1 parent ba14a68 commit 4c43de8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __init__(self, system_locale, config):
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)
Expand Down
20 changes: 4 additions & 16 deletions safeeyes/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 4c43de8

Please sign in to comment.