From 3f7621145996f780d66b15891d8ca89bc824ae5d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 2 Jul 2021 13:48:20 -0700 Subject: [PATCH] Fix open in Preview for macOS --- dangerzone/gui/common.py | 51 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/dangerzone/gui/common.py b/dangerzone/gui/common.py index 6c9a642..f29d8e3 100644 --- a/dangerzone/gui/common.py +++ b/dangerzone/gui/common.py @@ -46,35 +46,34 @@ class GuiCommon(object): return QtGui.QIcon(path) def open_pdf_viewer(self, filename): - if self.global_common.settings.get("open_app") in self.pdf_viewers: - if platform.system() == "Darwin": - # Open in Preview - args = ["open", "-a", "Preview.app", filename] + if platform.system() == "Darwin": + # Open in Preview + args = ["open", "-a", "Preview.app", filename] - # Run - args_str = " ".join(pipes.quote(s) for s in args) - print(Fore.YELLOW + "> " + Fore.CYAN + args_str) - subprocess.run(args) + # Run + args_str = " ".join(pipes.quote(s) for s in args) + print(Fore.YELLOW + "> " + Fore.CYAN + args_str) + subprocess.run(args) - elif platform.system() == "Linux": - # Get the PDF reader command - args = shlex.split( - self.pdf_viewers[self.global_common.settings.get("open_app")] - ) - # %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open - for i in range(len(args)): - if ( - args[i] == "%f" - or args[i] == "%F" - or args[i] == "%u" - or args[i] == "%U" - ): - args[i] = filename + elif platform.system() == "Linux": + # Get the PDF reader command + args = shlex.split( + self.pdf_viewers[self.global_common.settings.get("open_app")] + ) + # %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open + for i in range(len(args)): + if ( + args[i] == "%f" + or args[i] == "%F" + or args[i] == "%u" + or args[i] == "%U" + ): + args[i] = filename - # Open as a background process - args_str = " ".join(pipes.quote(s) for s in args) - print(Fore.YELLOW + "> " + Fore.CYAN + args_str) - subprocess.Popen(args) + # Open as a background process + args_str = " ".join(pipes.quote(s) for s in args) + print(Fore.YELLOW + "> " + Fore.CYAN + args_str) + subprocess.Popen(args) def _find_pdf_viewers(self): pdf_viewers = {}