mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 04:44:15 +02:00
[appimage] refactoring: instantiating package custom actions on demand
This commit is contained in:
@@ -79,13 +79,6 @@ class AppImageManager(SoftwareManager):
|
|||||||
self.file_downloader = context.file_downloader
|
self.file_downloader = context.file_downloader
|
||||||
self.configman = AppImageConfigManager()
|
self.configman = AppImageConfigManager()
|
||||||
self._custom_actions: Optional[Iterable[CustomSoftwareAction]] = None
|
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:
|
def install_file(self, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||||
file_chooser = FileChooserComponent(label=self.i18n['file'].capitalize(),
|
file_chooser = FileChooserComponent(label=self.i18n['file'].capitalize(),
|
||||||
@@ -199,7 +192,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
|
|
||||||
idx = 0
|
idx = 0
|
||||||
for r in cursor.fetchall():
|
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)
|
not_installed.append(app)
|
||||||
found_map[self._gen_app_key(app)] = {'app': app, 'idx': idx}
|
found_map[self._gen_app_key(app)] = {'app': app, 'idx': idx}
|
||||||
idx += 1
|
idx += 1
|
||||||
@@ -251,7 +244,7 @@ class AppImageManager(SoftwareManager):
|
|||||||
for path in installed:
|
for path in installed:
|
||||||
if path:
|
if path:
|
||||||
with open(path) as f:
|
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
|
app.icon_url = app.icon_path
|
||||||
|
|
||||||
installed_apps.append(app)
|
installed_apps.append(app)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from io import StringIO
|
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.api.abstract.model import SoftwarePackage, CustomSoftwareAction
|
||||||
from bauh.commons import resource
|
from bauh.commons import resource
|
||||||
@@ -15,11 +15,26 @@ CACHED_ATTRS = {'name', 'description', 'version', 'url_download', 'author', 'lic
|
|||||||
|
|
||||||
class AppImage(SoftwarePackage):
|
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,
|
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,
|
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,
|
categories=None, icon_path: str = None, installed: bool = False,
|
||||||
url_download_latest_version: str = None, local_file_path: str = None, imported: 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):
|
symlink: str = None, **kwargs):
|
||||||
super(AppImage, self).__init__(id=name, name=name, version=version, latest_version=version,
|
super(AppImage, self).__init__(id=name, name=name, version=version, latest_version=version,
|
||||||
icon_url=url_icon, license=license, description=description,
|
icon_url=url_icon, license=license, description=description,
|
||||||
@@ -36,7 +51,6 @@ class AppImage(SoftwarePackage):
|
|||||||
self.imported = imported
|
self.imported = imported
|
||||||
self.i18n = i18n
|
self.i18n = i18n
|
||||||
self.install_dir = install_dir
|
self.install_dir = install_dir
|
||||||
self.custom_actions = custom_actions
|
|
||||||
self.updates_ignored = updates_ignored
|
self.updates_ignored = updates_ignored
|
||||||
self.symlink = symlink
|
self.symlink = symlink
|
||||||
|
|
||||||
@@ -109,8 +123,8 @@ class AppImage(SoftwarePackage):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def get_custom_actions(self) -> Optional[Iterable[CustomSoftwareAction]]:
|
def get_custom_actions(self) -> Optional[Iterable[CustomSoftwareAction]]:
|
||||||
if self.imported:
|
if self.installed and self.imported:
|
||||||
return self.custom_actions
|
return self.actions_local_installation()
|
||||||
|
|
||||||
def supports_backup(self) -> bool:
|
def supports_backup(self) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user