macos: detect renderer health failures and show error view

This commit is contained in:
Mitchell Hashimoto
2024-01-16 11:27:18 -08:00
parent 0277a0fb4c
commit 376345dcae
8 changed files with 120 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ const Allocator = std.mem.Allocator;
const objc = @import("objc");
const apprt = @import("../apprt.zig");
const input = @import("../input.zig");
const renderer = @import("../renderer.zig");
const terminal = @import("../terminal/main.zig");
const CoreApp = @import("../App.zig");
const CoreInspector = @import("../inspector/main.zig").Inspector;
@@ -123,6 +124,9 @@ pub const App = struct {
/// Show a desktop notification to the user.
show_desktop_notification: ?*const fn (SurfaceUD, [*:0]const u8, [*:0]const u8) void = null,
/// Called when the health of the renderer changes.
update_renderer_health: ?*const fn (SurfaceUD, renderer.Health) void = null,
};
/// Special values for the goto_tab callback.
@@ -960,6 +964,16 @@ pub const Surface = struct {
func(self.opts.userdata, title, body);
}
/// Update the health of the renderer.
pub fn updateRendererHealth(self: *const Surface, health: renderer.Health) void {
const func = self.app.opts.update_renderer_health orelse {
log.info("runtime embedder does not support update_renderer_health", .{});
return;
};
func(self.opts.userdata, health);
}
};
/// Inspector is the state required for the terminal inspector. A terminal

View File

@@ -55,7 +55,7 @@ pub const Renderer = switch (build_config.renderer) {
/// The health status of a renderer. These must be shared across all
/// renderers even if some states aren't reachable so that our API users
/// can use the same enum for all renderers.
pub const Health = enum(u8) {
pub const Health = enum(c_int) {
healthy = 0,
unhealthy = 1,
};

View File

@@ -896,7 +896,7 @@ fn bufferCompleted(
const status = buffer.getProperty(mtl.MTLCommandBufferStatus, "status");
const health: Health = switch (status) {
.@"error" => .unhealthy,
else => .healthy,
else => .unhealthy,
};
// If our health value hasn't changed, then we do nothing. We don't