also looking at this
test(window): make "every window can be reopened" a property the build checks
#76
4 files
+432
-23
| @@ -6,6 +6,7 @@ const local_tls = ; | ||
| 6 | 6 | const menu_roles = ; |
| 7 | 7 | const external_link = ; |
| 8 | 8 | const webview_recovery = ; |
| 9 | const window_registry = ; | |
| 9 | 10 | const request_context = ; |
| 10 | 11 | |
| 11 | 12 | // Objective-C runtime types and functions (manual declarations to avoid @cImport issues) |
| @@ -6415,25 +6416,15 @@ fn keepWindowAfterClose(window: objc.id) void { | ||
| 6415 | 6416 | rememberCraftWindow(window); |
| 6416 | 6417 | } |
| 6417 | 6418 | |
| 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. | |
| 6423 | var craft_windows: [16]objc.id = @splat(null); | |
| 6424 | ||
| 6425 | 6419 | fn 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 | ); | |
| 6437 | 6428 | } |
| 6438 | 6429 | |
| 6439 | 6430 | /// 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 | ||
| 6511 | 6502 | /// A test cannot see that. It needs a real reopen event against a sidebar |
| 6512 | 6503 | /// window, so the fix is to stop inferring the answer at all. |
| 6513 | 6504 | fn 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)); | |
| 6519 | 6506 | } |
| 6520 | 6507 | |
| 6521 | 6508 | var app_delegate_installed = false; |