From 3374f6b07f30f51b4006c5e9ef210cc2926d220d Mon Sep 17 00:00:00 2001 From: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> Date: Fri, 5 Sep 2025 13:44:52 -0700 Subject: [PATCH] fix: add option to use old Windows 'start' command (#1084) --- src/tagstudio/core/global_settings.py | 1 + .../preview/preview_thumb_controller.py | 8 +++-- src/tagstudio/qt/helpers/file_opener.py | 32 +++++++++++++------ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/tagstudio/core/global_settings.py b/src/tagstudio/core/global_settings.py index 7f3add39..ec9812bf 100644 --- a/src/tagstudio/core/global_settings.py +++ b/src/tagstudio/core/global_settings.py @@ -60,6 +60,7 @@ class GlobalSettings(BaseModel): tag_click_action: TagClickActionOption = Field(default=TagClickActionOption.DEFAULT) theme: Theme = Field(default=Theme.SYSTEM) splash: Splash = Field(default=Splash.DEFAULT) + windows_start_command: bool = Field(default=False) date_format: str = Field(default="%x") hour_format: bool = Field(default=True) diff --git a/src/tagstudio/qt/controller/widgets/preview/preview_thumb_controller.py b/src/tagstudio/qt/controller/widgets/preview/preview_thumb_controller.py index 017d8762..65223e54 100644 --- a/src/tagstudio/qt/controller/widgets/preview/preview_thumb_controller.py +++ b/src/tagstudio/qt/controller/widgets/preview/preview_thumb_controller.py @@ -144,7 +144,9 @@ class PreviewThumb(PreviewThumbView): return self.__get_image_stats(filepath) def _open_file_action_callback(self): - open_file(self.__current_file) + open_file( + self.__current_file, windows_start_command=self.__driver.settings.windows_start_command + ) def _open_explorer_action_callback(self): open_file(self.__current_file, file_manager=True) @@ -154,4 +156,6 @@ class PreviewThumb(PreviewThumbView): self.__driver.delete_files_callback(self.__current_file) def _button_wrapper_callback(self): - open_file(self.__current_file) + open_file( + self.__current_file, windows_start_command=self.__driver.settings.windows_start_command + ) diff --git a/src/tagstudio/qt/helpers/file_opener.py b/src/tagstudio/qt/helpers/file_opener.py index 583830c8..0227a0d0 100644 --- a/src/tagstudio/qt/helpers/file_opener.py +++ b/src/tagstudio/qt/helpers/file_opener.py @@ -20,13 +20,15 @@ from tagstudio.qt.helpers.silent_popen import silent_Popen logger = structlog.get_logger(__name__) -def open_file(path: str | Path, file_manager: bool = False): +def open_file(path: str | Path, file_manager: bool = False, windows_start_command: bool = False): """Open a file in the default application or file explorer. Args: path (str): The path to the file to open. file_manager (bool, optional): Whether to open the file in the file manager (e.g. Finder on macOS). Defaults to False. + windows_start_command (bool): Flag to determine if the older 'start' command should be used + on Windows for opening files. This fixes issues on some systems in niche cases. """ path = Path(path) logger.info("Opening file", path=path) @@ -51,14 +53,26 @@ def open_file(path: str | Path, file_manager: bool = False): | subprocess.CREATE_BREAKAWAY_FROM_JOB, ) else: - command = f'"{normpath}"' - silent_Popen( - command, - shell=True, - close_fds=True, - creationflags=subprocess.CREATE_NEW_PROCESS_GROUP - | subprocess.CREATE_BREAKAWAY_FROM_JOB, - ) + if windows_start_command: + command_name = "start" + # First parameter is for title, NOT filepath + command_args = ["", normpath] + subprocess.Popen( + [command_name] + command_args, + shell=True, + close_fds=True, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP + | subprocess.CREATE_BREAKAWAY_FROM_JOB, + ) + else: + command = f'"{normpath}"' + silent_Popen( + command, + shell=True, + close_fds=True, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP + | subprocess.CREATE_BREAKAWAY_FROM_JOB, + ) else: if sys.platform == "darwin": command_name = "open"