Fix os.startfile usage to check for availability on Windows

This commit is contained in:
leqo-c 2026-05-17 19:10:09 +02:00
commit 1f71f4b0e8

View file

@ -195,9 +195,9 @@ def modify_atime(file_path: str) -> None:
def open_file(file_path: Path, in_browser: bool = False) -> None:
current_os = platform.system()
if current_os == "Windows":
# The method os.startfile is only available in Windows,
# ignoring type error caused by this.
os.startfile(file_path if not in_browser else file_path.parent)
# The method os.startfile is only available in Windows.
if hasattr(os, "startfile"):
os.startfile(file_path if not in_browser else file_path.parent)
else:
if current_os == "Linux":
commands = ["xdg-open"]