[fix][tray] not working when installed on a virtualenv

This commit is contained in:
Vinícius Moreira
2020-04-14 10:33:46 -03:00
parent e9b26ffc08
commit 2decb97179
3 changed files with 23 additions and 11 deletions

View File

@@ -32,7 +32,7 @@ def main(tray: bool = False):
if tray or bool(args.tray):
from bauh.tray import new_tray_icon
app, widget = new_tray_icon(app_config)
app, widget = new_tray_icon(app_config, logger)
else:
from bauh.manage import new_manage_panel
app, widget = new_manage_panel(args, app_config, logger)

View File

@@ -1,3 +1,4 @@
import logging
from typing import Tuple
from PyQt5.QtWidgets import QApplication, QWidget
@@ -6,9 +7,9 @@ from bauh.context import new_qt_application
from bauh.view.qt.systray import TrayIcon
def new_tray_icon(app_config: dict) -> Tuple[QApplication, QWidget]:
def new_tray_icon(app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]:
app = new_qt_application(app_config, quit_on_last_closed=True)
tray_icon = TrayIcon(screen_size=app.primaryScreen().size(), config=app_config)
tray_icon = TrayIcon(screen_size=app.primaryScreen().size(), config=app_config, logger=logger)
tray_icon.show()
return app, tray_icon

View File

@@ -1,4 +1,5 @@
import json
import logging
import os
import sys
import time
@@ -21,13 +22,20 @@ from bauh.view.qt.about import AboutDialog
from bauh.view.qt.view_utils import load_resource_icon
from bauh.view.util import util, resource
CLI_PATH = '{}/bin/bauh-cli'.format(sys.exec_prefix)
def list_updates() -> List[PackageUpdate]:
if run_cmd('which bauh-cli', print_error=False):
output = run_cmd('bauh-cli updates -f json')
def list_updates(logger: logging.Logger) -> List[PackageUpdate]:
if os.path.exists(CLI_PATH):
output = run_cmd('{} updates -f json'.format(CLI_PATH))
if output:
return [PackageUpdate(pkg_id=o['id'], name=o['name'], version=o['version'], pkg_type=o['type']) for o in json.loads(output)]
else:
logger.info("No updates found")
else:
logger.warning('bauh-cli seems not to be installed ({})'.format(CLI_PATH))
return []
@@ -36,16 +44,17 @@ class UpdateCheck(QThread):
signal = pyqtSignal(list)
def __init__(self, check_interval: int, lock: Lock, check_file: bool, parent=None):
def __init__(self, check_interval: int, lock: Lock, check_file: bool, logger: logging.Logger, parent=None):
super(UpdateCheck, self).__init__(parent)
self.check_interval = check_interval
self.lock = lock
self.check_file = check_file
self.logger = logger
def _notify_updates(self):
self.lock.acquire()
try:
updates = list_updates()
updates = list_updates(self.logger)
if updates is not None:
self.signal.emit(updates)
@@ -71,12 +80,13 @@ class UpdateCheck(QThread):
class TrayIcon(QSystemTrayIcon):
def __init__(self, config: dict, screen_size: QSize, manage_process: Popen = None, settings_process: Popen = None):
def __init__(self, config: dict, screen_size: QSize, logger: logging.Logger, manage_process: Popen = None, settings_process: Popen = None):
super(TrayIcon, self).__init__()
self.i18n = generate_i18n(config, resource.get_path('locale/tray'))
self.screen_size = screen_size
self.manage_process = manage_process
self.settings_process = settings_process
self.logger = logger
if config['ui']['tray']['default_icon']:
self.icon_default = QIcon(config['ui']['tray']['default_icon'])
@@ -117,11 +127,11 @@ class TrayIcon(QSystemTrayIcon):
self.settings_window = None
self.check_lock = Lock()
self.check_thread = UpdateCheck(check_interval=int(config['updates']['check_interval']), check_file=False, lock=self.check_lock)
self.check_thread = UpdateCheck(check_interval=int(config['updates']['check_interval']), check_file=False, lock=self.check_lock, logger=logger)
self.check_thread.signal.connect(self.notify_updates)
self.check_thread.start()
self.recheck_thread = UpdateCheck(check_interval=2, check_file=True, lock=self.check_lock)
self.recheck_thread = UpdateCheck(check_interval=2, check_file=True, lock=self.check_lock, logger=logger)
self.recheck_thread.signal.connect(self.notify_updates)
self.recheck_thread.start()
@@ -150,6 +160,7 @@ class TrayIcon(QSystemTrayIcon):
try:
if len(updates) > 0:
self.logger.info("{} updates available".format(len(updates)))
update_keys = {'{}:{}:{}'.format(up.type, up.id, up.version) for up in updates}
new_icon = self.icon_updates