From 72c4207d9e1785a101b015b20b4f5618c97830c2 Mon Sep 17 00:00:00 2001 From: GithubAnon0000 <160563432+GithubAnon0000@users.noreply.github.com> Date: Fri, 27 Jun 2025 19:24:18 +0200 Subject: [PATCH] Use heuristics --- qt/aqt/utils.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 0bf8f49ff..d71f6e216 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -936,10 +936,33 @@ def show_in_folder(path: str) -> None: """ call(osascript_to_args(script)) else: - # Open the file using the default file handler. This might still open - # the file in an image viewer or the browser (instead of in a file - # manager) if the user has configured the system that way. - subprocess.run(["xdg-open", path], check=False) + # For linux, there are multiple file managers. Let's test if one of the + # most common file managers is found and use it in case it is installed. + # If none of this list are installed, fallback to xdg-open. xdg-open + # might open the image in a web browser, image viewer or others, + # depending on the users defaults. + file_managers = [ + "nautilus", # GNOME + "dolphin", # KDE + "pcmanfm", # LXDE + "thunar", # XFCE + "nemo", # Cinnamon + "caja", # MATE + ] + + available_file_manager = None + + # Test if a file manager is installed. Fallback to xdg-open if none are + # found. + for file_manager in file_managers: + if shutil.which(file_manager): + available_file_manager = file_manager + break + + if available_file_manager: + subprocess.run([available_file_manager, path], check=False) + else: + subprocess.run(["xdg-open", path], check=False) def _show_in_folder_win32(path: str) -> None: