From 416a3fd0dd22f88b2bb5454ebfc5e6a558adff25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 13 Dec 2019 17:15:25 -0300 Subject: [PATCH] [wgem] set the application to autostart if --tray=start-in-tray --- bauh/gems/web/controller.py | 20 +++++++++++++++++++- bauh/gems/web/model.py | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 7e9df38a..a72ac7c7 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -19,6 +19,7 @@ from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \ SelectViewType, TextInputComponent, FormComponent +from bauh.api.constants import HOME_PATH from bauh.commons.html import bold from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str from bauh.gems.web import INSTALLED_PATH, nativefier, DESKTOP_ENTRY_PATH_PATTERN, URL_FIX_PATTERN @@ -189,7 +190,16 @@ class WebApplicationManager(SoftwareManager): body=self.i18n['web.uninstall.error.remove'].format(bold(pkg.desktop_entry)), type_=MessageType.ERROR) traceback.print_exc() - return False + + autostart_path = pkg.get_autostart_path() + if os.path.exists(autostart_path): + try: + os.remove(autostart_path) + except: + watcher.show_message(title=self.i18n['error'], + body=self.i18n['web.uninstall.error.remove'].format(bold(autostart_path)), + type_=MessageType.ERROR) + traceback.print_exc() return True @@ -390,6 +400,14 @@ class WebApplicationManager(SoftwareManager): f.write(entry_content) pkg.desktop_entry = desktop_entry_path + + if '--tray=start-in-tray' in install_options: + autostart_dir = '{}/.config/autostart'.format(Path.home()) + Path(autostart_dir).mkdir(parents=True, exist_ok=True) + + with open(pkg.get_autostart_path(), 'w+') as f: + f.write(entry_content) + return True def _gen_desktop_entry_content(self, pkg: WebApplication) -> str: diff --git a/bauh/gems/web/model.py b/bauh/gems/web/model.py index 12d3c93b..4374f74f 100644 --- a/bauh/gems/web/model.py +++ b/bauh/gems/web/model.py @@ -1,4 +1,5 @@ import re +from pathlib import Path from typing import List from bauh.api.abstract.model import SoftwarePackage @@ -86,3 +87,7 @@ class WebApplication(SoftwarePackage): def has_screenshots(self) -> bool: return False + + def get_autostart_path(self) -> str: + if self.desktop_entry: + return '{}/.config/autostart/{}'.format(Path.home(), self.desktop_entry.split('/')[-1])