Skip to content

Added Flatpak runtime detection #1301

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

Jujstme
Copy link

@Jujstme Jujstme commented Mar 10, 2025

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
Copy link
Author

Jujstme commented Mar 10, 2025

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

@DarioSamo
Copy link
Contributor

No worries, it has to be reviewed anyway.

@DarioSamo DarioSamo reopened this Mar 10, 2025
@DarioSamo
Copy link
Contributor

Feel free to just force push and clean the commit.

@Jujstme Jujstme deployed to external March 10, 2025 19:01 — with GitHub Actions Active
This reverts commit 44effe4, reversing
changes made to d7d7c20.
Copy link
Contributor

@DarioSamo DarioSamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me except for the part that I pointed out. Needs Steam Deck testing from someone to confirm it. Will deploy some builds to test.

@blueskythlikesclouds
Copy link
Member

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.

Copy link

@orowith2os orowith2os left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does UR need to know if it's running under Flatpak? If you need to look for specific files, you should be looking inside of the folders you own under the XDG base directory spec.

@blueskythlikesclouds
Copy link
Member

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

@Jujstme
Copy link
Author

Jujstme commented Mar 22, 2025

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

@DarioSamo
Copy link
Contributor

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

Zelda64Recomp/Zelda64Recomp#572 (comment)

@RushingAlien
Copy link

RushingAlien commented May 23, 2025

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 #679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants