From fd6590007b458f92648f39cdee3816dabcc6e30a Mon Sep 17 00:00:00 2001 From: Lorenzo Paderi Date: Sun, 4 Aug 2024 19:00:03 +0000 Subject: [PATCH] check if running in a flatpak sandbox before using flatpak-spawn --- src/lib/terminal.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/terminal.py b/src/lib/terminal.py index 91de1ed..c06cfe0 100644 --- a/src/lib/terminal.py +++ b/src/lib/terminal.py @@ -3,10 +3,17 @@ import threading from typing import Callable, List, Union, Optional import logging +import os + +def is_flatpak(): + return os.environ.get('FLATPAK_ID', False) != False def host_sh(command: List[str], return_stderr=False, **kwargs) -> str: try: - cmd = ['flatpak-spawn', '--host', *command] + cmd = [*command] + + if is_flatpak(): + cmd = ['flatpak-spawn', '--host', *cmd] logging.debug(f'Running {cmd}') output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)