From f125e5a50d63af63d4f8f8f9321354d8f850af6b Mon Sep 17 00:00:00 2001 From: Xarvex Date: Wed, 24 Apr 2024 23:37:36 -0500 Subject: [PATCH 1/3] Implement file opening for Linux and MacOS, allow Windows in background Note: this is only tested on Linux --- tagstudio/src/qt/ts_qt.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 45ebd0d8..1695690f 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -41,6 +41,8 @@ import src.qt.resources_rc # from typing_extensions import deprecated from humanfriendly import format_timespan # from src.qt.qtacrylic.qtacrylic import WindowEffect +import shutil +import subprocess # SIGQUIT is not defined on Windows if sys.platform == "win32": @@ -56,13 +58,21 @@ INFO = f'[INFO]' logging.basicConfig(format="%(message)s", level=logging.INFO) -def open_file(path): - try: - os.startfile(path) - except FileNotFoundError: - logging.info('File Not Found! (Imagine this as a popup)') - except: - traceback.print_exc() +def open_file(path: str): + if sys.platform == "win32": + command_name = "start" + elif sys.platform == "darwin": + command_name = "open" + else: + command_name = "xdg-open" + command = shutil.which(command_name) + if command is not None: + try: + subprocess.Popen([command, path], close_fds=True) + except: + traceback.print_exc() + else: + logging.info(f"Could not find {command_name} on system PATH") class NavigationState(): From 8b4b2507fa841af1816493a9380230d9b6b46da5 Mon Sep 17 00:00:00 2001 From: Xarvex Date: Wed, 24 Apr 2024 23:50:26 -0500 Subject: [PATCH 2/3] Account for start being a shell builtin on Windows --- tagstudio/src/qt/ts_qt.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 1695690f..57e056a9 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -59,20 +59,21 @@ logging.basicConfig(format="%(message)s", level=logging.INFO) def open_file(path: str): - if sys.platform == "win32": - command_name = "start" - elif sys.platform == "darwin": - command_name = "open" - else: - command_name = "xdg-open" - command = shutil.which(command_name) - if command is not None: - try: - subprocess.Popen([command, path], close_fds=True) - except: - traceback.print_exc() - else: - logging.info(f"Could not find {command_name} on system PATH") + try: + if sys.platform == "win32": + subprocess.Popen(["start", path], shell=True, close_fds=True) + else: + if sys.platform == "darwin": + command_name = "open" + else: + command_name = "xdg-open" + command = shutil.which(command_name) + if command is not None: + subprocess.Popen([command, path], close_fds=True) + else: + logging.info(f"Could not find {command_name} on system PATH") + except: + traceback.print_exc() class NavigationState(): From 956ffd4663ce98dc4f124fa6287514efbb01b3c8 Mon Sep 17 00:00:00 2001 From: Xarvex Date: Thu, 25 Apr 2024 00:07:14 -0500 Subject: [PATCH 3/3] Properly detach process on Windows --- tagstudio/src/qt/ts_qt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 57e056a9..253f9d20 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -61,7 +61,7 @@ logging.basicConfig(format="%(message)s", level=logging.INFO) def open_file(path: str): try: if sys.platform == "win32": - subprocess.Popen(["start", path], shell=True, close_fds=True) + subprocess.Popen(["start", path], shell=True, close_fds=True, creationflags=subprocess.DETACHED_PROCESS) else: if sys.platform == "darwin": command_name = "open"