diff --git a/src/apprt/browser.zig b/src/apprt/browser.zig index d60776a6a..3b1aa468f 100644 --- a/src/apprt/browser.zig +++ b/src/apprt/browser.zig @@ -1,2 +1,4 @@ +const internal_os = @import("../os/main.zig"); +pub const resourcesDir = internal_os.resourcesDir; pub const App = struct {}; pub const Window = struct {}; diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 77c22c7f5..31dd2f46b 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -23,6 +23,8 @@ const Config = configpkg.Config; const log = std.log.scoped(.embedded_window); +pub const resourcesDir = internal_os.resourcesDir; + pub const App = struct { /// Because we only expect the embedding API to be used in embedded /// environments, the options are extern so that we can expose it diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 924737074..6e131435d 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -35,6 +35,8 @@ const darwin_enabled = builtin.target.os.tag.isDarwin() and const log = std.log.scoped(.glfw); +pub const resourcesDir = internal_os.resourcesDir; + pub const App = struct { app: *CoreApp, config: Config, diff --git a/src/apprt/none.zig b/src/apprt/none.zig index 76a0a8ecb..76faa88af 100644 --- a/src/apprt/none.zig +++ b/src/apprt/none.zig @@ -1,2 +1,4 @@ +const internal_os = @import("../os/main.zig"); +pub const resourcesDir = internal_os.resourcesDir; pub const App = struct {}; pub const Surface = struct {}; diff --git a/src/global.zig b/src/global.zig index 76b57898b..668d2faec 100644 --- a/src/global.zig +++ b/src/global.zig @@ -171,10 +171,7 @@ pub const GlobalState = struct { // Find our resources directory once for the app so every launch // hereafter can use this cached value. - self.resources_dir = rd: { - if (@hasDecl(apprt.runtime, "resourcesDir")) break :rd try apprt.runtime.resourcesDir(self.alloc); - break :rd try internal_os.resourcesDir(self.alloc); - }; + self.resources_dir = try apprt.runtime.resourcesDir(self.alloc); errdefer self.resources_dir.deinit(self.alloc); // Setup i18n diff --git a/src/os/resourcesdir.zig b/src/os/resourcesdir.zig index d4287c1bd..278de44fc 100644 --- a/src/os/resourcesdir.zig +++ b/src/os/resourcesdir.zig @@ -3,12 +3,13 @@ const builtin = @import("builtin"); const Allocator = std.mem.Allocator; pub const ResourcesDir = struct { + /// Avoid accessing these directly, use the app() and host() methods instead. app_path: ?[]const u8 = null, host_path: ?[]const u8 = null, /// Free resources held. Requires the same allocator as when resourcesDir() /// is called. - pub fn deinit(self: *ResourcesDir, alloc: std.mem.Allocator) void { + pub fn deinit(self: *ResourcesDir, alloc: Allocator) void { if (self.app_path) |p| alloc.free(p); if (self.host_path) |p| alloc.free(p); } @@ -36,7 +37,7 @@ pub const ResourcesDir = struct { /// /// This is highly Ghostty-specific and can likely be generalized at /// some point but we can cross that bridge if we ever need to. -pub fn resourcesDir(alloc: std.mem.Allocator) !ResourcesDir { +pub fn resourcesDir(alloc: Allocator) !ResourcesDir { // Use the GHOSTTY_RESOURCES_DIR environment variable in release builds. // // In debug builds we try using terminfo detection first instead, since