Skip to content

Commit

Permalink
Merge pull request #168 from Ulauncher/issue-166
Browse files Browse the repository at this point in the history
#166: Fixed swtich indicator on/off using GLib.idle_add to avoid crashes
  • Loading branch information
gornostal committed Sep 30, 2017
2 parents 8070e42 + 4f56566 commit 5a9124a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions tests/ui/windows/test_PreferencesUlauncherDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def webview(self, mocker):
def hotkey_dialog(self, mocker):
return mocker.patch('ulauncher.ui.windows.PreferencesUlauncherDialog.HotkeyDialog').return_value

@pytest.fixture(autouse=True)
def idle_add(self, mocker):
return mocker.patch('ulauncher.ui.windows.PreferencesUlauncherDialog.GLib.idle_add')

@pytest.fixture
def builder(self):
return mock.MagicMock()
Expand All @@ -45,13 +49,13 @@ def dialog(self, builder, mocker, settings, webview, autostart_pref, hotkey_dial
dialog.builder = builder
return dialog

def test_prefs_set_show_indicator_icon(self, dialog, builder, settings, indicator):
def test_prefs_set_show_indicator_icon(self, dialog, builder, settings, indicator, idle_add):
dialog.prefs_set_show_indicator_icon({'query': {'value': 'true'}})
indicator.show.assert_called_with()
idle_add.assert_called_with(indicator.switch, True)
settings.set_property.assert_called_with('show-indicator-icon', True)

dialog.prefs_set_show_indicator_icon({'query': {'value': '0'}})
indicator.hide.assert_called_with()
idle_add.assert_called_with(indicator.switch, False)
settings.set_property.assert_called_with('show-indicator-icon', False)
settings.save_to_file.assert_called_with()

Expand Down
3 changes: 3 additions & 0 deletions ulauncher/ui/AppIndicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, iconname):
def set_icon(self, path):
self.__indicator.set_icon(path)

def switch(self, on=False):
self.show() if on else self.hide()

def add_menu_item(self, command, title):
menu_item = Gtk.MenuItem()
menu_item.set_label(title)
Expand Down
6 changes: 3 additions & 3 deletions ulauncher/ui/windows/PreferencesUlauncherDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import json

from gi.repository import Gio, Gtk, WebKit2
from gi.repository import Gio, Gtk, WebKit2, GLib
from urllib import unquote
from base64 import b64decode

Expand Down Expand Up @@ -191,9 +191,9 @@ def prefs_set_show_indicator_icon(self, url_params):
show_indicator = self._get_bool(url_params['query']['value'])
logger.info('Set show-indicator-icon to %s' % show_indicator)
self.settings.set_property('show-indicator-icon', show_indicator)
indicator = AppIndicator.get_instance()
indicator.show() if show_indicator else indicator.hide()
self.settings.save_to_file()
indicator = AppIndicator.get_instance()
GLib.idle_add(indicator.switch, show_indicator)

@rt.route('/set/autostart-enabled')
def prefs_set_autostart(self, url_params):
Expand Down

0 comments on commit 5a9124a

Please sign in to comment.