UnleashedRecomp icon indicating copy to clipboard operation
UnleashedRecomp copied to clipboard

Added Flatpak runtime detection

Open Jujstme opened this issue 11 months ago • 8 comments

This PR removes flatpak-specific preprocessor macros, leaving the game to figure out at runtime whether it's running under a flatpak environment or not.

To be more specific, this relies on checking the FLATPAK_ID environment variable, which is always set for sandboxed environments as described in the official documentation

For Unleashed Recompiled, FLATPAK_ID is set to io.github.hedge_dev.unleashedrecomp. This can be checked by entering the sandboxed environment and checking directly:

$ flatpak run --command=bash io.github.hedge_dev.unleashedrecomp
$ env | grep FLATPAK_ID

For Windows builds, the present PR bears no effect.

Jujstme avatar Mar 10 '25 18:03 Jujstme

Sorry for the confusion, i'm reopening the PR soon

Jujstme avatar Mar 10 '25 18:03 Jujstme

No worries, it has to be reviewed anyway.

DarioSamo avatar Mar 10 '25 18:03 DarioSamo

Feel free to just force push and clean the commit.

DarioSamo avatar Mar 10 '25 18:03 DarioSamo

FYI the CI is broken and doesn't actually pull changes from branches outside the repository, so the CI build will be based on the main branch.

blueskythlikesclouds avatar Mar 19 '25 20:03 blueskythlikesclouds

Why do we need a filesystem check? What was wrong with the environment variable approach?

blueskythlikesclouds avatar Mar 22 '25 09:03 blueskythlikesclouds

I don't think there's any difference, but if libportal uses this approach it's good to do the same imo.

Jujstme avatar Mar 22 '25 22:03 Jujstme

This approach is not reliable if a Flatpak application launches a native binary.

https://github.com/Zelda64Recomp/Zelda64Recomp/pull/572#issuecomment-2848821949

DarioSamo avatar May 03 '25 22:05 DarioSamo

Checking it out, most of these Flatpak specific codes can be thrown away if Unleashed Recomp is compliant with XDG Base Directory Specification. These env vars are used to figure out which directories are to be used for user data, if the env vars are not set or is empty, the fallback directories are used.

$XDG_DATA_HOME defines the base directory relative to which user-specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

$XDG_CONFIG_HOME defines the base directory relative to which user-specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

This is relevant to Flatpak because flatpak sets the following env vars automatically:

  • XDG_CONFIG_HOME to $HOME/.var/app/example.app.id/config; and
  • XDG_DATA_HOME to $HOME/.var/app/example.app.id/data.
  ➜ flatpak run --command=bash io.github.hedge_dev.unleashedrecomp
[📦 io.github.hedge_dev.unleashedrecomp ~]$ echo -e \
> $XDG_CONFIG_HOME \\n \
> $XDG_DATA_HOME
/home/raambm/.var/app/io.github.hedge_dev.unleashedrecomp/config 
 /home/raambm/.var/app/io.github.hedge_dev.unleashedrecomp/data
[📦 io.github.hedge_dev.unleashedrecomp ~]$ 

but it seems currently ~/.config/UnleashedRecomp and ~/.var/app/io.github.hedge_dev.unleashedrecomp/data are both hard coded. And in this MR the latter is dynamically figured out, even if not XDG compliant.

Where it should attempt to use $XDG_CONFIG_HOME/UnleashedRecomp and $XDG_DATA_HOME/UnleashedRecomp for the game config and game data respectively. Otherwise fallback to ~/.config/UnleashedRecomp and ~/.local/share/UnleashedRecomp respectively.

EDIT: This is related https://github.com/hedge-dev/UnleashedRecomp/issues/679

RushingAlien avatar May 23 '25 19:05 RushingAlien