From dd5b5f891c3eddc40f9d48aeeb7c34f50d260cd8 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sun, 12 Dec 2021 19:03:20 -0300 Subject: [PATCH] [web] improvement: able to specify a custom User-Agent when installing apps that demand specific settings to work properly on Electron 13.X --- CHANGELOG.md | 5 +++++ bauh/gems/web/controller.py | 4 +++- bauh/gems/web/model.py | 7 +++++-- bauh/gems/web/nativefier.py | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b61a998..9f7f2506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.9.24] +### 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) + ## [0.9.23] 2021-12-10 ### Features - General diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 76972514..aabd404a 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -702,6 +702,7 @@ class WebApplicationManager(SoftwareManager): electron_version=electron_version if not widevine_support else None, system=bool(web_config['environment']['system']), cwd=INSTALLED_PATH, + user_agent=pkg.user_agent, extra_options=install_options)) if not installed: @@ -893,7 +894,8 @@ class WebApplicationManager(SoftwareManager): icon_url=suggestion.get('icon_url'), categories=[suggestion['category']] if suggestion.get('category') else None, preset_options=suggestion.get('options'), - save_icon=suggestion.get('save_icon', False)) + save_icon=suggestion.get('save_icon', False), + user_agent=suggestion.get('user_agent')) app.set_version(suggestion.get('version')) diff --git a/bauh/gems/web/model.py b/bauh/gems/web/model.py index a7eeb2ef..58217f68 100644 --- a/bauh/gems/web/model.py +++ b/bauh/gems/web/model.py @@ -17,7 +17,8 @@ class WebApplication(SoftwarePackage): icon_url: Optional[str] = None, installation_dir: Optional[str] = None, desktop_entry: Optional[str] = None, installed: bool = False, version: Optional[str] = None, categories: Optional[List[str]] = None, custom_icon: Optional[str] = None, preset_options: Optional[List[str]] = None, save_icon: bool = True, - options_set: Optional[List[str]] = None, package_name: Optional[str] = None, source_url: Optional[str] = None): + options_set: Optional[List[str]] = None, package_name: Optional[str] = None, source_url: Optional[str] = None, + user_agent: Optional[str] = None): super(WebApplication, self).__init__(id=id if id else url, name=name, description=description, icon_url=icon_url, installed=installed, version=version, categories=categories) @@ -31,6 +32,7 @@ class WebApplication(SoftwarePackage): self.package_name = package_name self.custom_icon = custom_icon self.set_custom_icon(custom_icon) + self.user_agent = user_agent def get_source_url(self): if self.source_url: @@ -51,7 +53,8 @@ class WebApplication(SoftwarePackage): @staticmethod def _get_cached_attrs() -> tuple: return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', \ - 'desktop_entry', 'categories', 'custom_icon', 'options_set', 'save_icon', 'package_name', 'source_url' + 'desktop_entry', 'categories', 'custom_icon', 'options_set', 'save_icon', 'package_name', 'source_url', \ + 'user_agent' def can_be_downgraded(self): return False diff --git a/bauh/gems/web/nativefier.py b/bauh/gems/web/nativefier.py index a1590a94..e6fcd215 100644 --- a/bauh/gems/web/nativefier.py +++ b/bauh/gems/web/nativefier.py @@ -6,13 +6,17 @@ from bauh.commons.system import SimpleProcess, run_cmd from bauh.gems.web import NATIVEFIER_BIN_PATH, NODE_PATHS, ELECTRON_CACHE_DIR -def install(url: str, name: str, output_dir: str, electron_version: Optional[str], cwd: str, system: bool, extra_options: List[str] = None) -> SimpleProcess: +def install(url: str, name: str, output_dir: str, electron_version: Optional[str], cwd: str, system: bool, + user_agent: Optional[str] = None, extra_options: List[str] = None) -> SimpleProcess: cmd = [NATIVEFIER_BIN_PATH if not system else 'nativefier', url, '--name', name, output_dir] if electron_version: cmd.append('-e') cmd.append(electron_version) + if user_agent: + cmd.extend(('--user-agent', user_agent)) + if extra_options: cmd.extend(extra_options)