mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-10 11:32:13 -03:00
fix(filesystem): select files via FileManager1 DBus on Linux
open-file-location now asks the freedesktop org.freedesktop.FileManager1 ShowItems interface to reveal the file selected (GNOME Files, Dolphin, Nemo, Caja, recent Thunar), falling back to plain xdg-open when the interface is unavailable. Also align the Linux branch with the other location handlers: headless sessions return clipboard mode instead of silently failing.
This commit is contained in:
@@ -23,6 +23,7 @@ import tempfile
|
||||
import zipfile
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
from urllib.parse import quote
|
||||
from typing import Any, Awaitable, Callable, Dict, Mapping, Protocol, Sequence
|
||||
|
||||
from aiohttp import web
|
||||
@@ -439,6 +440,35 @@ def _has_gui_display() -> bool:
|
||||
return bool(os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"))
|
||||
|
||||
|
||||
def _select_in_linux_file_manager(file_path: str) -> bool:
|
||||
"""Reveal ``file_path`` selected in the desktop file manager.
|
||||
|
||||
Uses the freedesktop ``org.freedesktop.FileManager1.ShowItems`` DBus
|
||||
interface, which is supported by GNOME Files (Nautilus), KDE Dolphin,
|
||||
Nemo, Caja, and recent Thunar. Returns ``False`` when the interface is
|
||||
unavailable so the caller can fall back to plain ``xdg-open``.
|
||||
"""
|
||||
uri = "file://" + quote(file_path)
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
"dbus-send",
|
||||
"--session",
|
||||
"--print-reply",
|
||||
"--dest=org.freedesktop.FileManager1",
|
||||
"/org/freedesktop/FileManager1",
|
||||
"org.freedesktop.FileManager1.ShowItems",
|
||||
f"array:string:{uri}",
|
||||
"string:",
|
||||
],
|
||||
capture_output=True,
|
||||
timeout=5,
|
||||
)
|
||||
except (FileNotFoundError, subprocess.SubprocessError, OSError):
|
||||
return False
|
||||
return result.returncode == 0
|
||||
|
||||
|
||||
class PromptServerProtocol(Protocol):
|
||||
"""Subset of PromptServer used by the handlers."""
|
||||
|
||||
@@ -3512,8 +3542,22 @@ class FileSystemHandler:
|
||||
elif sys.platform == "darwin":
|
||||
subprocess.Popen(["open", "-R", file_path])
|
||||
else:
|
||||
folder = os.path.dirname(file_path)
|
||||
subprocess.Popen(["xdg-open", folder])
|
||||
if not _has_gui_display():
|
||||
# Headless/SSH session: no file manager to open, so
|
||||
# hand the path to the browser for copying instead
|
||||
# of reporting a success that never happened.
|
||||
return web.json_response(
|
||||
{
|
||||
"success": True,
|
||||
"message": "Headless session: path available for copying",
|
||||
"path": file_path,
|
||||
"mode": "clipboard",
|
||||
}
|
||||
)
|
||||
selected = _select_in_linux_file_manager(file_path)
|
||||
if not selected:
|
||||
folder = os.path.dirname(file_path)
|
||||
subprocess.Popen(["xdg-open", folder])
|
||||
|
||||
return web.json_response(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user