Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#79744 - [code] Editor opens '/usr/lib/code/code.js' on every start

Attached to Project: Arch Linux
Opened by Hanabishi (Hanabishi) - Wednesday, 20 September 2023, 17:10 GMT
Last edited by Massimiliano Torromeo (mtorromeo) - Thursday, 28 September 2023, 15:14 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Massimiliano Torromeo (mtorromeo)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

Description:

Code opens an editor with '/usr/lib/code/code.js' on every start if electron flags are present.
Introduced by https://gitlab.archlinux.org/archlinux/packaging/packages/code/-/commit/08dca5a4bc70f6fd433a468d6121d4d944081d16

Command line looks like '/usr/lib/electron25/electron --ozone-platform-hint=auto --disable-gpu-sandbox /usr/lib/code/code.js'.

Additional info:
* package versions:
code 1.82.2-2
electron25 25.6.0-1

Steps to reproduce:
1. Define some electron flags in ~/.config/electron25-flags.conf (e.g. '--ozone-platform-hint=auto')
2. Run 'code'.
This task depends upon

Closed by  Massimiliano Torromeo (mtorromeo)
Thursday, 28 September 2023, 15:14 GMT
Reason for closing:  Fixed
Additional comments about closing:  code-1.82.2-3
Comment by Massimiliano Torromeo (mtorromeo) - Wednesday, 20 September 2023, 19:18 GMT
It's weird that with the flags I am using the command line is "/usr/lib/electron25/electron /usr/lib/code/out/cli.js --ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-webrtc-pipewire-capturer /usr/lib/code/code.js" and it doesn't open the code.js file.

I have to do a bit of debugging.
Comment by Hanabishi (Hanabishi) - Thursday, 21 September 2023, 02:15 GMT
The problem is in https://gitlab.archlinux.org/archlinux/packaging/packages/code/-/blob/08dca5a4bc70f6fd433a468d6121d4d944081d16/code.js#L16

It removes the first argument, but 'process.argv' actually contains the full command line at this point, so '/usr/lib/code/code.js' is not the first argument and '/usr/lib/electron25/electron' is being removed instead.

Considering that the script last time updated 2 years ago, I think there is some behavior changes in newer electron versions. I am not sure why it opens the file sometimes and sometimes don't though. But '/usr/lib/code/code.js' is always present in the command line.
Comment by Hanabishi (Hanabishi) - Thursday, 21 September 2023, 02:25 GMT
Basically we need to patch it like so:
Comment by Hanabishi (Hanabishi) - Thursday, 21 September 2023, 02:53 GMT
But actually this is dirty. Ideally we want to strip all that electron stuff and its flags entirely.

So I think it will be better to do:
Comment by Hanabishi (Hanabishi) - Thursday, 21 September 2023, 11:06 GMT
Simplified it a bit, as splice(0, 0) does nothing anyway, index check is not required.
Comment by Sebastian Wiesner (lunaryorn) - Wednesday, 27 September 2023, 17:31 GMT
With electron25-flags "--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations" I get code.js opened every time I start code, with "--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-webrtc-pipewire-capturer" I don't. Seems to depend on the kind of flag that's passed last.

If I revert the last commit https://gitlab.archlinux.org/archlinux/packaging/packages/code/-/commit/08dca5a4bc70f6fd433a468d6121d4d944081d16 code never opens code.js.
Comment by Massimiliano Torromeo (mtorromeo) - Thursday, 28 September 2023, 13:00 GMT
The proposed patch didn't work for me or broke other features like saving files with sudo, but I think I managed to fix it for good.

I tried with different number of electron flags and code flags, and it seems to be working fine here.

Give a try to code-1.82.2-3
Comment by Hanabishi (Hanabishi) - Thursday, 28 September 2023, 13:13 GMT
Yeah, '--' presumably supposed to be put before codeflags.

I also noticed that the current script does not capture 'code.js' itself, only flags prior it. If this is not intended, you need to do 'findIndex(...) + 1' to remove it.
Comment by Massimiliano Torromeo (mtorromeo) - Thursday, 28 September 2023, 13:15 GMT
It is intended. I am more interested in confirmation that everything else works.
Comment by Hanabishi (Hanabishi) - Thursday, 28 September 2023, 13:27 GMT
Then looks good to me.

Loading...