Skip to content

Fix: Prevent Multiple Electron Icons in macOS Dock#11

Open
pomelo-nwu wants to merge 1 commit intomainfrom
fix/macos-dock-icons
Open

Fix: Prevent Multiple Electron Icons in macOS Dock#11
pomelo-nwu wants to merge 1 commit intomainfrom
fix/macos-dock-icons

Conversation

@pomelo-nwu
Copy link
Collaborator

Problem

When running npm run dev on macOS and sending a message (e.g., typing "hi"), multiple Electron icons appear in the Dock. These icons disappear after the API response is received.

image

Root Cause

  1. SDK Spawns Child Processes: The @qwen-code/sdk library internally uses child_process.spawn to spawn child processes for handling user requests.

  2. Missing Environment Variable in Dev Mode: The original code only set ELECTRON_RUN_AS_NODE=1 when app.isPackaged was true (production mode). In development mode, this environment variable was not set.

  3. Electron Runs as GUI App: Without ELECTRON_RUN_AS_NODE, when the SDK spawns a child process using process.execPath (which points to the Electron executable), macOS treats it as a separate GUI application, causing it to appear in the Dock.

  4. Processes Exit After Response: Once the API response is received, the child processes exit, and the Dock icons disappear.

Solution

Changes Made

  1. Always Set ELECTRON_RUN_AS_NODE=1

    • Removed the app.isPackaged condition so this variable is set in both development and production modes
    • This forces Electron to run as a Node.js runtime instead of a GUI application
  2. Create hide-dock.js Preload Script

    • Sets LSUIElement=1 environment variable
    • Calls app.dock.hide() to hide the Dock icon
    • Handles both immediate and deferred app ready states
  3. Configure NODE_OPTIONS

    • Added --require "hide-dock.js" to NODE_OPTIONS environment variable
    • This ensures the script is loaded in all child processes spawned by the SDK
  4. Update Build Script

    • Modified transpile:electron to copy .js files to dist-electron/libs/
    • Ensures the script is available in both development and production builds

Files Changed

File Change
src/electron/libs/hide-dock.js New file: Preload script to hide Dock icons on macOS
src/electron/libs/util.ts Set ELECTRON_RUN_AS_NODE=1 for all modes; add NODE_OPTIONS with hide-dock script
package.json Update transpile:electron script to copy .js files

Testing

  • Run npm run dev on macOS
  • Send a message (e.g., "hi")
  • Verify no multiple Electron icons appear in Dock
  • Verify API responses are received normally
  • Test in production build (npm run dist:mac)

Checklist

  • Code follows project style guidelines
  • Changes are minimal and focused on the fix
  • No breaking changes introduced
  • Tested on macOS (Darwin)

Related Issues

Fixes: Multiple Electron icons appearing in macOS Dock during SDK subprocess execution

…subprocesses

When SDK spawns subprocesses during development, each Electron child process
would appear as a separate icon in the macOS Dock. This fix:

- Adds ELECTRON_RUN_AS_NODE=1 for all modes (not just packaged)
- Creates hide-dock.js preload script to hide Dock icons on macOS
- Configures NODE_OPTIONS to preload the script in child processes
- Updates build script to copy .js files to dist-electron/libs/

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant