coc-discord-rpc icon indicating copy to clipboard operation
coc-discord-rpc copied to clipboard

fix: Cannot read properties of null reading "write"

Open xhayper opened this issue 3 years ago • 16 comments

Cause: This was caused by 2 issue stacking over each other

  1. neovim OR coc set the $TMPDIR to /var/folders/tg/**/T/nvim**
  2. macOS returning /var/folders/tg/**/T/** via $TMPDIR when the real tmp directory is /private/var/folders/tg/**/T/**

Fix: What we do is we loop through the path variable that discord-rpc search and fix the path, 1. Loop through the path variable 2. Turn the path into real path 3. check if it contains nvim 4. if yes, get the parent directory 5. if no, continue 6. set that variable to modified one

Note:

  • This was tested on a macOS machine, running on macOS 12.5, This still need to be tested on linux machine too.
  • on macOS, /var is a symlink to /private/var, i am not sure if net package can handle symlink properly, so the i did the fs.realPath, I am not taking any risk either.

Fixes #59 Fixes #56

xhayper avatar Jul 24 '22 11:07 xhayper

Before fix: Screen Shot 2022-07-24 at 6 23 33 PM

After fix: Screen Shot 2022-07-24 at 6 42 32 PM

Discord IPC Path: Screen Shot 2022-07-24 at 6 43 51 PM

xhayper avatar Jul 24 '22 11:07 xhayper

Thanks for this PR, I'm glad you found a solution to this problem, I'm going to make a Linux VM environment so I can test it too.

I'll keep this PR open until we see if it's right.

leonardssh avatar Jul 24 '22 11:07 leonardssh

I gonna test this on an Arch Linux VM with KDE Plasma and SDDM.

xhayper avatar Jul 24 '22 13:07 xhayper

~~Works great. image~~

Nevermind, It work without the patch.

xhayper avatar Jul 24 '22 13:07 xhayper

Ah... discord-ipc-{number} in this case is inside $XDG_RUNTIME_DIR/, which we have no problem with, BUT HOWEVER image TMPDIR is wrong here, Which might explain why people who are using X doesn't have the error.

xhayper avatar Jul 24 '22 14:07 xhayper

Ah... discord-ipc-{number} in this case is inside XDG_RUNTIME_DIR, which we have no problem with, BUT HOWEVER image TMPDIR is wrong here, Which might explain why people who are using X doesn't have the error.

It makes perfect sense.

leonardssh avatar Jul 24 '22 14:07 leonardssh

Trying this on Wayland version of plasma.

xhayper avatar Jul 24 '22 14:07 xhayper

My assumption are correct. image

xhayper avatar Jul 24 '22 14:07 xhayper

Yup! This patch fix it! image

xhayper avatar Jul 24 '22 14:07 xhayper

Conclusion: discord-rpc will breaks under non-x display server with coc / neovim. Why? coc / neovim set $TMPDIR / $TMP / $TEMP to $TEMP_DIR/nvim**.

xhayper avatar Jul 24 '22 14:07 xhayper

Alright, I got tired of discordjs/RPC, I made my own fork of discordjs/RPC that's up to date, use typescript and can specify your own way to find the ipc path.

xhayper avatar Jul 31 '22 15:07 xhayper

If you want, I can port to my discord-rpc for this project in separate PR.

xhayper avatar Jul 31 '22 16:07 xhayper

A PR in this regard would be welcome. I also want to port my vscode extension to your discord-rpc fork.

leonardssh avatar Jul 31 '22 18:07 leonardssh

Alright! I just need someone to test if the extension works under Snap version of discord, It's confirmed to work on macOS, Windows and non-snap discord on linux.

xhayper avatar Jul 31 '22 23:07 xhayper

Yep, the thing works with snap versions of discord.

xhayper avatar Aug 04 '22 00:08 xhayper

Thank you for your work @xhayper!

SeniorMars avatar Aug 04 '22 02:08 SeniorMars