Skip to content

Commit 53e5efc

Browse files
committed
os: add resources lookup for Flatpak
Implements support code to retrieve the absolute path of Ghostty's /app on the host file system, allowing shell integrations to function within Flatpak environment.
1 parent 1b52d5c commit 53e5efc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: src/os/resourcesdir.zig

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
const Allocator = std.mem.Allocator;
4+
const build_config = @import("../build_config.zig");
5+
const internal_os = @import("main.zig");
6+
const glib = @import("glib");
47

58
/// Gets the directory to the bundled resources directory, if it
69
/// exists (not all platforms or packages have it). The output is
@@ -27,6 +30,20 @@ pub fn resourcesDir(alloc: std.mem.Allocator) !?[]const u8 {
2730
}
2831
}
2932

33+
if (comptime build_config.flatpak) {
34+
if (internal_os.isFlatpak()) {
35+
const keyfile = glib.KeyFile.new();
36+
defer keyfile.unref();
37+
if (keyfile.loadFromFile("/.flatpak-info", .{}, null) == 0) return null;
38+
39+
// Get application path as seen from the host
40+
const app_path = std.mem.span(keyfile.getString("Instance", "app-path", null)) orelse return null;
41+
defer glib.free(app_path.ptr);
42+
43+
return try std.fs.path.join(alloc, &.{ app_path, "share", "ghostty" });
44+
}
45+
}
46+
3047
// This is the sentinel value we look for in the path to know
3148
// we've found the resources directory.
3249
const sentinel = switch (comptime builtin.target.os.tag) {

0 commit comments

Comments
 (0)