Skip to content

Commit 4c43de8

Browse files
authored
Fix crash in smartpause (slgobinath#582)
* 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.
1 parent ba14a68 commit 4c43de8

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

safeeyes/safeeyes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__(self, system_locale, config):
7171
self.show_about)
7272
self.context['api']['enable_safeeyes'] = lambda next_break_time=-1, reset_breaks=False: \
7373
utility.execute_main_thread(self.enable_safeeyes, next_break_time, reset_breaks)
74-
self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread(
75-
self.disable_safeeyes, status)
74+
self.context['api']['disable_safeeyes'] = lambda status=None, is_resting=False: utility.execute_main_thread(
75+
self.disable_safeeyes, status, is_resting)
7676
self.context['api']['status'] = self.status
7777
self.context['api']['quit'] = lambda: utility.execute_main_thread(
7878
self.quit)

safeeyes/utility.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,16 @@ def start_thread(target_function, **args):
9494
thread.start()
9595

9696

97-
# def execute_main_thread(target_function, args=None):
97+
# def execute_main_thread(target_function, *args, **kwargs):
9898
# """
99-
# Execute the given function in main thread.
99+
# Execute the given function in main thread, forwarding positional and keyword arguments.
100100
# """
101-
# if args:
102-
# GLib.idle_add(lambda: target_function(args))
103-
# else:
104-
# GLib.idle_add(target_function)
105101

106-
def execute_main_thread(target_function, arg1=None, arg2=None):
102+
def execute_main_thread(target_function, *args, **kwargs):
107103
"""
108104
Execute the given function in main thread.
109105
"""
110-
if arg1 is not None and arg2 is not None:
111-
GLib.idle_add(lambda: target_function(arg1, arg2))
112-
elif arg1 is not None:
113-
GLib.idle_add(lambda: target_function(arg1))
114-
elif arg2 is not None:
115-
GLib.idle_add(lambda: target_function(arg2))
116-
else:
117-
GLib.idle_add(target_function)
118-
106+
GLib.idle_add(lambda: target_function(*args, **kwargs))
119107

120108
def system_locale(category=locale.LC_MESSAGES):
121109
"""

0 commit comments

Comments
 (0)