From 6b8ee684633ffac200b1290b7589c92735579c91 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sat, 27 Jul 2019 21:48:28 -0300 Subject: [PATCH] showing a warning dialog when the application starts and **snapd** is unavailable --- CHANGELOG.md | 2 ++ fpakman/app.py | 11 +++++++++-- fpakman/core/controller.py | 22 +++++++++++++++++++++- fpakman/core/flatpak/controller.py | 8 +++++--- fpakman/core/snap/controller.py | 8 ++++++-- fpakman/core/snap/snap.py | 4 ++-- fpakman/resources/locale/en | 4 +++- fpakman/resources/locale/es | 4 +++- fpakman/resources/locale/pt | 4 +++- fpakman/view/qt/dialog.py | 14 +++++++++++++- 10 files changed, 67 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce96f4db..45feaefd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ 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.4.2] +### Improvements +- showing a warning dialog when the application starts and **snapd** is unavailable ### Fixes: - [Snaps read index error](https://github.com/vinifmor/fpakman/issues/30) diff --git a/fpakman/app.py b/fpakman/app.py index 9a855b19..ed8ad245 100755 --- a/fpakman/app.py +++ b/fpakman/app.py @@ -21,6 +21,7 @@ from fpakman.core.snap.model import SnapApplication from fpakman.util import util from fpakman.util.cache import Cache from fpakman.util.memory import CacheCleaner +from fpakman.view.qt import dialog from fpakman.view.qt.systray import TrayIcon @@ -85,7 +86,7 @@ managers = [] if args.flatpak: flatpak_api_cache = Cache(expiration_time=args.cache_exp) cache_map[FlatpakApplication] = flatpak_api_cache - managers.append(FlatpakManager(app_args=args, api_cache=flatpak_api_cache, disk_cache=args.disk_cache, http_session=http_session)) + managers.append(FlatpakManager(app_args=args, api_cache=flatpak_api_cache, disk_cache=args.disk_cache, http_session=http_session, locale_keys=locale_keys)) caches.append(flatpak_api_cache) if args.disk_cache: @@ -94,7 +95,7 @@ if args.flatpak: if args.snap: snap_api_cache = Cache(expiration_time=args.cache_exp) cache_map[SnapApplication] = snap_api_cache - managers.append(SnapManager(app_args=args, disk_cache=args.disk_cache, api_cache=snap_api_cache, http_session=http_session)) + managers.append(SnapManager(app_args=args, disk_cache=args.disk_cache, api_cache=snap_api_cache, http_session=http_session, locale_keys=locale_keys)) caches.append(snap_api_cache) if args.disk_cache: @@ -124,4 +125,10 @@ trayIcon.show() CacheCleaner(caches).start() +warnings = manager.list_warnings() + +if warnings: + for warning in warnings: + dialog.show_warning(title=locale_keys['warning'].capitalize(), body=warning) + sys.exit(app.exec_()) diff --git a/fpakman/core/controller.py b/fpakman/core/controller.py index cea20876..e188337d 100755 --- a/fpakman/core/controller.py +++ b/fpakman/core/controller.py @@ -9,8 +9,9 @@ from fpakman.core.system import FpakmanProcess class ApplicationManager(ABC): - def __init__(self, app_args): + def __init__(self, app_args, locale_keys: dict): self.app_args = app_args + self.locale_keys = locale_keys @abstractmethod def search(self, word: str, disk_loader: DiskCacheLoader) -> Dict[str, List[Application]]: @@ -84,6 +85,10 @@ class ApplicationManager(ABC): def list_updates(self) -> List[ApplicationUpdate]: pass + @abstractmethod + def list_warnings(self) -> List[str]: + pass + class GenericApplicationManager(ApplicationManager): @@ -266,3 +271,18 @@ class GenericApplicationManager(ApplicationManager): updates.extend(man.list_updates()) return updates + + def list_warnings(self) -> List[str]: + if self.managers: + warnings = None + + for man in self.managers: + man_warnings = man.list_warnings() + + if man_warnings: + if warnings is None: + warnings = [] + + warnings.extend(man_warnings) + + return warnings diff --git a/fpakman/core/flatpak/controller.py b/fpakman/core/flatpak/controller.py index f0298e25..72f04040 100644 --- a/fpakman/core/flatpak/controller.py +++ b/fpakman/core/flatpak/controller.py @@ -17,8 +17,8 @@ from fpakman.util.cache import Cache class FlatpakManager(ApplicationManager): - def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session): - super(FlatpakManager, self).__init__(app_args=app_args) + def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session, locale_keys: dict): + super(FlatpakManager, self).__init__(app_args=app_args, locale_keys=locale_keys) self.api_cache = api_cache self.http_session = http_session self.disk_cache = disk_cache @@ -176,5 +176,7 @@ class FlatpakManager(ApplicationManager): updates.append(ApplicationUpdate(app_id='{}:{}'.format(app['id'], app['branch']), app_type='flatpak', version=app.get('version'))) - return updates + + def list_warnings(self) -> List[str]: + return None diff --git a/fpakman/core/snap/controller.py b/fpakman/core/snap/controller.py index eaf89496..9052ef48 100644 --- a/fpakman/core/snap/controller.py +++ b/fpakman/core/snap/controller.py @@ -17,8 +17,8 @@ from fpakman.util.cache import Cache class SnapManager(ApplicationManager): - def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session): - super(SnapManager, self).__init__(app_args=app_args) + def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session, locale_keys: dict): + super(SnapManager, self).__init__(app_args=app_args, locale_keys=locale_keys) self.api_cache = api_cache self.http_session = http_session self.disk_cache = disk_cache @@ -133,3 +133,7 @@ class SnapManager(ApplicationManager): def list_updates(self) -> List[ApplicationUpdate]: return [] + + def list_warnings(self) -> List[str]: + if snap.get_snapd_version() == 'unavailable': + return [self.locale_keys['snap.notification.snapd_unavailable']] diff --git a/fpakman/core/snap/snap.py b/fpakman/core/snap/snap.py index 5b0eb7d1..af01c5ac 100644 --- a/fpakman/core/snap/snap.py +++ b/fpakman/core/snap/snap.py @@ -9,7 +9,7 @@ BASE_CMD = 'snap' def is_installed(): version = get_snapd_version() - return False if version is None else True + return False if version is None or version == 'unavailable' else True def get_version(): @@ -27,7 +27,7 @@ def get_snapd_version(): if lines and len(lines) >= 2: version = lines[1].split(' ')[-1].strip() - return version if version and version.lower() != 'unavailable' else None + return version.lower() if version else None else: return None diff --git a/fpakman/resources/locale/en b/fpakman/resources/locale/en index 657d1618..26bb313e 100644 --- a/fpakman/resources/locale/en +++ b/fpakman/resources/locale/en @@ -99,4 +99,6 @@ version.installed=installed version version.latest=latest version version.installed_outdated=the installed version is outdated version.unknown=not informed -app.name=application name \ No newline at end of file +app.name=application name +warning=warning +snap.notification.snapd_unavailable=snapd seems not to be enabled. snap packages will not be available. \ No newline at end of file diff --git a/fpakman/resources/locale/es b/fpakman/resources/locale/es index 7e1036d4..a4c4b0c8 100644 --- a/fpakman/resources/locale/es +++ b/fpakman/resources/locale/es @@ -100,4 +100,6 @@ version.installed=versión instalada version.latest=versión más reciente version.installed_outdated=la versión instalada está desactualizada version.unknown=versión no informada -app.name=nombre del aplicativo \ No newline at end of file +app.name=nombre del aplicativo +warning=aviso +snap.notification.snapd_unavailable=snapd no parece estar habilitado. los paquetes snap estarán indisponibles. \ No newline at end of file diff --git a/fpakman/resources/locale/pt b/fpakman/resources/locale/pt index 82b0ee6a..13c49288 100644 --- a/fpakman/resources/locale/pt +++ b/fpakman/resources/locale/pt @@ -100,4 +100,6 @@ version.installed=versão instalada version.latest=versão mais recente version.installed_outdated=a versão instalada está desatualizada version.unknown=versão não informada -app.name=nome do aplicativo \ No newline at end of file +app.name=nome do aplicativo +warning=aviso +snap.notification.snapd_unavailable=snapd não parece estar habilitado. os pacotes snap estarão indisponíveis. \ No newline at end of file diff --git a/fpakman/view/qt/dialog.py b/fpakman/view/qt/dialog.py index 7d3e27e2..f5cfbb09 100644 --- a/fpakman/view/qt/dialog.py +++ b/fpakman/view/qt/dialog.py @@ -1,5 +1,5 @@ from PyQt5.QtGui import QIcon -from PyQt5.QtWidgets import QMessageBox, QSizePolicy +from PyQt5.QtWidgets import QMessageBox from fpakman.core import resource @@ -16,6 +16,18 @@ def show_error(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img error_msg.exec_() +def show_warning(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))): + msg = QMessageBox() + msg.setIcon(QMessageBox.Warning) + msg.setWindowTitle(title) + msg.setText(body) + + if icon: + msg.setWindowIcon(icon) + + msg.exec_() + + def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))): dialog_confirmation = QMessageBox() dialog_confirmation.setIcon(QMessageBox.Question)