40 lines
2 KiB
Markdown
40 lines
2 KiB
Markdown
---
|
|
title: Discord and Spotify for Linux and xdg-mime
|
|
date: 2019-05-05 04:26
|
|
author: Lynne
|
|
categories: [Scripts, Technology]
|
|
---
|
|
|
|
The bug
|
|
-------
|
|
|
|
I've noticed that Discord for Linux takes a very, very long time to start up - sometimes in the order of hours. During this time, my laptop gets very hot. I eventually decided to look into this and found that several instances of `xdg-mime` were taking up 100% CPU. Killing them caused Discord to open instantly.
|
|
|
|
Apparently this issue is present with Spotify too. This fix will work for both of them.
|
|
|
|
<!--more-->
|
|
You can fix this manually by killing the various `xdg-mime` processes every time you open Discord, but that's annoying. You can work around it permanently by creating a custom wrapper around `xdg-mime` and placing it somewhere in your `$PATH` with higher priority than `/usr/local/bin`, or wherever `xdg-mime` is on your system. In this guide, we'll use `/usr/local/bin`.
|
|
|
|
The fix
|
|
-------
|
|
|
|
Create a file called `xdg-mime` in `/usr/local/bin` by running `sudo nano /usr/local/bin/xdg-mime`. Paste this in the file:
|
|
|
|
```bash
|
|
#!/usr/bin/sh
|
|
if [[ "$@" == *"x-scheme-handler/discord"* ]] || [[ "$@" == *"x-scheme-handler/spotify"* ]]; then
|
|
/usr/bin/true
|
|
else
|
|
/usr/bin/xdg-mime $@
|
|
fi
|
|
```
|
|
|
|
If `xdg-mime` isn't in `/usr/bin` on your machine (you can check where it is by running `which xdg-mime`), you'll need to edit that script to match its location.
|
|
|
|
Save it with ctrl-o, then exit with ctrl-x. This should fix the problem.
|
|
|
|
The explanation
|
|
---------------
|
|
|
|
For whatever reason, Discord and Spotify have a lot of trouble registering themselves with `xdg-mime`. This causes them to hang for minutes or hours on startup. The workaround outlined above simply checks for what you're trying to do with xdg-mime, and if you're trying to modify the scheme handlers for Discord or Spotify - the process that causes these apps to hang - it carries on without doing anything. If you're doing anything else, it passes you through to the real `xdg-mime`.
|
|
|