From 0f63c89a5929182e9ea120075fe47d58536ce2fc Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sun, 14 Nov 2021 17:16:21 -0800 Subject: [PATCH] Detect Flatpak via environment variable --- cli/onionshare_cli/common.py | 6 ++++++ desktop/src/onionshare/tab/mode/file_selection.py | 15 +++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index bab3fd86..ca88deef 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -432,6 +432,12 @@ class Common: r = random.SystemRandom() return "-".join(r.choice(wordlist) for _ in range(word_count)) + def is_flatpak(self): + """ + Returns True if OnionShare is running in a Flatpak sandbox + """ + return os.environ.get("FLATPAK_ID") == "org.onionshare.OnionShare" + @staticmethod def random_string(num_bytes, output_len=None): """ diff --git a/desktop/src/onionshare/tab/mode/file_selection.py b/desktop/src/onionshare/tab/mode/file_selection.py index 40ca1685..c75e9db6 100644 --- a/desktop/src/onionshare/tab/mode/file_selection.py +++ b/desktop/src/onionshare/tab/mode/file_selection.py @@ -186,7 +186,7 @@ class FileList(QtWidgets.QListWidget): dragEnterEvent for dragging files and directories into the widget. """ # Drag and drop doesn't work in Flatpak, because of the sandbox - if self.common.platform == "Linux" and os.path.exists("/app/manifest.json"): + if self.common.is_flatpak(): Alert(self.common, strings._("gui_dragdrop_sandbox_flatpak").format()) event.ignore() return @@ -213,7 +213,7 @@ class FileList(QtWidgets.QListWidget): dragLeaveEvent for dragging files and directories into the widget. """ # Drag and drop doesn't work in Flatpak, because of the sandbox - if self.common.platform == "Linux" and os.path.exists("/app/manifest.json"): + if self.common.is_flatpak(): event.ignore() return @@ -227,7 +227,7 @@ class FileList(QtWidgets.QListWidget): dragMoveEvent for dragging files and directories into the widget. """ # Drag and drop doesn't work in Flatpak, because of the sandbox - if self.common.platform == "Linux" and os.path.exists("/app/manifest.json"): + if self.common.is_flatpak(): event.ignore() return @@ -242,7 +242,7 @@ class FileList(QtWidgets.QListWidget): dropEvent for dragging files and directories into the widget. """ # Drag and drop doesn't work in Flatpak, because of the sandbox - if self.common.platform == "Linux" and os.path.exists("/app/manifest.json"): + if self.common.is_flatpak(): event.ignore() return @@ -365,12 +365,7 @@ class FileSelection(QtWidgets.QVBoxLayout): # Sandboxes (for masOS, Flatpak, etc.) need separate add files and folders buttons, in # order to use native file selection dialogs - - # macOS - if self.common.platform == "Darwin": - self.sandbox = True - # Flatpack - elif self.common.platform == "Linux" and os.path.exists("/app/manifest.json"): + if self.common.platform == "Darwin" or self.common.is_flatpak(): self.sandbox = True else: self.sandbox = False