Skip to content

Commit

Permalink
ui: move ui_async to common.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Feb 18, 2024
1 parent afdfcb0 commit ab9e068
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
18 changes: 3 additions & 15 deletions lib/solaar/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

from logitech_receiver.status import ALERT
from solaar.i18n import _
from solaar.tasks import TaskRunner as _TaskRunner
from solaar.ui.config_panel import change_setting
from solaar.ui.window import find_device

from . import diversion_rules, notify, tray, window
from . import common, diversion_rules, notify, tray, window

gi.require_version('Gtk', '3.0')
from gi.repository import Gio, GLib, Gtk # NOQA: E402
Expand All @@ -50,16 +49,11 @@
def _startup(app, startup_hook, use_tray, show_window):
if logger.isEnabledFor(logging.DEBUG):
logger.debug('startup registered=%s, remote=%s', app.get_is_registered(), app.get_is_remote())

global _task_runner
_task_runner = _TaskRunner('AsyncUI')
_task_runner.start()

common.start_async()
notify.init()
if use_tray:
tray.init(lambda _ignore: window.destroy())
window.init(show_window, use_tray)

startup_hook()


Expand Down Expand Up @@ -91,14 +85,8 @@ def _command_line(app, command_line):
def _shutdown(app, shutdown_hook):
if logger.isEnabledFor(logging.DEBUG):
logger.debug('shutdown')

shutdown_hook()

# stop the async UI processor
global _task_runner
_task_runner.stop()
_task_runner = None

common.stop_async()
tray.destroy()
notify.uninit()

Expand Down
19 changes: 16 additions & 3 deletions lib/solaar/ui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gi

from solaar.i18n import _
from solaar.tasks import TaskRunner as _TaskRunner

gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk # NOQA: E402
Expand Down Expand Up @@ -70,9 +71,21 @@ def error_dialog(reason, object):
#
#

task_runner = None
_task_runner = None


def start_async():
global _task_runner
_task_runner = _TaskRunner('AsyncUI')
_task_runner.start()


def stop_async():
global _task_runner
_task_runner.stop()
_task_runner = None


def ui_async(function, *args, **kwargs):
if task_runner:
task_runner(function, *args, **kwargs)
if _task_runner:
_task_runner(function, *args, **kwargs)

0 comments on commit ab9e068

Please sign in to comment.