diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecec11c..c6a78e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.9.1] 2020 +### Features +- Tray + - displaying a notification when there is a new bauh release + ### Improvements - Internet availability checking code - Arch diff --git a/bauh/view/core/controller.py b/bauh/view/core/controller.py index 0192f53b..f3f819e5 100755 --- a/bauh/view/core/controller.py +++ b/bauh/view/core/controller.py @@ -1,12 +1,10 @@ -import os +import re import re import time import traceback -from pathlib import Path from threading import Thread from typing import List, Set, Type, Tuple, Dict -from bauh import __app_name__, __version__ from bauh.api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext, UpgradeRequirements, \ UpgradeRequirement from bauh.api.abstract.disk import DiskCacheLoader @@ -14,11 +12,10 @@ from bauh.api.abstract.handler import ProcessWatcher, TaskManager from bauh.api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory, PackageSuggestion, \ CustomSoftwareAction from bauh.api.abstract.view import ViewComponent, TabGroupComponent -from bauh.api.constants import CACHE_PATH from bauh.api.exception import NoInternetException from bauh.commons import internet -from bauh.commons.html import bold, link from bauh.view.core.settings import GenericSettingsManager +from bauh.view.core.update import check_for_update RE_IS_URL = re.compile(r'^https?://.+') @@ -330,50 +327,13 @@ class GenericSoftwareManager(SoftwareManager): return updates - def _check_for_updates(self) -> str: - self.logger.info("Checking for updates") - - try: - releases = self.http_client.get_json('https://api.github.com/repos/vinifmor/bauh/releases') - - if releases: - latest = None - - for r in releases: - if not r['draft']: - latest = r - break - - if latest and latest.get('tag_name'): - notifications_dir = '{}/updates'.format(CACHE_PATH) - release_file = '{}/{}'.format(notifications_dir, latest['tag_name']) - if os.path.exists(release_file): - self.logger.info("Release {} already notified".format(latest['tag_name'])) - elif latest['tag_name'] > __version__: - try: - Path(notifications_dir).mkdir(parents=True, exist_ok=True) - with open(release_file, 'w+') as f: - f.write('') - except: - self.logger.error("An error occurred while trying to create the update notification file: {}".format(release_file)) - - return self.i18n['warning.update_available'].format(bold(__app_name__), bold(latest['tag_name']), link(latest.get('html_url', '?'))) - else: - self.logger.info("No updates available") - else: - self.logger.warning("No official release found") - else: - self.logger.warning("No releases returned from the GitHub API") - except: - self.logger.error("An error occurred while trying to retrieve the current releases") - def list_warnings(self, internet_available: bool = None) -> List[str]: warnings = [] int_available = internet.is_available() if int_available: - updates_msg = self._check_for_updates() + updates_msg = check_for_update(self.logger, self.http_client, self.i18n) if updates_msg: warnings.append(updates_msg) diff --git a/bauh/view/core/update.py b/bauh/view/core/update.py new file mode 100644 index 00000000..dfebba4c --- /dev/null +++ b/bauh/view/core/update.py @@ -0,0 +1,57 @@ +import logging +import os +from pathlib import Path + +from bauh import __app_name__, __version__ +from bauh.api.constants import CACHE_PATH +from bauh.api.http import HttpClient +from bauh.commons.html import bold, link +from bauh.view.util.translation import I18n + + +def check_for_update(logger: logging.Logger, http_client: HttpClient, i18n: I18n, tray: bool = False) -> str: + """ + :param logger: + :param http_client: + :param i18n: + :param file_prefix: notification file prefix + :return: bauh update warning string or 'None' if no update is available + """ + logger.info("Checking for updates") + + try: + releases = http_client.get_json('https://api.github.com/repos/vinifmor/bauh/releases') + + if releases: + latest = None + + for r in releases: + if not r['draft']: + latest = r + break + + if latest and latest.get('tag_name'): + notifications_dir = '{}/updates'.format(CACHE_PATH) + release_file = '{}/{}{}'.format(notifications_dir, '' if not tray else 'tray_', latest['tag_name']) + if os.path.exists(release_file): + logger.info("Release {} already notified".format(latest['tag_name'])) + elif latest['tag_name'] > __version__: + try: + Path(notifications_dir).mkdir(parents=True, exist_ok=True) + with open(release_file, 'w+') as f: + f.write('') + except: + logger.error("An error occurred while trying to create the update notification file: {}".format(release_file)) + + if tray: + return i18n['tray.warning.update_available'].format(__app_name__, latest['tag_name']) + else: + return i18n['warning.update_available'].format(bold(__app_name__), bold(latest['tag_name']), link(latest.get('html_url', '?'))) + else: + logger.info("No updates available") + else: + logger.warning("No official release found") + else: + logger.warning("No releases returned from the GitHub API") + except: + logger.error("An error occurred while trying to retrieve the current releases") diff --git a/bauh/view/qt/systray.py b/bauh/view/qt/systray.py index 2ecfa30d..c0a80600 100755 --- a/bauh/view/qt/systray.py +++ b/bauh/view/qt/systray.py @@ -15,12 +15,15 @@ from PyQt5.QtWidgets import QSystemTrayIcon, QMenu from bauh import __app_name__, ROOT_DIR from bauh.api.abstract.model import PackageUpdate +from bauh.api.http import HttpClient from bauh.commons.system import run_cmd from bauh.context import generate_i18n from bauh.view.core.tray_client import TRAY_CHECK_FILE +from bauh.view.core.update import check_for_update from bauh.view.qt.about import AboutDialog from bauh.view.qt.view_utils import load_resource_icon from bauh.view.util import util, resource +from bauh.view.util.translation import I18n CLI_PATH = '{}/bin/bauh-cli'.format(sys.exec_prefix) @@ -78,6 +81,25 @@ class UpdateCheck(QThread): self._notify_updates() +class AppUpdateCheck(Thread): + + def __init__(self, http_client: HttpClient, logger: logging.Logger, i18n: I18n, interval: int = 300): + super(AppUpdateCheck, self).__init__(daemon=True) + self.interval = interval + self.http_client = http_client + self.logger = logger + self.i18n = i18n + + def run(self): + while True: + update_msg = check_for_update(http_client=self.http_client, logger=self.logger, i18n=self.i18n, tray=True) + + if update_msg: + util.notify_user(msg=update_msg) + + time.sleep(self.interval) + + class TrayIcon(QSystemTrayIcon): def __init__(self, config: dict, screen_size: QSize, logger: logging.Logger, manage_process: Popen = None, settings_process: Popen = None): @@ -87,6 +109,7 @@ class TrayIcon(QSystemTrayIcon): self.manage_process = manage_process self.settings_process = settings_process self.logger = logger + self.http_client = HttpClient(logger=logger) if config['ui']['tray']['default_icon']: self.icon_default = QIcon(config['ui']['tray']['default_icon']) @@ -135,6 +158,9 @@ class TrayIcon(QSystemTrayIcon): self.recheck_thread.signal.connect(self.notify_updates) self.recheck_thread.start() + self.update_thread = AppUpdateCheck(http_client=self.http_client, logger=self.logger, i18n=self.i18n) + self.update_thread.start() + self.last_updates = set() self.update_notification = bool(config['system']['notifications']) self.lock_notify = Lock() diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca index 75cc15a4..15118223 100644 --- a/bauh/view/resources/locale/ca +++ b/bauh/view/resources/locale/ca @@ -371,7 +371,7 @@ version.unknown=no informat version.updated=actualitzada view.components.file_chooser.placeholder=Feu clic aquí per seleccionar warning=avís -warning.update_available=There is a new {} update available ({}). Checkout the news at {}. +warning.update_available=There is a new {} version available ({}). Checkout the news at {}. welcome=us donem la benvinguda window_manage.input_search.placeholder=Cerca window_manage.input_search.tooltip=Escriviu i premeu Intro per a cercar aplicacions diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index 2192a5fa..dffe1dbe 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -370,7 +370,7 @@ version.unknown=unbekannt version.updated=geupdated view.components.file_chooser.placeholder=Auswählen warning=Warnung -warning.update_available=There is a new {} update available ({}). Checkout the news at {}. +warning.update_available=There is a new {} version available ({}). Checkout the news at {}. welcome=Willkommen window_manage.input_search.placeholder=Suchbegriff window_manage.input_search.tooltip=Suchbegriff eingeben und Enter drücken, um zu suchen diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index bf9dc100..cbe2ced0 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -371,7 +371,7 @@ version=version view.components.file_chooser.placeholder=Click here to select warning=warning welcome=welcome -warning.update_available=There is a new {} update available ({}). Checkout the news at {}. +warning.update_available=There is a new {} version available ({}). Checkout the news at {}. window_manage.input_search.placeholder=Search window_manage.input_search.tooltip=Type and press ENTER to search for applications yes=yes \ No newline at end of file diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es index c65d4b92..fabd5d18 100644 --- a/bauh/view/resources/locale/es +++ b/bauh/view/resources/locale/es @@ -371,7 +371,7 @@ version.unknown=versión no informada version.updated=actualizada view.components.file_chooser.placeholder=Pulse aquí para seleccionar warning=aviso -warning.update_available=Hay una nueva actualización de {} disponible ({}). Vea las novedades en {}. +warning.update_available=Hay una nueva versión de {} disponible ({}). Vea las novedades en {}. welcome=bienvenido window_manage.input_search.placeholder=Buscar window_manage.input_search.tooltip=Escriba y oprima Intro para buscar aplicaciones diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index 08db453a..1a776190 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -373,7 +373,7 @@ version.unknown=non informato version.updated=aggiornata view.components.file_chooser.placeholder=Fai clic qui per selezionare warning=Avviso -warning.update_available=There is a new {} update available ({}). Checkout the news at {}. +warning.update_available=There is a new {} version available ({}). Checkout the news at {}. welcome=benvenuto window_manage.input_search.placeholder=Cerca window_manage.input_search.tooltip=Digitare e premere INVIO per cercare applicazioni diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt index cccb1e1d..d5806ad6 100644 --- a/bauh/view/resources/locale/pt +++ b/bauh/view/resources/locale/pt @@ -370,7 +370,7 @@ version.updated=atualizada version=versão view.components.file_chooser.placeholder=Clique aqui para selecionar warning=aviso -warning.update_available=Há uma nova atualização do {} disponível ({}). Confira as novidades em {} +warning.update_available=Há uma nova versão do {} disponível ({}). Confira as novidades em {} welcome=bem vindo window_manage.input_search.placeholder=Buscar window_manage.input_search.tooltip=Digite e pressione ENTER para buscar aplicativos diff --git a/bauh/view/resources/locale/ru b/bauh/view/resources/locale/ru index cf580b18..e7fdd5ee 100644 --- a/bauh/view/resources/locale/ru +++ b/bauh/view/resources/locale/ru @@ -370,7 +370,7 @@ version.unknown=не сообщать version.updated=Обновленная view.components.file_chooser.placeholder=Нажмите здесь, чтобы выбрать warning=Предупреждение -warning.update_available=There is a new {} update available ({}). Checkout the news at {}. +warning.update_available=There is a new {} version available ({}). Checkout the news at {}. welcome=Добро пожаловать! window_manage.input_search.placeholder=Поиск window_manage.input_search.tooltip=Введите и нажмите ENTER для поиска приложений diff --git a/bauh/view/resources/locale/tray/ca b/bauh/view/resources/locale/tray/ca index 7997de31..954bba3a 100644 --- a/bauh/view/resources/locale/tray/ca +++ b/bauh/view/resources/locale/tray/ca @@ -4,4 +4,5 @@ tray.action.about=Quant a tray.action.refreshing=Refrescant tray.settings=configuració notification.update={} actualització disponible -notification.updates={} actualitzacions disponibles \ No newline at end of file +notification.updates={} actualitzacions disponibles +tray.warning.update_available=New {} version available ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/de b/bauh/view/resources/locale/tray/de index c22e50e8..abbf93b4 100644 --- a/bauh/view/resources/locale/tray/de +++ b/bauh/view/resources/locale/tray/de @@ -4,4 +4,5 @@ tray.action.about=Über tray.action.refreshing=Aktualisieren tray.settings=Einstellungen notification.update={} Update verfügbar -notification.updates={} Updates verfügbar \ No newline at end of file +notification.updates={} Updates verfügbar +tray.warning.update_available=New {} version available ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/en b/bauh/view/resources/locale/tray/en index 217cccad..a213b543 100644 --- a/bauh/view/resources/locale/tray/en +++ b/bauh/view/resources/locale/tray/en @@ -4,4 +4,5 @@ tray.action.about=About tray.action.refreshing=Refreshing tray.settings=Settings notification.update={} available update -notification.updates={} available updates \ No newline at end of file +notification.updates={} available updates +tray.warning.update_available=New {} version available ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/es b/bauh/view/resources/locale/tray/es index 0d4c2301..fc3f30b5 100644 --- a/bauh/view/resources/locale/tray/es +++ b/bauh/view/resources/locale/tray/es @@ -4,4 +4,5 @@ tray.action.about=Acerca de tray.action.refreshing=Recargando tray.settings=configuraciones notification.update={} actualización disponible -notification.updates={} actualizaciones disponibles \ No newline at end of file +notification.updates={} actualizaciones disponibles +tray.warning.update_available=Nueva versión de {} disponible ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/it b/bauh/view/resources/locale/tray/it index 31d8d5cf..db7d675f 100644 --- a/bauh/view/resources/locale/tray/it +++ b/bauh/view/resources/locale/tray/it @@ -4,4 +4,5 @@ tray.action.about=Informazioni su tray.action.refreshing=Refreshing tray.settings=impostazioni notification.update={} aggiornamento disponibile -notification.updates={} aggiornamenti disponibile \ No newline at end of file +notification.updates={} aggiornamenti disponibile +tray.warning.update_available=New {} version available ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/pt b/bauh/view/resources/locale/tray/pt index 9983dfe6..bd1a71c4 100644 --- a/bauh/view/resources/locale/tray/pt +++ b/bauh/view/resources/locale/tray/pt @@ -4,4 +4,5 @@ tray.action.about=Sobre tray.action.refreshing=Recarregando tray.settings=Configurações notification.update={} atualização disponível -notification.updates={} atualizações disponíveis \ No newline at end of file +notification.updates={} atualizações disponíveis +tray.warning.update_available=Nova versão do {} disponível ({}) \ No newline at end of file diff --git a/bauh/view/resources/locale/tray/ru b/bauh/view/resources/locale/tray/ru index 10f42800..e1a36fb9 100644 --- a/bauh/view/resources/locale/tray/ru +++ b/bauh/view/resources/locale/tray/ru @@ -4,4 +4,5 @@ tray.action.about=О программе tray.action.refreshing=Обновляется tray.settings=Настройки notification.update={} обновления доступно -notification.updates={} обновлений доступно \ No newline at end of file +notification.updates={} обновлений доступно +tray.warning.update_available=New {} version available ({}) \ No newline at end of file