Skip to content

core, gtk: implement host resources dir for Flatpak #6661

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 1 commit into
base: main
Choose a base branch
from

Conversation

alaviss
Copy link
Contributor

@alaviss alaviss commented Mar 10, 2025

Introduces host resources directory as a new concept: A directory containing application resources that can only be accessed from the host operating system. This is significant for sandboxed application runtimes like Flatpak where shells spawned on the host should have access to application resources to enable integrations.

Alongside this, apprt is now allowed to override the resources lookup logic.

@alaviss alaviss force-pushed the push-qrqtympzwnox branch from 4d88103 to 53e5efc Compare March 10, 2025 21:44
@alaviss alaviss force-pushed the push-qrqtympzwnox branch from 53e5efc to f76d334 Compare March 11, 2025 01:49
@alaviss alaviss changed the title os: add resources lookup for Flatpak flatpak, termio: use host paths for resources Mar 11, 2025
@alaviss
Copy link
Contributor Author

alaviss commented Mar 11, 2025

Changes in v2:

  • New FlatpakInfo struct that provides methods for querying information about the current Flatpak.
  • Only resolve host paths for termio.Exec instead of everything. This fixes issues with themes as Ghostty cannot access the host paths directly and must use /app paths.

@alaviss alaviss force-pushed the push-qrqtympzwnox branch from f76d334 to 4982c0d Compare March 11, 2025 23:19
@alaviss alaviss changed the title flatpak, termio: use host paths for resources core, gtk: implement host resources dir for Flatpak Mar 11, 2025
@alaviss
Copy link
Contributor Author

alaviss commented Mar 11, 2025

Changes in v3:

  • Dropped FlatpakInfo as it is not very useful outside of the host resources directory case.
  • GlobalState will now resolve *resources_dir with apprt.runtime implementation if available.
  • Added a new parameter to resourcesDir to request for a host-accessible resource directory if available.
  • Added host_resources_dir to GlobalState. I'm not entirely sure whether this is the best way, but it's certainly the cleanest to me.
  • Removed additional logic in termio.Exec.

@alaviss alaviss force-pushed the push-qrqtympzwnox branch 4 times, most recently from e1e708a to 9aa7f5d Compare March 15, 2025 07:25
@alaviss
Copy link
Contributor Author

alaviss commented Mar 15, 2025

Changes in v4:

@alaviss alaviss marked this pull request as ready for review March 15, 2025 07:28
@alaviss alaviss requested review from a team as code owners March 15, 2025 07:28
src/global.zig Outdated
@@ -170,9 +176,18 @@ pub const GlobalState = struct {

// Find our resources directory once for the app so every launch
// hereafter can use this cached value.
self.resources_dir = try internal_os.resourcesDir(self.alloc);
self.resources_dir = rd: {
if (@hasDecl(apprt.runtime, "resourcesDir")) break :rd try apprt.runtime.resourcesDir(self.alloc, false);
Copy link
Member

Choose a reason for hiding this comment

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

We try to avoid @hasDecl in new apprt-related code, although I'm not exactly sure what's a better alternative here

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Its better, but I still don't love this approach...

Calling resourcesDir twice once for guest once for host is not great, especially since 99% of users (today, but a significant number) are not running in a sandboxed mode. Its just waste.

A perhaps better approach would be to return a struct instead so we can get all the info in one call. But stepping back its not clear to me if we ever need both, would it be more useful to redocument resourcesDir as always being host accessible?

@alaviss
Copy link
Contributor Author

alaviss commented Mar 15, 2025

But stepping back its not clear to me if we ever need both

For platforms like Flatpak the host-accessible directory is usually non-accessible in the sandbox, but the sandbox path is not accessible outside.

We need sandbox-accessible paths for things like reading bundled themes, and only termio needs the host-accessible one since that's where host processes are launched. So on Flatpak you'd want both to implement all the features.

@alaviss alaviss force-pushed the push-qrqtympzwnox branch from 9aa7f5d to de54443 Compare March 15, 2025 20:15
@alaviss
Copy link
Contributor Author

alaviss commented Mar 15, 2025

Changes in v5:

  • Rebased to main
  • New ResourcesDir struct that abstracts over host/app paths selection, removing the need to allocate two paths for non-sandboxed cases, as well as reducing the resourcesDir call count to 1.

Introduces host resources directory as a new concept: A directory
containing application resources that can only be accessed from the host
operating system. This is significant for sandboxed application runtimes
like Flatpak where shells spawned on the host should have access to
application resources to enable integrations.

Alongside this, apprt is now allowed to override the resources lookup
logic.
@alaviss alaviss force-pushed the push-qrqtympzwnox branch from de54443 to 696d3b2 Compare March 21, 2025 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants