electron icon indicating copy to clipboard operation
electron copied to clipboard

[Bug]: requestSingleInstanceLock({ myEmptyArray: [] }) - additionalData is { myEmptyArray: [] } on Linux ✅ but null on Windows ❌

Open nktnet1 opened this issue 1 year ago • 2 comments
trafficstars

Preflight Checklist

Electron Version

27.1.0

Operating System Version

Windows 11 Home | Linux x86_64

What arch are you using?

x64

Last Known Working Electron version

Not sure

Expected Behavior

Windows should behave like Linux and prints

// console.log(additionalData);
{ myEmptyArray: [] }

linux-electron

Actual Behavior

On Windows, we get

// console.log(additionalData);
null

windows-electron

Testcase Gist URL

https://gist.github.com/6b77dd48dc95b711267c62fb9cd5c939

Edit: added further instructions in a separate comment below.

Additional Information

In addition to the gist above, I've created a minimal reproducible example GitHub repository.

The example uses the electron-quickstart-template.

The feature in question is app#apprequestsingleinstancelockadditionaldata.

The example adds the code in this commit to the template:

// At the very top, after imports
if (!app.requestSingleInstanceLock({ myEmptyArray: [] })) {
  app.quit();
  process.exit(0);
}

app.on('second-instance', (_event, _commandLine, _workingDirectory, additionalData) => {
  console.log('second-instance additionalData:', additionalData);
});

If the array isn't empty (e.g. [1] or [''] instead of []), Windows behaves as expected similar to Linux.

nktnet1 avatar Nov 26 '23 12:11 nktnet1

Adding further results when using the Electron Fiddle gist (Electron v27.0.4).

Steps:

  1. Paste https://gist.github.com/6b77dd48dc95b711267c62fb9cd5c939 and "Load Fiddle"
  2. Click "Run", minimize electron app window
  3. Right click on the "Stop" button (previously the "Run" button from step 2) and select "Run Fiddle" from the dropdown menu to run a second instance:
    Dropdown Fiddle - Second Run

Linux results:

linux-fiddle

Windows results:

windows-fiddle

nktnet1 avatar Nov 26 '23 14:11 nktnet1

This is affected by key order:

// This gets `null`:
app.requestSingleInstanceLock({
	argv: [],
	nonsense: [1],
});
// whereas this gets through:
app.requestSingleInstanceLock({
	nonsense: [1],
	argv: [],
});

Also, odd-numbered length keys, and keys born in the year of the Snake appear to be unaffected:

{ a: [] } -> { a: [] }
{ b: [] } -> { b: [] }
{ m: [] } -> { m: [] }
{ aa: [] } -> null
{ ab: [] } -> null
{ am: [] } -> null
{ ba: [] } -> null
{ bb: [] } -> null
{ bm: [] } -> null
{ ma: [] } -> null
{ mb: [] } -> null
{ mm: [] } -> null
{ aaa: [] } -> { aaa: [] }
{ aab: [] } -> { aab: [] }
{ aam: [] } -> { aam: [] }
{ aba: [] } -> { aba: [] }
{ abb: [] } -> { abb: [] }
{ abm: [] } -> { abm: [] }
{ ama: [] } -> { ama: [] }
{ amb: [] } -> { amb: [] }
{ amm: [] } -> { amm: [] }
{ baa: [] } -> { baa: [] }
{ bab: [] } -> { bab: [] }
{ bam: [] } -> { bam: [] }
{ bba: [] } -> { bba: [] }
{ bbb: [] } -> { bbb: [] }
{ bbm: [] } -> { bbm: [] }
{ bma: [] } -> { bma: [] }
{ bmb: [] } -> { bmb: [] }
{ bmm: [] } -> { bmm: [] }
{ maa: [] } -> { maa: [] }
{ mab: [] } -> { mab: [] }
{ mam: [] } -> { mam: [] }
{ mba: [] } -> { mba: [] }
{ mbb: [] } -> { mbb: [] }
{ mbm: [] } -> { mbm: [] }
{ mma: [] } -> { mma: [] }
{ mmb: [] } -> { mmb: [] }
{ mmm: [] } -> { mmm: [] }
{ aaaa: [] } -> null
{ aaab: [] } -> null
...
{ aaaaa: [] } -> { aaaaa: [] }
...
{ mamba: [] } -> { mamba: [] }
...

Personally I think we should explore an astrological explanation for this behavior.

1j01 avatar Mar 07 '24 19:03 1j01

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

bump

nktnet1 avatar Jun 06 '24 11:06 nktnet1