mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
store iid in application data directory
This commit is contained in:
28
src/app.zig
28
src/app.zig
@@ -4,6 +4,8 @@ const Loop = @import("jsruntime").Loop;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Telemetry = @import("telemetry/telemetry.zig").Telemetry;
|
||||
|
||||
const log = std.log.scoped(.app);
|
||||
|
||||
pub const RunMode = enum {
|
||||
serve,
|
||||
fetch,
|
||||
@@ -13,6 +15,7 @@ pub const RunMode = enum {
|
||||
// might need.
|
||||
pub const App = struct {
|
||||
loop: *Loop,
|
||||
app_dir_path: ?[]const u8,
|
||||
allocator: Allocator,
|
||||
telemetry: Telemetry,
|
||||
|
||||
@@ -23,19 +26,42 @@ pub const App = struct {
|
||||
loop.* = try Loop.init(allocator);
|
||||
errdefer loop.deinit();
|
||||
|
||||
const telemetry = Telemetry.init(allocator, run_mode);
|
||||
const app_dir_path = getAndMakeAppDir(allocator);
|
||||
const telemetry = Telemetry.init(allocator, run_mode, app_dir_path);
|
||||
errdefer telemetry.deinit();
|
||||
|
||||
return .{
|
||||
.loop = loop,
|
||||
.allocator = allocator,
|
||||
.telemetry = telemetry,
|
||||
.app_dir_path = app_dir_path,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *App) void {
|
||||
if (self.app_dir_path) |app_dir_path| {
|
||||
self.allocator.free(app_dir_path);
|
||||
}
|
||||
|
||||
self.telemetry.deinit();
|
||||
self.loop.deinit();
|
||||
self.allocator.destroy(self.loop);
|
||||
}
|
||||
};
|
||||
|
||||
fn getAndMakeAppDir(allocator: Allocator) ?[]const u8 {
|
||||
const app_dir_path = std.fs.getAppDataDir(allocator, "lightpanda") catch |err| {
|
||||
log.warn("failed to get lightpanda data dir: {}", .{err});
|
||||
return null;
|
||||
};
|
||||
|
||||
std.fs.makeDirAbsolute(app_dir_path) catch |err| switch (err) {
|
||||
error.PathAlreadyExists => return app_dir_path,
|
||||
else => {
|
||||
allocator.free(app_dir_path);
|
||||
log.warn("failed to create lightpanda data dir: {}", .{err});
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return app_dir_path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user