Added Flatpak runtime detection
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.
Sorry for the confusion, i'm reopening the PR soon
No worries, it has to be reviewed anyway.
Feel free to just force push and clean the commit.
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.
Why do we need a filesystem check? What was wrong with the environment variable approach?
I don't think there's any difference, but if libportal uses this approach it's good to do the same imo.
This approach is not reliable if a Flatpak application launches a native binary.
https://github.com/Zelda64Recomp/Zelda64Recomp/pull/572#issuecomment-2848821949
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_HOMEdefines the base directory relative to which user-specific data files should be stored. If$XDG_DATA_HOMEis either not set or empty, a default equal to$HOME/.local/shareshould be used.
$XDG_CONFIG_HOMEdefines the base directory relative to which user-specific configuration files should be stored. If$XDG_CONFIG_HOMEis either not set or empty, a default equal to$HOME/.configshould be used.
This is relevant to Flatpak because flatpak sets the following env vars automatically:
-
XDG_CONFIG_HOMEto$HOME/.var/app/example.app.id/config; and -
XDG_DATA_HOMEto$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