Make the App own the Platform

Removes optional platform, which only existed for tests.

There is now a global `@import("testing.zig").test_app` available. This is setup
when the test runner starts, and cleaned up at the end of tests. Individual
tests don't have to worry about creating app, which I assume was the reason I
Platform optional, since that woul dhave been something else that needed to be
setup.
This commit is contained in:
Karl Seguin
2025-08-22 15:48:20 +08:00
parent 67b479b5c8
commit 687f09d952
10 changed files with 63 additions and 74 deletions

View File

@@ -14,7 +14,7 @@ const Notification = @import("notification.zig").Notification;
pub const App = struct {
http: Http,
config: Config,
platform: ?*const Platform,
platform: Platform,
allocator: Allocator,
telemetry: Telemetry,
app_dir_path: ?[]const u8,
@@ -29,7 +29,6 @@ pub const App = struct {
pub const Config = struct {
run_mode: RunMode,
platform: ?*const Platform = null,
tls_verify_host: bool = true,
http_proxy: ?[:0]const u8 = null,
proxy_bearer_token: ?[:0]const u8 = null,
@@ -57,13 +56,16 @@ pub const App = struct {
});
errdefer http.deinit();
const platform = try Platform.init();
errdefer platform.deinit();
const app_dir_path = getAndMakeAppDir(allocator);
app.* = .{
.http = http,
.allocator = allocator,
.telemetry = undefined,
.platform = config.platform,
.platform = platform,
.app_dir_path = app_dir_path,
.notification = notification,
.config = config,
@@ -85,6 +87,7 @@ pub const App = struct {
self.telemetry.deinit();
self.notification.deinit();
self.http.deinit();
self.platform.deinit();
allocator.destroy(self);
}
};