mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 18:22:37 +02:00
To allow the Apple sandbox, disable finding PDF viewers on Mac
This commit is contained in:
parent
d7cd8584f2
commit
2dd509f980
2 changed files with 18 additions and 47 deletions
|
@ -48,11 +48,8 @@ class GuiCommon(object):
|
||||||
def open_pdf_viewer(self, filename):
|
def open_pdf_viewer(self, filename):
|
||||||
if self.global_common.settings.get("open_app") in self.pdf_viewers:
|
if self.global_common.settings.get("open_app") in self.pdf_viewers:
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
# Get the PDF reader bundle command
|
# Open in Preview
|
||||||
bundle_identifier = self.pdf_viewers[
|
args = ["open", "-a", "Preview.app", filename]
|
||||||
self.global_common.settings.get("open_app")
|
|
||||||
]
|
|
||||||
args = ["open", "-b", bundle_identifier, filename]
|
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
args_str = " ".join(pipes.quote(s) for s in args)
|
args_str = " ".join(pipes.quote(s) for s in args)
|
||||||
|
@ -81,41 +78,7 @@ class GuiCommon(object):
|
||||||
|
|
||||||
def _find_pdf_viewers(self):
|
def _find_pdf_viewers(self):
|
||||||
pdf_viewers = {}
|
pdf_viewers = {}
|
||||||
|
if platform.system() == "Linux":
|
||||||
if platform.system() == "Darwin":
|
|
||||||
# Get all installed apps that can open PDFs
|
|
||||||
bundle_identifiers = LaunchServices.LSCopyAllRoleHandlersForContentType(
|
|
||||||
"com.adobe.pdf", CoreServices.kLSRolesAll
|
|
||||||
)
|
|
||||||
for bundle_identifier in bundle_identifiers:
|
|
||||||
# Get the filesystem path of the app
|
|
||||||
res = LaunchServices.LSCopyApplicationURLsForBundleIdentifier(
|
|
||||||
bundle_identifier, None
|
|
||||||
)
|
|
||||||
if res[0] is None:
|
|
||||||
continue
|
|
||||||
app_url = res[0][0]
|
|
||||||
app_path = str(app_url.path())
|
|
||||||
|
|
||||||
# Load its plist file
|
|
||||||
plist_path = os.path.join(app_path, "Contents/Info.plist")
|
|
||||||
|
|
||||||
# Skip if there's not an Info.plist
|
|
||||||
if not os.path.exists(plist_path):
|
|
||||||
continue
|
|
||||||
|
|
||||||
with open(plist_path, "rb") as f:
|
|
||||||
plist_data = f.read()
|
|
||||||
|
|
||||||
plist_dict = plistlib.loads(plist_data)
|
|
||||||
|
|
||||||
if (
|
|
||||||
plist_dict.get("CFBundleName")
|
|
||||||
and plist_dict["CFBundleName"] != "Dangerzone"
|
|
||||||
):
|
|
||||||
pdf_viewers[plist_dict["CFBundleName"]] = bundle_identifier
|
|
||||||
|
|
||||||
elif platform.system() == "Linux":
|
|
||||||
# Find all .desktop files
|
# Find all .desktop files
|
||||||
for search_path in [
|
for search_path in [
|
||||||
"/usr/share/applications",
|
"/usr/share/applications",
|
||||||
|
|
|
@ -42,7 +42,14 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
save_layout.addWidget(self.save_browse_button)
|
save_layout.addWidget(self.save_browse_button)
|
||||||
save_layout.addStretch()
|
save_layout.addStretch()
|
||||||
|
|
||||||
if platform.system() != "Windows":
|
if platform.system() == "Darwin":
|
||||||
|
# Open safe document
|
||||||
|
self.open_checkbox = QtWidgets.QCheckBox(
|
||||||
|
"Open safe document after converting"
|
||||||
|
)
|
||||||
|
self.open_checkbox.clicked.connect(self.update_ui)
|
||||||
|
|
||||||
|
elif platform.system() != "Linux":
|
||||||
# Open safe document
|
# Open safe document
|
||||||
self.open_checkbox = QtWidgets.QCheckBox(
|
self.open_checkbox = QtWidgets.QCheckBox(
|
||||||
"Open safe document after converting, using"
|
"Open safe document after converting, using"
|
||||||
|
@ -114,12 +121,13 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
if index != -1:
|
if index != -1:
|
||||||
self.ocr_combobox.setCurrentIndex(index)
|
self.ocr_combobox.setCurrentIndex(index)
|
||||||
|
|
||||||
if platform.system() != "Windows":
|
if platform.system() == "Darwin" or platform.system() == "Linux":
|
||||||
if self.global_common.settings.get("open"):
|
if self.global_common.settings.get("open"):
|
||||||
self.open_checkbox.setCheckState(QtCore.Qt.Checked)
|
self.open_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||||
else:
|
else:
|
||||||
self.open_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
self.open_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
index = self.open_combobox.findText(
|
index = self.open_combobox.findText(
|
||||||
self.global_common.settings.get("open_app")
|
self.global_common.settings.get("open_app")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue