electron: [Bug]: shell.openPath open windows explorer in the background (windows 11 update 22H2)
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
22.0.0
What operating system are you using?
Windows
Operating System Version
22621.963
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
shell.openPath should open windows explorer on top of the electron app.
Actual Behavior
shell.openPath open windows explorer behind the electron app.
Testcase Gist URL
No response
Additional Information
When this issue was discovered, the electron app was using shell.openItem. I updated electron to 22.0.0 and updated shell.openPath from (*.openItem) but it is the same behavior. I tested on different Windows 11 22H2 machines and I have encountered the same issue. I tried shell.showItemInFolder() and shell.openExternal() but the same issue occured. Before Windows 11 22H2 there was a registry key connected with foreground (HKCU\Control Panel\Desktop\ForegroundLockTimeout set to 0; ForegroundFlashCount set to 7) that would help to make sure windows explorer appear in front of the electron app but this is not the case anymore; after some research I did not find any information on some new registry key that could help. After reading this issue (https://github.com/electron/electron/issues/4349) I realized it is probably a similar problem with electron. Please advise.
I found a way where shell.openPath() open in front of the electron app, in Windows 11 22H2. However, I would like to make sure this is a safe way to do it. Please let me know if it is not. I am not really yet so comfortable with the IPC shenanigans…
Here is the code that for me resolve the issue : // Renderer
try {
ipcRenderer.send('openExplorer', docName);
}
catch(errorMsg) {
/*log it*/
}
// Main.js
ipcMain.on('openExplorer', (event, pathToOpenExplorerIn) => {
try {
if (testSender(event.senderFrame.url)){
shell.openExternal(pathToOpenBrowserIn);
}
}
catch(error) {
/*log it*/
}
})
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 16 (1 by maintainers)
This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.
I had the same problem version: electron20.0.0
Hello,
I noticed you were looking for a solution to your issue. I believe the following code snippet could be beneficial for addressing the problem you’ve described. This code provides a way to handle file operations such as showing an item in a folder or opening a path directly from the Electron main process, making these operations accessible to the renderer process through a secure, context-isolated bridge.
To use this functionality in your renderer process, you can call the methods provided by
window.electronAPIlike so:This setup ensures that your application can perform these operations safely and efficiently, leveraging Electron’s IPC (Inter-Process Communication) for secure communication between the renderer and the main process. Let me know if this helps or if you need further assistance!
Best regards,
zhangsan
I know only a workaround. Something like that: