From 62a1c4fa3bb6eff5e5169d380a9cc0a32df2472e Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 20 May 2022 11:36:47 -0300 Subject: [PATCH] [view] feature: new parameter '--suggestions' to force loading software suggestions after the initialization process --- CHANGELOG.md | 4 ++++ README.md | 1 + bauh/app.py | 3 +++ bauh/app_args.py | 2 ++ bauh/manage.py | 7 +++++-- bauh/view/core/controller.py | 10 +++++++--- bauh/view/qt/prepare.py | 7 +++++-- bauh/view/qt/window.py | 16 +++++++++------- 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccd41229..ea89e31c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.10.3] +### Features +- General + - new parameter `--suggestions`: forces loading software suggestions after the initialization process [#260](https://github.com/vinifmor/bauh/issues/260) + ### Improvements - General - preventing command injection through the search mechanism [#266](https://github.com/vinifmor/bauh/issues/266) diff --git a/README.md b/README.md index 72f213f4..555daf4c 100644 --- a/README.md +++ b/README.md @@ -398,6 +398,7 @@ You can change some application settings via environment variables or arguments - `--reset`: it cleans all configurations and cached data stored in the HOME directory. - `--logs`: it enables logs (for debugging purposes). - `--offline`: it assumes the internet connection is off. +- `--suggestions`: it forces loading software suggestions after the initialization process. ##### Configuration file (**~/.config/bauh/config.yml**) diff --git a/bauh/app.py b/bauh/app.py index 5ee5bcd2..68800f9c 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -53,6 +53,9 @@ def main(tray: bool = False): QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) + if bool(args.suggestions): + logger.info("Forcing loading software suggestions after the initialization process") + if tray or bool(args.tray): from bauh.tray import new_tray_icon app, widget = new_tray_icon(app_config, logger) diff --git a/bauh/app_args.py b/bauh/app_args.py index b6c1c386..a9a74792 100644 --- a/bauh/app_args.py +++ b/bauh/app_args.py @@ -9,6 +9,8 @@ def read() -> Namespace: parser.add_argument('-v', '--version', action='version', version='%(prog)s {}'.format(__version__)) parser.add_argument('--logs', action="store_true", help='It activates {} logs.'.format(__app_name__)) parser.add_argument('--offline', action="store_true", help='It assumes the internet connection is off') + parser.add_argument('--suggestions', action="store_true", + help='It forces loading software suggestions after the initialization process') exclusive_args = parser.add_mutually_exclusive_group() exclusive_args.add_argument('--tray', action="store_true", help='If {} should be attached to the system tray.'.format(__app_name__)) diff --git a/bauh/manage.py b/bauh/manage.py index f7d3af58..9e9bddf9 100644 --- a/bauh/manage.py +++ b/bauh/manage.py @@ -57,7 +57,8 @@ def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logg util.clean_app_files(managers) exit(0) - manager = GenericSoftwareManager(managers, context=context, config=app_config) + force_suggestions = bool(app_args.suggestions) + manager = GenericSoftwareManager(managers, context=context, config=app_config, force_suggestions=force_suggestions) app = new_qt_application(app_config=app_config, logger=logger, quit_on_last_closed=True) @@ -78,6 +79,7 @@ def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logg context=context, http_client=http_client, icon=util.get_default_icon()[1], + force_suggestions=force_suggestions, logger=logger) prepare = PreparePanel(screen_size=screen_size, @@ -85,7 +87,8 @@ def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logg manager=manager, i18n=i18n, manage_window=manage_window, - app_config=app_config) + app_config=app_config, + force_suggestions=force_suggestions) cache_cleaner.start() return app, prepare diff --git a/bauh/view/core/controller.py b/bauh/view/core/controller.py index 74a2711a..3e2733ed 100755 --- a/bauh/view/core/controller.py +++ b/bauh/view/core/controller.py @@ -39,7 +39,9 @@ class GenericUpgradeRequirements(UpgradeRequirements): class GenericSoftwareManager(SoftwareManager, SettingsController): - def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: dict): + def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: dict, + force_suggestions: bool = False): + super(GenericSoftwareManager, self).__init__(context=context) self.managers = managers self.map = {t: m for m in self.managers for t in m.get_managed_types()} @@ -56,6 +58,7 @@ class GenericSoftwareManager(SoftwareManager, SettingsController): self.configman = CoreConfigManager() self._action_reset: Optional[CustomSoftwareAction] = None self._dynamic_extra_actions: Optional[Dict[CustomSoftwareAction, Callable[[dict], bool]]] = None + self.force_suggestions = force_suggestions @property def dynamic_extra_actions(self) -> Dict[CustomSoftwareAction, Callable[[dict], bool]]: @@ -488,11 +491,12 @@ class GenericSoftwareManager(SoftwareManager, SettingsController): suggestions.extend(man_sugs) def list_suggestions(self, limit: int, filter_installed: bool) -> List[PackageSuggestion]: - if bool(self.config['suggestions']['enabled']): + if self.force_suggestions or bool(self.config['suggestions']['enabled']): if self.managers and self.context.is_internet_available(): suggestions, threads = [], [] for man in self.managers: - t = Thread(target=self._fill_suggestions, args=(suggestions, man, int(self.config['suggestions']['by_type']), filter_installed)) + t = Thread(target=self._fill_suggestions, + args=(suggestions, man, int(self.config['suggestions']['by_type']), filter_installed)) t.start() threads.append(t) diff --git a/bauh/view/qt/prepare.py b/bauh/view/qt/prepare.py index 71ee58b7..b93ee42e 100644 --- a/bauh/view/qt/prepare.py +++ b/bauh/view/qt/prepare.py @@ -146,7 +146,7 @@ class PreparePanel(QWidget, TaskManager): signal_password_response = pyqtSignal(bool, str) def __init__(self, context: ApplicationContext, manager: SoftwareManager, screen_size: QSize, - i18n: I18n, manage_window: QWidget, app_config: dict): + i18n: I18n, manage_window: QWidget, app_config: dict, force_suggestions: bool = False): super(PreparePanel, self).__init__(flags=Qt.CustomizeWindowHint | Qt.WindowTitleHint) self.i18n = i18n self.context = context @@ -165,6 +165,7 @@ class PreparePanel(QWidget, TaskManager): self.ftasks = 0 self.started_at = None self.self_close = False + self.force_suggestions = force_suggestions self.prepare_thread = Prepare(self.context, manager, self.i18n) self.prepare_thread.signal_register.connect(self.register_task) @@ -438,7 +439,9 @@ class PreparePanel(QWidget, TaskManager): if self.isVisible(): self.manage_window.show() - if self.app_config['boot']['load_apps']: + if self.force_suggestions: + self.manage_window.begin_load_suggestions(filter_installed=True) + elif self.app_config['boot']['load_apps']: self.manage_window.begin_refresh_packages() else: self.manage_window.load_without_packages() diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index db96405f..ba03d35c 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -97,7 +97,8 @@ class ManageWindow(QWidget): signal_stop_notifying = pyqtSignal() def __init__(self, i18n: I18n, icon_cache: MemoryCache, manager: SoftwareManager, screen_size: QSize, config: dict, - context: ApplicationContext, http_client: HttpClient, logger: logging.Logger, icon: QIcon): + context: ApplicationContext, http_client: HttpClient, logger: logging.Logger, icon: QIcon, + force_suggestions: bool = False): super(ManageWindow, self).__init__() self.setObjectName('manage_window') self.comp_manager = QtComponentsManager() @@ -375,8 +376,11 @@ class ManageWindow(QWidget): self.container_bottom.layout().addWidget(new_spacer()) - if config['suggestions']['enabled']: - bt_sugs = IconButton(action=lambda: self._begin_load_suggestions(filter_installed=True), + self.load_suggestions = force_suggestions or bool(config['suggestions']['enabled']) + self.suggestions_requested = False + + if self.load_suggestions: + bt_sugs = IconButton(action=lambda: self.begin_load_suggestions(filter_installed=True), i18n=i18n, tooltip=self.i18n['manage_window.bt.suggestions.tooltip']) bt_sugs.setObjectName('suggestions') @@ -442,8 +446,6 @@ class ManageWindow(QWidget): self.types_changed = False self.dialog_about = None - self.load_suggestions = bool(config['suggestions']['enabled']) - self.suggestions_requested = False self.first_refresh = True self.thread_warnings = ListWarnings(man=manager, i18n=i18n) @@ -739,7 +741,7 @@ class ManageWindow(QWidget): self._handle_console_option(False) self._finish_refresh_packages({'installed': None, 'types': None}, as_installed=False) - def _begin_load_suggestions(self, filter_installed: bool): + def begin_load_suggestions(self, filter_installed: bool): self.search_bar.clear() self._begin_action(self.i18n['manage_window.status.suggestions']) self._handle_console_option(False) @@ -972,7 +974,7 @@ class ManageWindow(QWidget): if as_installed: self.pkgs_installed = pkgs_info['pkgs'] - self._begin_load_suggestions(filter_installed=False) + self.begin_load_suggestions(filter_installed=False) self.load_suggestions = False return False else: