Introduction

The DSH input box only accepts image attachments by default. Dragging local files (such as .txt, .pdf, or code files) is usually rejected, and the action seems unresponsive.

This plugin takes over such rejected drag-and-drop operations: it extracts the actual disk path of the file, writes it into the input box, and also copies it to the clipboard. This way, you can send the path directly to the model to read.

What Is This

dsh-drop-path is a DSH server-side bundle plugin (cordis style). It registers a route and injects a client script into the web page index, then listens for drag-and-drop events during the window capture phase. It uses window.__DSH_DESKTOP_FILE_PATH__.getPathForFile(file) exposed by DSH Desktop (based on Electron’s webUtils.getPathForFile) to resolve the absolute path.

Core Features

  1. Automatically extracts and inserts the absolute path of a local file.
  2. Automatically copies the file path to the clipboard.
  3. Supports dragging non-image files (such as .txt and .pdf).
  4. Provides three mode options (Auto / Always / Off).
  5. Compatible with textarea and contenteditable input boxes.
  6. Works only on the desktop client (relies on the DSH Desktop preload bridge).

Installation and Enablement

Add the plugin to a specified profile using the official installation command:

dsh plugin --profile <profile> add dsh-drop-path

After installation, refresh the web page to enable it. New bundles require restarting DSH or reloading the profile.

Working Principles and Modes

This plugin takes over operations by listening for drag-and-drop events during the window capture phase. This happens before DSH’s built-in ComposerAttachments overlay listener, preventing the overlay from being triggered and avoiding frozen-overlay issues.

There is a “Path Drop” toggle in the lower-left corner for switching modes:

  • Auto (default): Insert the path when a non-image file is dropped; for image-only drops, hand off to DSH to handle as attachments.
  • Always: Insert the path for all drops (including images).
  • Off: Do not intercept; restore DSH’s original behavior.

The state is stored in the browser’s localStorage.

You can switch modes manually in the developer console:

window.__dshDropPath.setMode('off'|'auto'|'always')
window.__dshDropPath.mode()        // 读当前模式
window.__dshDropPath.reset()       // 清除可能残留的拖拽浮层

Usage Examples

  1. Drag a local file into the DSH desktop input box.
  2. Run the console command above to switch modes.
  3. Run tests:
node test/logic.test.mjs

Notes

  • Desktop only: Ordinary browsers cannot access local paths due to security restrictions. If the preload bridge is unavailable, this plugin automatically falls back and does not affect DSH’s original behavior.
  • Conflict handling: It listens during the capture phase and calls stopPropagation() to avoid conflicts with DSH’s built-in drag-and-drop overlay.
  • Hot updates: If only the client script (client/drop-path.js) is modified, there is no need to restart the server; refresh the page instead.

Summary

This plugin solves the pain point of directly referencing local file paths in DSH. With a simple drag operation, developers can hand a file path directly to the model for processing, without manual copy and paste.