From 9310e31f861d8ffc8c943893beb9b0891efc4f16 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Mon, 13 Dec 2021 17:02:56 -0300 Subject: [PATCH] [web] improvement: checking for javascript fixes based on the Electron version --- CHANGELOG.md | 3 ++- bauh/gems/web/__init__.py | 2 +- bauh/gems/web/controller.py | 17 +++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35858b89..49d8be1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Improvements - Web - able to specify a custom User-Agent when installing apps that demand specific settings to work properly on Electron 13.X (e.g: WhatsApp Web) - + - checking for javascript fixes based on the Electron version + ### Fixes - UI - crashing when resizing with floats instead of integers [#216](https://github.com/vinifmor/bauh/issues/216) diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py index 85f9144c..2540add2 100644 --- a/bauh/gems/web/__init__.py +++ b/bauh/gems/web/__init__.py @@ -20,7 +20,7 @@ NATIVEFIER_BIN_PATH = f'{NODE_MODULES_PATH}/.bin/nativefier' ELECTRON_CACHE_DIR = f'{ENV_PATH}/electron' URL_ENVIRONMENT_SETTINGS = f'https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v2/environment.yml' DESKTOP_ENTRY_PATH_PATTERN = f'{DESKTOP_ENTRIES_DIR}/{__app_name__}.web.' + '{name}.desktop' -URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/fix/{url}.js" +URL_FIX_PATTERN = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v2/fix/{domain}/{electron_branch}/fix.js" URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/env/v2/suggestions.yml" UA_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' TEMP_PATH = f'{TEMP_DIR}/web' diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index aabd404a..062a9b7f 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -181,8 +181,10 @@ class WebApplicationManager(SoftwareManager): return description - def _get_fix_for(self, url_no_protocol: str) -> str: - fix_url = URL_FIX_PATTERN.format(url=url_no_protocol) + def _get_fix_for(self, url_domain: str, electron_version: str) -> str: + electron_branch = f"electron_{'_'.join(electron_version.split('.')[0:-1])}_X" + fix_url = URL_FIX_PATTERN.format(domain=url_domain, + electron_branch=electron_branch) try: res = self.http_client.get(fix_url, session=False) @@ -661,13 +663,17 @@ class WebApplicationManager(SoftwareManager): app_dir = '{}/{}'.format(INSTALLED_PATH, app_id) watcher.change_substatus(self.i18n['web.install.substatus.checking_fixes']) - fix = self._get_fix_for(url_no_protocol=self._strip_url_protocol(pkg.url)) + + electron_version = str(next((c for c in env_components if c.id == 'electron')).version) + + fix = self._get_fix_for(url_domain=self._strip_url_protocol(pkg.url), electron_version=electron_version) fix_path = '{}/{}.js'.format(FIXES_PATH, app_id) if fix: # just adding the fix as an installation option. The file will be written later - self.logger.info('Fix found for {}'.format(pkg.url)) - watcher.print('Fix found for {}'.format(pkg.url)) + fix_log = f'Fix found for {pkg.url} (electron={electron_version}, widevine={widevine_support})' + self.logger.info(fix_log) + watcher.print(fix_log) install_options.append('--inject={}'.format(fix_path)) Path(FIXES_PATH).mkdir(exist_ok=True, parents=True) @@ -697,7 +703,6 @@ class WebApplicationManager(SoftwareManager): watcher.change_substatus(self.i18n['web.install.substatus.call_nativefier'].format(bold('nativefier'))) - electron_version = str(next((c for c in env_components if c.id == 'electron')).version) installed = handler.handle_simple(nativefier.install(url=pkg.url, name=app_id, output_dir=app_dir, electron_version=electron_version if not widevine_support else None, system=bool(web_config['environment']['system']),