Skip to content

Commit 4ee19ff

Browse files
carson-katrikrichprollsch
authored andcommitted
Add getAppDir implementation for iOS
1 parent 67eb795 commit 4ee19ff

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/.DS_Store

6 KB
Binary file not shown.

src/app.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,24 @@ pub const App = struct {
9494
}
9595
};
9696

97+
fn getAppDir(allocator: Allocator) ![]const u8 {
98+
if (@import("builtin").os.tag == .ios) {
99+
// std.fs.getAppDataDir is not available on iOS, so we inline the same macOS implementation here.
100+
const home_dir = std.posix.getenv("HOME") orelse {
101+
return error.AppDataDirUnavailable;
102+
};
103+
return std.fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", "lightpanda" });
104+
} else {
105+
return try std.fs.getAppDataDir(allocator, "lightpanda");
106+
}
107+
}
108+
97109
fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
98110
if (@import("builtin").is_test) {
99111
return allocator.dupe(u8, "/tmp") catch unreachable;
100112
}
101113

102-
if (@import("builtin").os.tag == .ios) {
103-
return null; // getAppDataDir is not available on iOS
104-
}
105-
106-
const app_dir_path = std.fs.getAppDataDir(allocator, "lightpanda") catch |err| {
114+
const app_dir_path = getAppDir(allocator) catch |err| {
107115
log.warn(.app, "get data dir", .{ .err = err });
108116
return null;
109117
};

0 commit comments

Comments
 (0)