Skip to content

Commit

Permalink
Cherry-picked threading changed from #822
Browse files Browse the repository at this point in the history
  • Loading branch information
friday committed Aug 1, 2022
1 parent 8727f5c commit 61f3db7
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions ulauncher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import signal
import logging
import time
from functools import partial
from threading import Event
# This xinit import must happen before any GUI libraries are initialized.
# pylint: disable=wrong-import-position,wrong-import-order,ungrouped-imports,unused-import
Expand All @@ -15,20 +15,20 @@

gi.require_version('Gtk', '3.0')
# pylint: disable=wrong-import-position
from gi.repository import Gtk
from gi.repository import Gtk, GLib
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop

from ulauncher.config import get_version, get_options, CACHE_DIR, CONFIG_DIR, DATA_DIR
from ulauncher.utils.decorator.run_async import run_async
from ulauncher.utils.wayland import is_wayland, is_wayland_compatibility_on
from ulauncher.ui.windows.UlauncherWindow import UlauncherWindow
from ulauncher.ui.AppIndicator import AppIndicator
from ulauncher.utils.Settings import Settings
from ulauncher.utils.setup_logging import setup_logging
from ulauncher.api.version import api_version

logger = logging.getLogger('ulauncher')

DBUS_SERVICE = 'net.launchpad.ulauncher'
DBUS_PATH = '/net/launchpad/ulauncher'
Expand Down Expand Up @@ -57,6 +57,18 @@ def toggle_window(self):
self.window.toggle_window()


def reload_config(win):
logger.info("Reloading config")
win.init_theme()


def graceful_exit(data):
logger.info("Exiting gracefully nesting level %s: %s", Gtk.main_level(), data)
# ExtensionServer.get_instance().stop()
# Gtk.main_quit()
sys.exit(0)


# pylint: disable=too-few-public-methods
class SignalHandler:

Expand Down Expand Up @@ -109,7 +121,6 @@ def main():

options = get_options()
setup_logging(options)
logger = logging.getLogger('ulauncher')
logger.info('Ulauncher version %s', get_version())
logger.info('Extension API version %s', api_version)
logger.info("GTK+ %s.%s.%s", Gtk.get_major_version(), Gtk.get_minor_version(), Gtk.get_micro_version())
Expand All @@ -130,13 +141,15 @@ def except_hook(exctype, value, tb):
if Settings.get_instance().get_property('show-indicator-icon'):
AppIndicator.get_instance().show()

# workaround to make Ctrl+C quitting the app
signal_handler = SignalHandler(window)
gtk_thread = run_async(Gtk.main)()
GLib.unix_signal_add(
GLib.PRIORITY_DEFAULT,
signal.SIGHUP,
partial(reload_config, window),
None
)
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGTERM, graceful_exit, None)

try:
while gtk_thread.is_alive() and not signal_handler.killed():
time.sleep(0.5)
Gtk.main()
except KeyboardInterrupt:
logger.warning('On KeyboardInterrupt')
finally:
Gtk.main_quit()

0 comments on commit 61f3db7

Please sign in to comment.