pypresence
pypresence copied to clipboard
Discord never detected in Linux enviroment without `XDG_RUNTIME_DIR`
As the title describes pypresence doesn't detect Discord in an Linux enviroment where the XDG_RUNTIME_DIR
is unset. I've been trying to create a python script which gets started at boot using crontab
. Using this starting method the needed XDG_RUNTIME_DIR
variable won't be set and thus pypresence won't detect the location in which the runtime directory is located.
This hapens even when it is set by the system in the user's graphical space later on. The discord-ipc-*
file won't be placed within the tempdir on my system either, so that workaround won't work I've noticed.
The issue has been narrowed to the line 32 of utils.py
shown below; https://github.com/qwertyquerty/pypresence/blob/690320919144269885cb6c6be8c41d63a49365ec/pypresence/utils.py#L31-L33
Kinda already know how it needs to changed but need to find time and energy to do so. In the mean time I will leave this issue here so it's known.
Try using this
def get_ipc_path(pipe=None):
ipc = 'discord-ipc-'
if pipe:
ipc = f"{ipc}{pipe}"
if sys.platform in ('linux', 'darwin'):
env_keys = ('XDG_RUNTIME_DIR', 'TMPDIR', 'TMP', 'TEMP')
for env_key in env_keys:
tempdir = (os.environ.get(env_key)
paths = ['.', 'snap.discord', 'app/com.discordapp.Discord', 'app/com.discordapp.DiscordCanary']
That won't work for this specific thing. In Linux I'm guessing crontab
is started within an enviroment which doesn't have any of those enviremental variables set. Becouse of this it seems that any program started by it won't have user or shell specific enviroment variables.
One can't rely on enviroment variables within this edgecase
What's wrong with crontab -e
? Are you positive this is an issue with pypresence?
https://stackoverflow.com/a/10657111
Yes I would argue this is an issue with pypresence. Not every user environment has the same environment variables. I would not expect people to need to know that the XDG_RUNTIME_DIR
variable needs to be set to use this library since this would require digging into the code of pypresence.
Crontab has options to add environment variables and runs programs using them, yes. But with the case of the crontab daemon, it only starts programs with some variables set by default (see the crontab manual) and I would suspect that that isn't the only case where the XDG_RUNTIME_DIR
variable isn't available.
When this this variable is set elsewhere on a system, like it will eventually in my case, it won't be detected by my scripts because those have already started in another environment. Making sure it does in fact detect Discord in this case just requires checking additional standard location which I've done in pull request #217
Hope this explains it all well enough
Ther's a fix and little testing script ready within pull #218. Took some time since I fully missed the responce I got on there earlier