mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-28 22:01:24 +00:00
fix: add option to use old Windows 'start' command (#1084)
This commit is contained in:
committed by
GitHub
parent
eecb4d3e38
commit
3374f6b07f
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user