[web] improvement: checking for javascript fixes based on the Electron version

This commit is contained in:
Vinicius Moreira
2021-12-13 17:02:56 -03:00
parent 394a5367d3
commit 9310e31f86
3 changed files with 14 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ 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

View File

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

View File

@@ -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']),