mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 17:54:14 +02:00
[wgem] using the suggestions custom icon to install the application
This commit is contained in:
@@ -465,6 +465,27 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
confirmation_label=self.i18n['continue'].capitalize(),
|
confirmation_label=self.i18n['continue'].capitalize(),
|
||||||
deny_label=self.i18n['cancel'].capitalize())
|
deny_label=self.i18n['cancel'].capitalize())
|
||||||
|
|
||||||
|
def _download_suggestion_icon(self, pkg: WebApplication, app_dir: str) -> Tuple[str, bytes]:
|
||||||
|
try:
|
||||||
|
if self.http_client.exists(pkg.icon_url):
|
||||||
|
icon_path = '{}/{}'.format(app_dir, pkg.icon_url.split('/')[-1])
|
||||||
|
|
||||||
|
try:
|
||||||
|
res = self.http_client.get(pkg.icon_url)
|
||||||
|
if not res:
|
||||||
|
self.logger.info('Could not download the icon {}'.format(pkg.icon_url))
|
||||||
|
else:
|
||||||
|
return icon_path, res.content
|
||||||
|
except:
|
||||||
|
self.logger.error("An exception has happened when downloading {}".format(pkg.icon_url))
|
||||||
|
traceback.print_exc()
|
||||||
|
else:
|
||||||
|
self.logger.warning('Could no retrieve the icon {} defined for the suggestion {}'.format(pkg.icon_url, pkg.name))
|
||||||
|
except:
|
||||||
|
self.logger.warning('An exception happened when trying to retrieve the icon {} for the suggestion {}'.format(pkg.icon_url,
|
||||||
|
pkg.name))
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
def install(self, pkg: WebApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
def install(self, pkg: WebApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||||
|
|
||||||
continue_install, install_options = self._ask_install_options(pkg, watcher)
|
continue_install, install_options = self._ask_install_options(pkg, watcher)
|
||||||
@@ -504,6 +525,23 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
watcher.print('Fix found for {}'.format(pkg.url))
|
watcher.print('Fix found for {}'.format(pkg.url))
|
||||||
install_options.append('--inject={}'.format(fix_path))
|
install_options.append('--inject={}'.format(fix_path))
|
||||||
|
|
||||||
|
# if a custom icon is defined for an app suggestion:
|
||||||
|
icon_path, icon_bytes = None, None
|
||||||
|
if pkg.is_suggestion and pkg.icon_url and not {o for o in install_options if o.startswith('--icon')}:
|
||||||
|
download = self._download_suggestion_icon(pkg, app_dir)
|
||||||
|
|
||||||
|
if download and download[1]:
|
||||||
|
icon_path, icon_bytes = download[0], download[1]
|
||||||
|
pkg.custom_icon = icon_path
|
||||||
|
|
||||||
|
# writting the icon in a temporary folder to be used by the nativefier process
|
||||||
|
temp_icon_path = '/tmp/bauh/web/{}'.format(pkg.icon_url.split('/')[-1])
|
||||||
|
install_options.append('--icon={}'.format(temp_icon_path))
|
||||||
|
|
||||||
|
self.logger.info("Writting a temp suggestion icon at {}".format(temp_icon_path))
|
||||||
|
with open(temp_icon_path, 'wb+') as f:
|
||||||
|
f.write(icon_bytes)
|
||||||
|
|
||||||
watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier')))
|
watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier')))
|
||||||
|
|
||||||
electron_version = next((c for c in env_components if c.id == 'electron')).version
|
electron_version = next((c for c in env_components if c.id == 'electron')).version
|
||||||
@@ -540,6 +578,12 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
with open(fix_path, 'w+') as f:
|
with open(fix_path, 'w+') as f:
|
||||||
f.write(fix)
|
f.write(fix)
|
||||||
|
|
||||||
|
# persisting the custom suggestion icon in the defitive directory
|
||||||
|
if icon_bytes:
|
||||||
|
self.logger.info("Writting the final custom suggestion icon at {}".format(icon_path))
|
||||||
|
with open(icon_path, 'wb+') as f:
|
||||||
|
f.write(icon_bytes)
|
||||||
|
|
||||||
pkg.installation_dir = app_dir
|
pkg.installation_dir = app_dir
|
||||||
|
|
||||||
version_path = '{}/version'.format(app_dir)
|
version_path = '{}/version'.format(app_dir)
|
||||||
@@ -660,7 +704,8 @@ class WebApplicationManager(SoftwareManager):
|
|||||||
url=suggestion.get('url'),
|
url=suggestion.get('url'),
|
||||||
icon_url=suggestion.get('icon_url'),
|
icon_url=suggestion.get('icon_url'),
|
||||||
categories=[suggestion['category']] if suggestion.get('category') else None,
|
categories=[suggestion['category']] if suggestion.get('category') else None,
|
||||||
preset_options=suggestion.get('options'))
|
preset_options=suggestion.get('options'),
|
||||||
|
is_suggestion=True)
|
||||||
|
|
||||||
app.set_version(suggestion.get('version'))
|
app.set_version(suggestion.get('version'))
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class WebApplication(SoftwarePackage):
|
|||||||
|
|
||||||
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
|
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
|
||||||
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
|
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
|
||||||
categories: List[str] = None, custom_icon: str = None, preset_options: List[str] = None):
|
categories: List[str] = None, custom_icon: str = None, preset_options: List[str] = None, is_suggestion: bool = False):
|
||||||
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
|
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
|
||||||
icon_url=icon_url, installed=installed, version=version,
|
icon_url=icon_url, installed=installed, version=version,
|
||||||
categories=categories)
|
categories=categories)
|
||||||
@@ -19,6 +19,7 @@ class WebApplication(SoftwarePackage):
|
|||||||
self.desktop_entry = desktop_entry
|
self.desktop_entry = desktop_entry
|
||||||
self.set_custom_icon(custom_icon)
|
self.set_custom_icon(custom_icon)
|
||||||
self.preset_options = preset_options
|
self.preset_options = preset_options
|
||||||
|
self.is_suggestion = is_suggestion
|
||||||
|
|
||||||
def set_version(self, version: str):
|
def set_version(self, version: str):
|
||||||
self.version = str(version) if version else None
|
self.version = str(version) if version else None
|
||||||
|
|||||||
Reference in New Issue
Block a user