[view] feature: new parameter '--suggestions' to force loading software suggestions after the initialization process

This commit is contained in:
Vinicius Moreira
2022-05-20 11:36:47 -03:00
parent cefab90052
commit 62a1c4fa3b
8 changed files with 36 additions and 14 deletions

View File

@@ -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)

View File

@@ -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()

View File

@@ -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: