From 1a2d97bf4647469668346a842a67efc8e6572f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 6 Mar 2020 12:20:04 -0300 Subject: [PATCH] [fix][web] not informing StartupWMClass on generated desktop entries --- CHANGELOG.md | 5 +++-- bauh/gems/web/controller.py | 14 +++++++++++++- bauh/gems/web/model.py | 23 ++++++++++++++--------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2926940..f96a2b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,12 @@ 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.8.5] - 2020-03-06 + +## [0.8.5] - 2020-03 ### Fixes - Web - not able to inject javascript fixes ( WhatsApp Web not working) [#74](https://github.com/vinifmor/bauh/issues/74) + - not informing StartupWMClass on generated desktop entries ( prevents Gnome to link the Favorite shortcut with the app instance [#76](https://github.com/vinifmor/bauh/issues/76) ) ### Improvements - AUR diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index cf7b1c91..1aaa4a03 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -1,4 +1,5 @@ import glob +import json import locale import os import re @@ -688,6 +689,15 @@ class WebApplicationManager(SoftwareManager): watcher.change_substatus(self.i18n['web.install.substatus.shortcut']) + try: + package_info_path = '{}/resources/app/package.json'.format(pkg.installation_dir) + with open(package_info_path) as f: + package_info_path = json.loads(f.read()) + pkg.package_name = package_info_path['name'] + except: + self.logger.info("Could not read the the package info from '{}'".format(package_info_path)) + traceback.print_exc() + desktop_entry_path = self._gen_desktop_entry_path(app_id) entry_content = self._gen_desktop_entry_content(pkg) @@ -720,9 +730,11 @@ class WebApplicationManager(SoftwareManager): Icon={icon} Exec={exec_path} {categories} + {wmclass} """.format(name=pkg.name, exec_path=pkg.get_command(), desc=pkg.description or pkg.url, icon=pkg.get_disk_icon_path(), - categories='Categories={}'.format(';'.join(pkg.categories)) if pkg.categories else '') + categories='Categories={}'.format(';'.join(pkg.categories)) if pkg.categories else '', + wmclass="StartupWMClass={}".format(pkg.package_name) if pkg.package_name else '') def is_enabled(self) -> bool: return self.enabled diff --git a/bauh/gems/web/model.py b/bauh/gems/web/model.py index d87e731e..59bd1a19 100644 --- a/bauh/gems/web/model.py +++ b/bauh/gems/web/model.py @@ -13,7 +13,7 @@ class WebApplication(SoftwarePackage): 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, categories: List[str] = None, custom_icon: str = None, preset_options: List[str] = None, save_icon: bool = True, - options_set: List[str] = None): + options_set: List[str] = None, package_name: 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) @@ -24,6 +24,7 @@ class WebApplication(SoftwarePackage): self.preset_options = preset_options self.save_icon = save_icon # if the icon_url should be used instead of the one retrieved by nativefier self.options_set = options_set + self.package_name = package_name def set_version(self, version: str): self.version = str(version) if version else None @@ -38,7 +39,7 @@ 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' + 'desktop_entry', 'categories', 'custom_icon', 'options_set', 'save_icon', 'package_name' def can_be_downgraded(self): return False @@ -123,13 +124,17 @@ class WebApplication(SoftwarePackage): self.icon_url = custom_icon def get_config_dir(self) -> str: - if self.installation_dir: - config_path = '{}/.config'.format(Path.home()) + if self.package_name: + config_dir = '{}/.config/{}'.format(str(Path.home()), self.package_name) - if os.path.exists(config_path): - config_dirs = glob.glob('{}/{}-nativefier-*'.format(config_path, self.installation_dir.split('/')[-1])) - - if config_dirs: - return config_dirs[0] + if os.path.exists(config_dir): + return config_dir + else: + if self.installation_dir: + config_path = '{}/.config'.format(str(Path.home())) + if os.path.exists(config_path): + config_dirs = glob.glob('{}/{}-nativefier-*'.format(config_path, self.installation_dir.split('/')[-1])) + if config_dirs: + return config_dirs[0]