Skip to content

Commit f125e5a

Browse files
committed
Implement file opening for Linux and MacOS, allow Windows in background
Note: this is only tested on Linux
1 parent ac00890 commit f125e5a

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tagstudio/src/qt/ts_qt.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
# from typing_extensions import deprecated
4242
from humanfriendly import format_timespan
4343
# from src.qt.qtacrylic.qtacrylic import WindowEffect
44+
import shutil
45+
import subprocess
4446

4547
# SIGQUIT is not defined on Windows
4648
if sys.platform == "win32":
@@ -56,13 +58,21 @@
5658
logging.basicConfig(format="%(message)s", level=logging.INFO)
5759

5860

59-
def open_file(path):
60-
try:
61-
os.startfile(path)
62-
except FileNotFoundError:
63-
logging.info('File Not Found! (Imagine this as a popup)')
64-
except:
65-
traceback.print_exc()
61+
def open_file(path: str):
62+
if sys.platform == "win32":
63+
command_name = "start"
64+
elif sys.platform == "darwin":
65+
command_name = "open"
66+
else:
67+
command_name = "xdg-open"
68+
command = shutil.which(command_name)
69+
if command is not None:
70+
try:
71+
subprocess.Popen([command, path], close_fds=True)
72+
except:
73+
traceback.print_exc()
74+
else:
75+
logging.info(f"Could not find {command_name} on system PATH")
6676

6777

6878
class NavigationState():

0 commit comments

Comments
 (0)