Introduction

DSH Desktop is an Electron-based application. Plugins run in separate Node processes, while system tray functionality typically requires modifying main process code. This plugin provides system tray support for DSH Desktop through code injection, including minimize to tray, hide on close, and self-healing recovery after application updates.

Plugin Overview

dsh-desktop-tray is a client plugin that provides system tray support for DSH Desktop. It is maintained by wodongx123 and licensed under MIT.

Installation and Enablement

Install it from the DSH Desktop plugin marketplace, or add it directly to the web profile:

dsh plugin --profile web add github:wodongx123/dsh-desktop-tray

After installation, you need to restart DSH Desktop (not just restart Harness). On first launch, the plugin will automatically perform injection.

Core Features

  • Minimize to Tray: Clicking the minimize button hides the app to the system tray instead of the taskbar.
  • Hide on Close: Closing the window keeps the app running in the background (enabled by default).
  • Hide Immediately: Hide the main window with one click.
  • Tray Interaction: Left single-click/double-click shows the main window; the right-click menu can show the main window or exit.
  • Settings Interface: Settings → System Tray (bilingual Chinese/English).
  • Code Injection Management Panel: Supported from 0.2.0; you can view injection status, start/cancel injection, and confirm the build effect on the settings page.

How It Works

Because DSH Desktop is an Electron application, the system tray can only be created in the main process, while plugins run in isolated processes and cannot directly call Electron APIs. This plugin uses a “self-healing injection at startup” mechanism:

  1. When the application starts, load the tray-boot.js bootstrapper.
  2. The bootstrapper reads the patch definitions inside the plugin and checks whether the main process files (out/main/index.js, out/preload/index.cjs) are already injected.
  3. If they are not injected, inject code at the anchors and back up the original files as *.dsh-tray.bak.
  4. If they are already injected, skip (idempotent operation).

Update Self-Healing: Application updates overwrite the resources/app directory and clear the injected content. The plugin itself is installed in AppData and is not removed by application updates. The next time DSH Desktop starts, the plugin will automatically re-inject the code and restore tray functionality.

Security Design

The plugin uses a five-layer protection mechanism to prevent duplicate injection and file corruption:
1. Idempotency Markers: Files that already contain a marker are not modified.
2. Anchor Consumption: Injection replaces anchors; once an anchor is consumed, it cannot be re-injected.
3. Content Detection: If there is no marker but the content already exists, only add the marker.
4. Whole-file Atomicity: If any anchor mismatches, the entire file is not written.
5. Backup + Atomic Write: Back up before injection, and write using a temporary file + rename method.

Notes

  • Destructive Modification: This plugin modifies DSH Desktop main program files (resources/app/out/main/index.js, out/preload/index.cjs, package.json). This is a destructive modification, not a pure read-only plugin.
  • Restoration Method: If DSH Desktop cannot start, restore the backup files in order and restore the main pointer in package.json.
  • Dependencies: Requires @deepseek-ai/cordis (^4.0.1) and @deepseek-ai/dsh-host-webserver (^0.1.0-rc.6).

Uninstall

  1. Remove the plugin: dsh plugin --profile web remove dsh-desktop-tray, and remove the corresponding entry from the configuration file.
  2. Manually restore application files (if you no longer need the tray):
    • Modify resources/app/package.json and change main back to "./out/main/index.js".
    • Delete resources/app/out/main/tray-boot.js.
    • Use the backup files (*.dsh-tray.bak) to overwrite and restore the corresponding files.

References

  • Plugin catalog: https://www.skillhub.cn/plugins/wodongx123/dsh-desktop-tray
  • GitHub repository: https://github.com/wodongx123/dsh-desktop-tray