From 463f4afc0529f3992aecdf552cfe0f3e81796722 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 18 Oct 2024 08:14:40 -0700 Subject: [PATCH] apprt/glfw: exit with invalid CLI args --- src/App.zig | 11 ++++++++++- src/apprt/glfw.zig | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/App.zig b/src/App.zig index b1ea2eb7b..0f9a0d89b 100644 --- a/src/App.zig +++ b/src/App.zig @@ -231,10 +231,19 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void { .open_config => try self.performAction(rt_app, .open_config), .new_window => |msg| try self.newWindow(rt_app, msg), .close => |surface| self.closeSurface(surface), - .quit => self.setQuit(), .surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message), .redraw_surface => |surface| self.redrawSurface(rt_app, surface), .redraw_inspector => |surface| self.redrawInspector(rt_app, surface), + + // If we're quitting, then we set the quit flag and stop + // draining the mailbox immediately. This lets us defer + // mailbox processing to the next tick so that the apprt + // can try to quick as quickly as possible. + .quit => { + log.info("quit message received, short circuiting mailbox drain", .{}); + self.setQuit(); + return; + }, } } } diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 0f0be5480..668dd9143 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -11,6 +11,7 @@ const Allocator = std.mem.Allocator; const glfw = @import("glfw"); const macos = @import("macos"); const objc = @import("objc"); +const cli = @import("../cli.zig"); const input = @import("../input.zig"); const internal_os = @import("../os/main.zig"); const renderer = @import("../renderer.zig"); @@ -77,9 +78,18 @@ pub const App = struct { log.warn("configuration error: {s}", .{buf.items}); buf.clearRetainingCapacity(); } + + // If we have any CLI errors, exit. + if (config._diagnostics.containsLocation(.cli)) { + log.warn("CLI errors detected, exiting", .{}); + _ = core_app.mailbox.push(.{ + .quit = {}, + }, .{ .forever = {} }); + } } // Queue a single new window that starts on launch + // Note: above we may send a quit so this may never happen _ = core_app.mailbox.push(.{ .new_window = .{}, }, .{ .forever = {} });