ReviewOS

also looking at this

craft-native/craft

test(window): make "every window can be reopened" a property the build checks

#76
Merged glennmichael123 wants to merge feat/window-lifecycle-conformance into main
4 files +432 -23
packages/zig/src/macos.zigmodified+10-23
Changes to packages/zig/src/macos.zig
@@ -6,6 +6,7 @@ const local_tls = ;
66const menu_roles = ;
77const external_link = ;
88const webview_recovery = ;
9const window_registry = ;
910const request_context = ;
1011
1112// Objective-C runtime types and functions (manual declarations to avoid @cImport issues)
@@ -6415,25 +6416,15 @@ fn keepWindowAfterClose(window: objc.id) void {
64156416 rememberCraftWindow(window);
64166417}
64176418
6418/// Every window craft opened, so reopen can tell them from AppKit's own.
6419///
6420/// Craft opens one today; #67 opens more. Sixteen is far past any real app and
6421/// bounded so this needs no allocator on a path that runs during window
6422/// creation.
6423var craft_windows: [16]objc.id = @splat(null);
6424
64256419fn rememberCraftWindow(window: objc.id) void {
6426 if (@intFromPtr(window) == 0) return;
6427 for (&craft_windows) |*slot| {
6428 if (slot.* == window) return;
6429 if (@intFromPtr(slot.*) == 0) {
6430 slot.* = window;
6431 return;
6432 }
6433 }
6434 // Full. Reopen will not restore this window, which is a worse outcome than
6435 // the table being bigger — say so rather than failing silently.
6436 std.log.warn("more than {d} windows; the newest will not be restored by a Dock click", .{craft_windows.len});
6420 if (window_registry.remember(@intFromPtr(window))) return;
6421 // Full. Reopen will not restore this window, which is worse than the table
6422 // being bigger — say so rather than letting a window quietly stop being
6423 // reopenable, which is the bug this registry exists to prevent.
6424 std.log.warn(
6425 "more than {d} windows open; the newest will not be restored by a Dock click",
6426 .{window_registry.capacity},
6427 );
64376428}
64386429
64396430/// Whether the app should quit when its last window closes.
@@ -6511,11 +6502,7 @@ fn appShouldHandleReopen(_: objc.id, _: objc.SEL, app: objc.id, has_visible: boo
65116502/// A test cannot see that. It needs a real reopen event against a sidebar
65126503/// window, so the fix is to stop inferring the answer at all.
65136504fn isCraftWindow(window: objc.id) bool {
6514 if (@intFromPtr(window) == 0) return false;
6515 for (craft_windows) |known| {
6516 if (known == window) return true;
6517 }
6518 return false;
6505 return window_registry.isKnown(@intFromPtr(window));
65196506}
65206507
65216508var app_delegate_installed = false;