apprt/glfw: exit with invalid CLI args

This commit is contained in:
Mitchell Hashimoto
2024-10-18 08:14:40 -07:00
parent 940a46d41f
commit 463f4afc05
2 changed files with 20 additions and 1 deletions

View File

@ -231,10 +231,19 @@ fn drainMailbox(self: *App, rt_app: *apprt.App) !void {
.open_config => try self.performAction(rt_app, .open_config), .open_config => try self.performAction(rt_app, .open_config),
.new_window => |msg| try self.newWindow(rt_app, msg), .new_window => |msg| try self.newWindow(rt_app, msg),
.close => |surface| self.closeSurface(surface), .close => |surface| self.closeSurface(surface),
.quit => self.setQuit(),
.surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message), .surface_message => |msg| try self.surfaceMessage(msg.surface, msg.message),
.redraw_surface => |surface| self.redrawSurface(rt_app, surface), .redraw_surface => |surface| self.redrawSurface(rt_app, surface),
.redraw_inspector => |surface| self.redrawInspector(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;
},
} }
} }
} }

View File

@ -11,6 +11,7 @@ const Allocator = std.mem.Allocator;
const glfw = @import("glfw"); const glfw = @import("glfw");
const macos = @import("macos"); const macos = @import("macos");
const objc = @import("objc"); const objc = @import("objc");
const cli = @import("../cli.zig");
const input = @import("../input.zig"); const input = @import("../input.zig");
const internal_os = @import("../os/main.zig"); const internal_os = @import("../os/main.zig");
const renderer = @import("../renderer.zig"); const renderer = @import("../renderer.zig");
@ -77,9 +78,18 @@ pub const App = struct {
log.warn("configuration error: {s}", .{buf.items}); log.warn("configuration error: {s}", .{buf.items});
buf.clearRetainingCapacity(); 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 // 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(.{ _ = core_app.mailbox.push(.{
.new_window = .{}, .new_window = .{},
}, .{ .forever = {} }); }, .{ .forever = {} });