mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[fix][tray] not working when installed on a virtualenv
This commit is contained in:
@@ -32,7 +32,7 @@ def main(tray: bool = False):
|
|||||||
|
|
||||||
if tray or bool(args.tray):
|
if tray or bool(args.tray):
|
||||||
from bauh.tray import new_tray_icon
|
from bauh.tray import new_tray_icon
|
||||||
app, widget = new_tray_icon(app_config)
|
app, widget = new_tray_icon(app_config, logger)
|
||||||
else:
|
else:
|
||||||
from bauh.manage import new_manage_panel
|
from bauh.manage import new_manage_panel
|
||||||
app, widget = new_manage_panel(args, app_config, logger)
|
app, widget = new_manage_panel(args, app_config, logger)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication, QWidget
|
from PyQt5.QtWidgets import QApplication, QWidget
|
||||||
@@ -6,9 +7,9 @@ from bauh.context import new_qt_application
|
|||||||
from bauh.view.qt.systray import TrayIcon
|
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)
|
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()
|
tray_icon.show()
|
||||||
|
|
||||||
return app, tray_icon
|
return app, tray_icon
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
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.qt.view_utils import load_resource_icon
|
||||||
from bauh.view.util import util, resource
|
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):
|
def list_updates(logger: logging.Logger) -> List[PackageUpdate]:
|
||||||
output = run_cmd('bauh-cli updates -f json')
|
if os.path.exists(CLI_PATH):
|
||||||
|
output = run_cmd('{} updates -f json'.format(CLI_PATH))
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
return [PackageUpdate(pkg_id=o['id'], name=o['name'], version=o['version'], pkg_type=o['type']) for o in json.loads(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 []
|
return []
|
||||||
|
|
||||||
@@ -36,16 +44,17 @@ class UpdateCheck(QThread):
|
|||||||
|
|
||||||
signal = pyqtSignal(list)
|
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)
|
super(UpdateCheck, self).__init__(parent)
|
||||||
self.check_interval = check_interval
|
self.check_interval = check_interval
|
||||||
self.lock = lock
|
self.lock = lock
|
||||||
self.check_file = check_file
|
self.check_file = check_file
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
def _notify_updates(self):
|
def _notify_updates(self):
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
try:
|
try:
|
||||||
updates = list_updates()
|
updates = list_updates(self.logger)
|
||||||
|
|
||||||
if updates is not None:
|
if updates is not None:
|
||||||
self.signal.emit(updates)
|
self.signal.emit(updates)
|
||||||
@@ -71,12 +80,13 @@ class UpdateCheck(QThread):
|
|||||||
|
|
||||||
class TrayIcon(QSystemTrayIcon):
|
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__()
|
super(TrayIcon, self).__init__()
|
||||||
self.i18n = generate_i18n(config, resource.get_path('locale/tray'))
|
self.i18n = generate_i18n(config, resource.get_path('locale/tray'))
|
||||||
self.screen_size = screen_size
|
self.screen_size = screen_size
|
||||||
self.manage_process = manage_process
|
self.manage_process = manage_process
|
||||||
self.settings_process = settings_process
|
self.settings_process = settings_process
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
if config['ui']['tray']['default_icon']:
|
if config['ui']['tray']['default_icon']:
|
||||||
self.icon_default = QIcon(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.settings_window = None
|
||||||
|
|
||||||
self.check_lock = Lock()
|
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.signal.connect(self.notify_updates)
|
||||||
self.check_thread.start()
|
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.signal.connect(self.notify_updates)
|
||||||
self.recheck_thread.start()
|
self.recheck_thread.start()
|
||||||
|
|
||||||
@@ -150,6 +160,7 @@ class TrayIcon(QSystemTrayIcon):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if len(updates) > 0:
|
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}
|
update_keys = {'{}:{}:{}'.format(up.type, up.id, up.version) for up in updates}
|
||||||
|
|
||||||
new_icon = self.icon_updates
|
new_icon = self.icon_updates
|
||||||
|
|||||||
Reference in New Issue
Block a user