[appimage] refactoring: instantiating package custom actions on demand

This commit is contained in:
Vinicius Moreira
2022-02-25 15:37:09 -03:00
parent 0245a3f605
commit 8ffcb492eb
2 changed files with 21 additions and 14 deletions

View File

@@ -79,13 +79,6 @@ class AppImageManager(SoftwareManager):
self.file_downloader = context.file_downloader
self.configman = AppImageConfigManager()
self._custom_actions: Optional[Iterable[CustomSoftwareAction]] = None
self.custom_app_actions = (CustomSoftwareAction(i18n_label_key='appimage.custom_action.manual_update',
i18n_status_key='appimage.custom_action.manual_update.status',
i18n_description_key='appimage.custom_action.manual_update.desc',
manager_method='update_file',
requires_root=False,
icon_path=resource.get_path('img/upgrade.svg', ROOT_DIR),
requires_confirmation=False),)
def install_file(self, root_password: str, watcher: ProcessWatcher) -> bool:
file_chooser = FileChooserComponent(label=self.i18n['file'].capitalize(),
@@ -199,7 +192,7 @@ class AppImageManager(SoftwareManager):
idx = 0
for r in cursor.fetchall():
app = AppImage(*r, i18n=self.i18n, custom_actions=self.custom_app_actions)
app = AppImage(*r, i18n=self.i18n)
not_installed.append(app)
found_map[self._gen_app_key(app)] = {'app': app, 'idx': idx}
idx += 1
@@ -251,7 +244,7 @@ class AppImageManager(SoftwareManager):
for path in installed:
if path:
with open(path) as f:
app = AppImage(installed=True, i18n=self.i18n, custom_actions=self.custom_app_actions, **json.loads(f.read()))
app = AppImage(installed=True, i18n=self.i18n, **json.loads(f.read()))
app.icon_url = app.icon_path
installed_apps.append(app)

View File

@@ -1,6 +1,6 @@
import re
from io import StringIO
from typing import List, Optional, Iterable
from typing import Optional, Iterable, Tuple
from bauh.api.abstract.model import SoftwarePackage, CustomSoftwareAction
from bauh.commons import resource
@@ -15,11 +15,26 @@ CACHED_ATTRS = {'name', 'description', 'version', 'url_download', 'author', 'lic
class AppImage(SoftwarePackage):
__actions_local_installation: Optional[Tuple[CustomSoftwareAction, ...]] = None
@classmethod
def actions_local_installation(cls) -> Tuple[CustomSoftwareAction, ...]:
if cls.__actions_local_installation is None:
cls.__actions_local_installation = (CustomSoftwareAction(i18n_label_key='appimage.custom_action.manual_update',
i18n_status_key='appimage.custom_action.manual_update.status',
i18n_description_key='appimage.custom_action.manual_update.desc',
manager_method='update_file',
requires_root=False,
icon_path=resource.get_path('img/upgrade.svg', ROOT_DIR),
requires_confirmation=False),)
return cls.__actions_local_installation
def __init__(self, name: str = None, description: str = None, github: str = None, source: str = None, version: str = None,
url_download: str = None, url_icon: str = None, url_screenshot: str = None, license: str = None, author: str = None,
categories=None, icon_path: str = None, installed: bool = False,
url_download_latest_version: str = None, local_file_path: str = None, imported: bool = False,
i18n: I18n = None, install_dir: str = None, custom_actions: Optional[Iterable[CustomSoftwareAction]] = None, updates_ignored: bool = False,
i18n: I18n = None, install_dir: str = None, updates_ignored: bool = False,
symlink: str = None, **kwargs):
super(AppImage, self).__init__(id=name, name=name, version=version, latest_version=version,
icon_url=url_icon, license=license, description=description,
@@ -36,7 +51,6 @@ class AppImage(SoftwarePackage):
self.imported = imported
self.i18n = i18n
self.install_dir = install_dir
self.custom_actions = custom_actions
self.updates_ignored = updates_ignored
self.symlink = symlink
@@ -109,8 +123,8 @@ class AppImage(SoftwarePackage):
return self.name
def get_custom_actions(self) -> Optional[Iterable[CustomSoftwareAction]]:
if self.imported:
return self.custom_actions
if self.installed and self.imported:
return self.actions_local_installation()
def supports_backup(self) -> bool:
return False