get-windows icon indicating copy to clipboard operation
get-windows copied to clipboard

active-win working in electron 7 but not in electron 8

Open SilentRush opened this issue 4 years ago • 8 comments

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

SilentRush avatar Apr 11 '20 05:04 SilentRush

Within windows.js the following line is causing the crash.

const windowTextBufferClean = ref.reinterpretUntilZeros(windowTextBuffer, wchar.size);

SilentRush avatar Apr 11 '20 06:04 SilentRush

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, '');

SilentRush avatar Apr 11 '20 07:04 SilentRush

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, '');

same problem here, your approach save me, thanks!

EntwistleOx avatar Apr 20 '20 02:04 EntwistleOx

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

sindresorhus avatar Jul 06 '20 11:07 sindresorhus

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

Antelope-IT avatar Aug 14 '20 17:08 Antelope-IT

@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?

Antelope-IT avatar Sep 03 '20 11:09 Antelope-IT

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:

  1. Install the patch_package module
  2. 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
  3. Run npx patch-package active-win
  4. Add "postinstall": "npx patch-package" to your package.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 !

tkainrad avatar Sep 29 '20 11:09 tkainrad

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.

tkainrad avatar Apr 19 '21 19:04 tkainrad