Skip to content

Add Snap support for portals #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/client_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static inline int *alloc_fd_array(int n)
return fds;
}

// Helper to check if we are running inside a flatpak
static int in_flatpak(void)
// Helper to check if we are running inside a sandboxed framework like Flatpak or Snap
static int in_sandbox(void)
{
static int status = -1;

Expand All @@ -120,6 +120,10 @@ static int in_flatpak(void)

r = lstat("/.flatpak-info", &sb);
status = r == 0 && sb.st_size > 0;

if (getenv("SNAP") != NULL) {
status = 1;
}
}

return status;
Expand Down Expand Up @@ -228,7 +232,7 @@ static int make_request(DBusConnection *bus, int native, int use_pidfds, const c
native,
use_pidfds);

// If we are inside a flatpak we need to talk to the portal instead
// If we are inside a Flatpak or Snap we need to talk to the portal instead
const char *dest = native ? DAEMON_DBUS_NAME : PORTAL_DBUS_NAME;
const char *path = native ? DAEMON_DBUS_PATH : PORTAL_DBUS_PATH;
const char *iface = native ? DAEMON_DBUS_IFACE : PORTAL_DBUS_IFACE;
Expand Down Expand Up @@ -302,7 +306,7 @@ static int gamemode_request(const char *method, pid_t for_pid)
int native;
int res = -1;

native = !in_flatpak();
native = !in_sandbox();

/* pid[0] is the client, i.e. the game
* pid[1] is the requestor, i.e. this process
Expand Down