-
-
Notifications
You must be signed in to change notification settings - Fork 955
feat: support Windows right-click context menu to open directory #3280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Windows Registry Editor Version 5.00 | ||
|
|
||
| ; ============================================================ | ||
| ; Remove Wave Terminal Context Menu | ||
| ; ============================================================ | ||
|
|
||
| [-HKEY_CLASSES_ROOT\Directory\Background\shell\WaveTerminal] | ||
| [-HKEY_CLASSES_ROOT\Directory\shell\WaveTerminal] | ||
| [-HKEY_CLASSES_ROOT\Drive\shell\WaveTerminal] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| Windows Registry Editor Version 5.00 | ||
|
|
||
| ; ============================================================ | ||
| ; Wave Terminal - Windows Right-Click Context Menu | ||
| ; ============================================================ | ||
| ; Adds "Open in Wave Terminal" to: | ||
| ; 1. Right-click on empty space in a folder (Directory\Background) | ||
| ; 2. Right-click on a folder itself (Directory) | ||
| ; ============================================================ | ||
|
|
||
| ; --- Folder background (right-click empty space) --- | ||
| [HKEY_CLASSES_ROOT\Directory\Background\shell\WaveTerminal] | ||
| @="Open in Wave Terminal" | ||
| "Icon"="C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe" | ||
|
|
||
| [HKEY_CLASSES_ROOT\Directory\Background\shell\WaveTerminal\command] | ||
| @="\"C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe\" \"%V\"" | ||
|
|
||
| ; --- Folder itself (right-click on folder) --- | ||
| [HKEY_CLASSES_ROOT\Directory\shell\WaveTerminal] | ||
| @="Open in Wave Terminal" | ||
| "Icon"="C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe" | ||
|
|
||
| [HKEY_CLASSES_ROOT\Directory\shell\WaveTerminal\command] | ||
| @="\"C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe\" \"%1\"" | ||
|
|
||
| ; --- Drive root (right-click on drive in This PC) --- | ||
| [HKEY_CLASSES_ROOT\Drive\shell\WaveTerminal] | ||
| @="Open in Wave Terminal" | ||
| "Icon"="C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe" | ||
|
|
||
| [HKEY_CLASSES_ROOT\Drive\shell\WaveTerminal\command] | ||
| @="\"C:\\Users\\azurr\\AppData\\Local\\Programs\\waveterm\\Wave.exe\" \"%1\"" | ||
|
Comment on lines
+14
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded developer path makes this file non-functional for any other user. All six path entries reference Since $wavePath = "$env:LOCALAPPDATA\Programs\waveterm\Wave.exe"
@(
"HKCU:\SOFTWARE\Classes\Directory\Background\shell\WaveTerminal",
"HKCU:\SOFTWARE\Classes\Directory\shell\WaveTerminal",
"HKCU:\SOFTWARE\Classes\Drive\shell\WaveTerminal"
) | ForEach-Object {
New-Item -Path "$_\command" -Force | Out-Null
Set-ItemProperty -Path $_ -Name "(default)" -Value "Open in Wave Terminal"
Set-ItemProperty -Path $_ -Name "Icon" -Value $wavePath
Set-ItemProperty -Path "$_\command" -Name "(default)" -Value "`"$wavePath`" `"%V`""
}Using
🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Electron second-instance workingDirectory vs argv for Windows Explorer right-click Directory context menu💡 Result:
Electron single-instance relaunch: use the second-instance event’s argv (and workingDirectory) rather than process.argv. 1) What Electron passes to the primary instance - When a second process starts and the first instance called app.requestSingleInstanceLock, Electron emits: - second-instance with parameters (event, argv, workingDirectory, additionalData). - argv is an array of the second instance’s command-line arguments, and workingDirectory is the second instance’s current working directory. - additionalData is JSON/object data you passed to app.requestSingleInstanceLock(additionalData); Electron documentation notes that argv may not be exactly the same as what you launched with (order may change; additional args may be appended). - Electron also notes Chromium may add extra arguments (e.g. --original-process-start-time). So, for your Windows Explorer right-click Directory context menu, the value you care about (the selected directory path) should be read from the argv array provided to the second-instance handler, and/or (more robustly) you should move that data into additionalData. 2) workingDirectory vs argv (which one to use) - workingDirectory: - It is the “current working directory” of the second launch. - This is generally not the selected directory path you get from Explorer context menus. - argv: - Contains the command-line arguments that Explorer (via your registered command) passed to your Electron executable for the second launch. - This is what you should parse to obtain the selected folder path. 3) Important caveats on Windows/Chromium argument handling - Electron/Chromium may manipulate the second-instance argv: - The documentation explicitly warns that argv “will not be exactly the same list of arguments as those passed to the second instance”; order can change and additional args can be appended. - Chromium command-line parsing can also split/move values such as switches vs positional arguments (documented in electron/electron issues). This can make “exact argv reproduction” unreliable. Practical implication for your question: - Don’t rely on workingDirectory to provide the right-click target. - Don’t rely on argv matching process.argv exactly. 4) Recommended robust pattern - In main process, register a single-instance lock and in second-instance: - Parse the directory path from the argv array you receive. - Focus/notify your existing BrowserWindow. - If you need strict data fidelity (exact path, including tricky quoting), prefer passing your payload through additionalData (Electron supports an object passed via app.requestSingleInstanceLock(additionalData) and received in the second-instance handler as additionalData). Code skeleton: const { app, BrowserWindow } = require('electron'); let win; const gotTheLock = app.requestSingleInstanceLock(/* optional initial data /); if (!gotTheLock) app.quit; else { app.on('second-instance', (event, argv, workingDirectory /, additionalData */) => { // argv: array of second instance’s command-line args // workingDirectory: cwd of second instance // Example: find your custom flag and read the following value // const path = extractFrom(argv); if (win) { if (win.isMinimized) win.restore; win.focus; } // send the extracted folder path to renderer / update tabs }); app.whenReady.then( => { win = new BrowserWindow({}); // load your app }); } 5) Bottom line answer to the “workingDirectory vs argv” part - Use argv for the Explorer right-click “Directory” target path you pass via your registry “command” line. - workingDirectory is only the second process’s current working directory and usually won’t be the selected directory. - Treat argv as parsed-by-Chromium and not guaranteed to equal your original process.argv; if you need exactness, use additionalData.
Citations:
second-instanceevent doesn't provide expected arguments electron/electron#13652second-instanceevent process arguments rip apart "name-value" arguments electron/electron#20322workingDirectoryis only correct forDirectory\Background; theDirectoryandDriveentries will silently open the wrong folder.workingDirectoryis the second instance's current working directory, not necessarily the folder that was right-clicked. ForDirectory\Background, Windows Explorer sets the process CWD to the browsed folder, soworkingDirectoryis correct. However, forDirectoryandDrive, the target path is passed as a command-line argument (%1in the registry command) and the process CWD is elsewhere —workingDirectorywill silently resolve to the wrong location.The robust approach is to scan
argvfor the first non-flag, absolute-path argument and fall back toworkingDirectory. Note that Electron'sargvmay not exactly match what was passed to the second instance — order may change and Chromium flags (e.g.,--original-process-start-time) may be appended, which is why scanning for a non-flag absolute path (not relying on a fixed position) is necessary.Proposed fix
electronApp.on("second-instance", (_event, argv, workingDirectory) => { console.log("second-instance event, argv:", argv, "workingDirectory:", workingDirectory); - const cwd = workingDirectory || undefined; + // For Directory/Drive context menu, the target path is passed as an explicit + // %1/%V argument in argv. For Directory\Background, workingDirectory is the folder. + // Electron may inject Chromium flags into argv, so scan for a non-flag absolute path. + const pathArg = argv?.find( + (arg) => !arg.startsWith("-") && /^[a-zA-Z]:[\\\/]/.test(arg) + ); + const cwd = pathArg || workingDirectory || undefined; fireAndForget(() => createNewWaveWindow(cwd)); });📝 Committable suggestion
🤖 Prompt for AI Agents