Skip to content

Instantly share code, notes, and snippets.

@Shika-B
Last active March 11, 2023 16:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Shika-B/fc15c63d66716347df8627c0d42959b5 to your computer and use it in GitHub Desktop.
Save Shika-B/fc15c63d66716347df8627c0d42959b5 to your computer and use it in GitHub Desktop.
Discord lagging during long calls on Linux

My discord was lagging increasingly during long calls on my Manjaro installation. I searched a bit on the Wiki but the fix shared there didn't work for. What worked for me is this answer on the Discord support forum, that I will detail a bit here. Start by moving to the right folder:

cd ~/.config/discord/<your_version>/modules/discord_desktop_core

Then, depending on whether you are a javascript developer or not, you may need to install the npm package of your distribution. On Arch/Manjaro, yay -S npm will do. Once this is done, unpack the core.asar file with

npx asar extract core.asar core

then open the discord_desktop_core folder with your favorite editor. Now we need to change two things.

  • Change the setTrayIcon in the discord_desktop_core/core/app/systemTray.js file so that it does nothing
  • Update the discord_desktop_core/index.js file to make it look for a core folder instead of a core.asar file

For the first part, open the file and replace the function with

function setTrayIcon(icon) {
  return;
  // Keep track of last set icon
  currentIcon = trayIcons[icon]; // If icon is null, hide the tray icon.  Otherwise show
  // These calls also check for tray existence, so minimal cost.

  if (icon == null) {
    hide();
    return;
  } else {
    show();
  } // Keep mute/deafen menu items in sync with client, based on icon states


  const muteIndex = contextMenu.indexOf(menuItems[MenuItems.MUTE]);
  const deafenIndex = contextMenu.indexOf(menuItems[MenuItems.DEAFEN]);
  const voiceConnected = contextMenu[muteIndex].visible;
  let shouldSetContextMenu = false;

  if (currentIcon !== trayIcons.DEFAULT && currentIcon !== trayIcons.UNREAD) {
    // Show mute/deaf controls
    if (!voiceConnected) {
      contextMenu[muteIndex].visible = true;
      contextMenu[deafenIndex].visible = true;
      shouldSetContextMenu = true;
    }

    if (currentIcon === trayIcons.DEAFENED) {
      contextMenu[muteIndex].checked = true;
      contextMenu[deafenIndex].checked = true;
      shouldSetContextMenu = true;
    } else if (currentIcon === trayIcons.MUTED) {
      contextMenu[muteIndex].checked = true;
      contextMenu[deafenIndex].checked = false;
      shouldSetContextMenu = true;
    } else if (contextMenu[muteIndex].checked || contextMenu[deafenIndex].checked) {
      contextMenu[muteIndex].checked = false;
      contextMenu[deafenIndex].checked = false;
      shouldSetContextMenu = true;
    }
  } else if (voiceConnected) {
    contextMenu[muteIndex].visible = false;
    contextMenu[deafenIndex].visible = false;
    shouldSetContextMenu = true;
  }

  shouldSetContextMenu && setContextMenu();
  atomTray != null && atomTray.setImage(_electron.nativeImage.createFromPath(currentIcon));
}

For the second part, replace the require call in the index.js file with

module.exports = require('./core');

Close any instance of discord you have running (be sure to close it and not just minimize it, in case you're not sure reboot your computer) and reopen Discord. You will probably need to apply this fix at each Discord update.

@real-F-00
Copy link

the fix seems to work, thanks for this guide.

@Shika-B
Copy link
Author

Shika-B commented Sep 4, 2022

the fix seems to work, thanks for this guide.

Np !

@IvarWithoutBones
Copy link

IvarWithoutBones commented Oct 15, 2022

Thanks for this! Seems to fix the problem for me as well :)

I wrote a small script that can automate these steps, with that updates wont be such a pain:

#!/usr/bin/env bash

# This fixes an issue with Discord where being in a call for a long time causes the client to become unresponsive.
# For more information see https://gist.github.com/Shika-B/fc15c63d66716347df8627c0d42959b5

# Required dependencies: coreutils, gnused, and the 'asar' package from NPM. 

set -euo pipefail

path="$(find "$HOME/.config/discord" -name discord_desktop_core -type d | tail -n1)"
if [ -d "$path/core-patched" ]; then
    echo "already patched, doing nothing"
    exit
fi

tmpdir=$(mktemp -dt asar-XXXXXXXXXX)
trap 'rm -rf "$tmpdir"' EXIT

echo "patching $path/core.asar"
asar extract "$path/core.asar" "$tmpdir"
sed -i '/^function setTrayIcon.*/a return;' "$tmpdir/app/systemTray.js"

echo "copying patched module to $path/core-patched"
cp -r "$tmpdir" "$path/core-patched"

echo "replacing reference to core.asar with the patched module"
sed -i.bak "s/require('.\/core\.asar')/require('.\/core-patched')/g" "$path/index.js"
echo "wrote a backup of index.js to $path/index.js.bak"

echo "patching was successful. you can now restart discord"

@real-F-00
Copy link

@IvarWithoutBones i was gonna do this myself but i was too lazy to do it, since i use canary i adapted the script to look for $HOME/.config/discordcanary thank you very much.

@IvarWithoutBones
Copy link

Happy to help!

@yasamnoya
Copy link

Thanks! It worked well.

@IvarWithoutBones
Copy link

IvarWithoutBones commented Oct 28, 2022

I noticed upon a recent update that the old version of this script breaks when multiple version folders are found, you can replace line 10 with the following to fix it:

path="$(find "$HOME/.config/discord" -name discord_desktop_core -type d | tail -n1)"

This just selects the path with the highest version, instead of erroring out because it attempts to select multiple versions.

@Prayag2
Copy link

Prayag2 commented Dec 7, 2022

It works! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment