get-windows
get-windows copied to clipboard
active-win working in electron 7 but not in electron 8
Hello,
I have been using this library for a while now but after updating to electron 8 it has completely stopped working. Have you had a chance to use the library with electron 8? I would simply uninstall electron 8 and re-install electron 7 but for some weird reason after installing 8 downgrading to 7 causes reloading (ctrl+r) electron to produce a white screen. Reloading works find on 8.
Below is the error message I receive when I run let win = await activeWin();
on an electron 8 app.
[1] before active-win [1] [1] [1] # [1] # Fatal error in , line 0 [1] # ignored [1] # [1] # [1] # #FailureMessage Object: 000000050F10BE50wait-on http://localhost:3000 && electron . exited with code 3
Within windows.js the following line is causing the crash.
const windowTextBufferClean = ref.reinterpretUntilZeros(windowTextBuffer, wchar.size);
I found a work around, it appears the ref-napi.reinterpretUntilZeros function is broken in electron 8.
I changed the following:
const windowTextBufferClean = ref.reinterpretUntilZeros(windowTextBuffer, wchar.size);
to
const dirtyTitle = wchar.toString(windowTextBuffer);
const windowTitle = dirtyTitle.replace(/\0/g, '');
const processFileNameBufferClean = ref.reinterpretUntilZeros(processFileNameBuffer, wchar.size);
to
const pathDirty = wchar.toString(processFileNameBuffer);
const processPath = pathDirty.replace(/\0/g, '');
I found a work around, it appears the ref-napi.reinterpretUntilZeros function is broken in electron 8.
I changed the following:
const windowTextBufferClean = ref.reinterpretUntilZeros(windowTextBuffer, wchar.size);
toconst dirtyTitle = wchar.toString(windowTextBuffer);
const windowTitle = dirtyTitle.replace(/\0/g, '');
const processFileNameBufferClean = ref.reinterpretUntilZeros(processFileNameBuffer, wchar.size);
toconst pathDirty = wchar.toString(processFileNameBuffer);
const processPath = pathDirty.replace(/\0/g, '');
same problem here, your approach save me, thanks!
If anyone wants to see this fixed here, please open an issue on Electron first. I'm not going to merge a fix and have to maintain that if people cannot even bother to open an issue to ensure it will eventually be fixed in Electron.
Previous PR attempts:
- https://github.com/sindresorhus/active-win/pull/70
- https://github.com/sindresorhus/active-win/pull/65
If anyone wants to see this fixed here, please open an issue on Electron first. I'm not going to merge a fix and have to maintain that if people cannot even bother to open an issue to ensure it will eventually be fixed in Electron.
Previous PR attempts:
- #70
- #65
I don't know if this is enough and if anyone can add to it then please do but with my limited understanding I have tried to open an issue on Electron https://github.com/electron/electron/issues/24981
@sindresorhus Hi, Now that Electron v7 is out of support (V10 has been released), please can we have a fix for this bug so that projects with dependencies on this library can at least be upgraded to Electron v8? Pull requests have been prepared, a bug has been raised and acknowledged on Electron for v8. There is little possibility of this being resolved in Electron in the short term and less possibility that the issues preventing us from upgrading to Electron v9 and Electron v10 will be resolved in the short term either. Is there anything else preventing this issue from being resolved or is there an alternative path we should follow?
For anyone that has this problem and is not sure how to best patch a library until a fix is available. I did the following:
- Install the patch_package module
- Apply the changes described above by @SilentRush
- Be careful, you need to replace also the two lines with the
reinterpretUntilZeros
calls, but also the line below with the assignment
- Be careful, you need to replace also the two lines with the
- Run
npx patch-package active-win
- Add
"postinstall": "npx patch-package"
to yourpackage.json
This works well also with deployment pipelines, e.g. GitHub Actions and can be removed easily once there is a fix either from the Electron project or the active-win project.
Btw, thanks for this amazing library @sindresorhus !
The patch I described in my previous comment is no longer necessary with Electron 11 and active-win 7.1. With this setup, everything works out of the box. I think this issue can possibly be closed.