Skip to content
Snippets Groups Projects
Commit 77f3acd4 authored by Ludovico de Nittis's avatar Ludovico de Nittis :palm_tree:
Browse files

wrap-discord: Bind Discord RPC sockets


Discord provides a mechanism called "Rich Presence" that allows games to
synchronize their state with Discord, e.g. showing status information in
the user's profile.

To make this work from inside a Pressure vessel container, we need to
bind-mount the Discord IPC sockets.
They are expected to be called `discord-ipc-`, followed by a number that
ranges from zero up to nine.
They are usually located under `XDG_RUNTIME_DIR`, with `TMPDIR`, `TMP`,
`TEMP` and `/tmp` used as fallback alternatives.

Example games that are known to be using the Discord sockets are:
VRChat, Among Us and osu!

Signed-off-by: default avatarLudovico de Nittis <ludovico.denittis@collabora.com>
parent 6158453a
No related branches found
No related tags found
1 merge request!552wrap-discord: Bind Discord RPC sockets
Pipeline #46549 passed
...@@ -147,6 +147,8 @@ pressure_vessel_wrap_lib = static_library( ...@@ -147,6 +147,8 @@ pressure_vessel_wrap_lib = static_library(
'runtime.h', 'runtime.h',
'supported-architectures.c', 'supported-architectures.c',
'supported-architectures.h', 'supported-architectures.h',
'wrap-discord.c',
'wrap-discord.h',
'wrap-flatpak.c', 'wrap-flatpak.c',
'wrap-flatpak.h', 'wrap-flatpak.h',
'wrap-home.h', 'wrap-home.h',
......
/*
* Copyright 2017 Discord
* Copyright 2021-2023 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "wrap-discord.h"
/* Adapted from discord-rpc v3.4.0 */
static const char *
get_temp_dir (void)
{
const char *temp_dir;
temp_dir = g_getenv ("XDG_RUNTIME_DIR");
if (temp_dir == NULL)
temp_dir = g_getenv ("TMPDIR");
if (temp_dir == NULL)
temp_dir = g_getenv ("TMP");
if (temp_dir == NULL)
temp_dir = g_getenv ("TEMP");
if (temp_dir == NULL)
temp_dir = "/tmp";
return temp_dir;
}
void
pv_wrap_add_discord_args (FlatpakBwrap *sharing_bwrap)
{
g_autoptr(GDir) dir = NULL;
const char *temp_dir = get_temp_dir ();
const char *member;
dir = g_dir_open (temp_dir, 0, NULL);
if (dir == NULL)
return;
for (member = g_dir_read_name (dir);
member != NULL;
member = g_dir_read_name (dir))
{
/* Bind the Discord Rich Presence IPC sockets. They are expected to be
* called `discord-ipc-`, followed by a number.
*/
if (g_str_has_prefix (member, "discord-ipc-"))
{
g_autofree gchar *host_socket =
g_build_filename (temp_dir, member, NULL);
g_autofree gchar *container_socket =
g_strdup_printf ("/run/user/%d/%s", getuid (), member);
flatpak_bwrap_add_args (sharing_bwrap,
"--ro-bind",
host_socket,
container_socket,
NULL);
}
}
}
/*
* Copyright 2021-2023 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <glib.h>
#include "libglnx.h"
#include "flatpak-bwrap-private.h"
void pv_wrap_add_discord_args (FlatpakBwrap *sharing_bwrap);
...@@ -342,6 +342,7 @@ pv_wrap_share_sockets (PvEnviron *container_env, ...@@ -342,6 +342,7 @@ pv_wrap_share_sockets (PvEnviron *container_env,
flatpak_run_add_resolved_args (sharing_bwrap); flatpak_run_add_resolved_args (sharing_bwrap);
flatpak_run_add_journal_args (sharing_bwrap); flatpak_run_add_journal_args (sharing_bwrap);
pv_wrap_add_pipewire_args (sharing_bwrap, container_env); pv_wrap_add_pipewire_args (sharing_bwrap, container_env);
pv_wrap_add_discord_args (sharing_bwrap);
} }
flatpak_bwrap_populate_runtime_dir (sharing_bwrap, NULL); flatpak_bwrap_populate_runtime_dir (sharing_bwrap, NULL);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "flatpak-bwrap-private.h" #include "flatpak-bwrap-private.h"
#include "flatpak-exports-private.h" #include "flatpak-exports-private.h"
#include "runtime.h" #include "runtime.h"
#include "wrap-discord.h"
#include "wrap-pipewire.h" #include "wrap-pipewire.h"
typedef enum typedef enum
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment