Make the FileSelection widget use native file browser widgets under Flatpak in order to enable the sandbox

This commit is contained in:
Micah Lee 2021-11-14 14:24:02 -08:00
parent 365ddc5e34
commit 94c588d0ce
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -342,8 +342,20 @@ class FileSelection(QtWidgets.QVBoxLayout):
self.file_list.files_dropped.connect(self.update) self.file_list.files_dropped.connect(self.update)
self.file_list.files_updated.connect(self.update) self.file_list.files_updated.connect(self.update)
# Buttons # 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": if self.common.platform == "Darwin":
self.sandbox = True
# Flatpack
elif self.common.platform == "Linux" and os.path.exists("/app/manifest.json"):
self.sandbox = True
else:
self.sandbox = False
# Buttons
if self.sandbox:
# The macOS sandbox makes it so the Mac version needs separate add files # The macOS sandbox makes it so the Mac version needs separate add files
# and folders buttons, in order to use native file selection dialogs # and folders buttons, in order to use native file selection dialogs
self.add_files_button = QtWidgets.QPushButton(strings._("gui_add_files")) self.add_files_button = QtWidgets.QPushButton(strings._("gui_add_files"))
@ -357,7 +369,7 @@ class FileSelection(QtWidgets.QVBoxLayout):
self.remove_button.clicked.connect(self.delete) self.remove_button.clicked.connect(self.delete)
button_layout = QtWidgets.QHBoxLayout() button_layout = QtWidgets.QHBoxLayout()
button_layout.addStretch() button_layout.addStretch()
if self.common.platform == "Darwin": if self.sandbox:
button_layout.addWidget(self.add_files_button) button_layout.addWidget(self.add_files_button)
button_layout.addWidget(self.add_folder_button) button_layout.addWidget(self.add_folder_button)
else: else:
@ -376,14 +388,14 @@ class FileSelection(QtWidgets.QVBoxLayout):
""" """
# All buttons should be hidden if the server is on # All buttons should be hidden if the server is on
if self.server_on: if self.server_on:
if self.common.platform == "Darwin": if self.sandbox:
self.add_files_button.hide() self.add_files_button.hide()
self.add_folder_button.hide() self.add_folder_button.hide()
else: else:
self.add_button.hide() self.add_button.hide()
self.remove_button.hide() self.remove_button.hide()
else: else:
if self.common.platform == "Darwin": if self.sandbox:
self.add_files_button.show() self.add_files_button.show()
self.add_folder_button.show() self.add_folder_button.show()
else: else: