Add getAppDir implementation for iOS

This commit is contained in:
Carson Katri
2025-09-18 16:36:03 -04:00
committed by Pierre Tachoire
parent 901294a180
commit 3b5c7b0c25
2 changed files with 13 additions and 5 deletions

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -94,16 +94,24 @@ pub const App = struct {
} }
}; };
fn getAppDir(allocator: Allocator) ![]const u8 {
if (@import("builtin").os.tag == .ios) {
// std.fs.getAppDataDir is not available on iOS, so we inline the same macOS implementation here.
const home_dir = std.posix.getenv("HOME") orelse {
return error.AppDataDirUnavailable;
};
return std.fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", "lightpanda" });
} else {
return try std.fs.getAppDataDir(allocator, "lightpanda");
}
}
fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 { fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
if (@import("builtin").is_test) { if (@import("builtin").is_test) {
return allocator.dupe(u8, "/tmp") catch unreachable; return allocator.dupe(u8, "/tmp") catch unreachable;
} }
if (@import("builtin").os.tag == .ios) { const app_dir_path = getAppDir(allocator) catch |err| {
return null; // getAppDataDir is not available on iOS
}
const app_dir_path = std.fs.getAppDataDir(allocator, "lightpanda") catch |err| {
log.warn(.app, "get data dir", .{ .err = err }); log.warn(.app, "get data dir", .{ .err = err });
return null; return null;
}; };