Skip to content

Commit c9c8957

Browse files
committed
Add getAppDir implementation for iOS
1 parent b5bf967 commit c9c8957

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
@@ -92,16 +92,24 @@ pub const App = struct {
9292
}
9393
};
9494

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

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

0 commit comments

Comments
 (0)