ReviewOS

also looking at this

craft-native/craft

feat: portable typed window controls on Linux and Windows

#326
Merged glennmichael123 wants to merge codex/portable-window-parity into main
9 files +652 -32

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

docs/architecture/multi-window-ownership.mdmodified+6-6
Changes to docs/architecture/multi-window-ownership.md
@@ -137,12 +137,12 @@ The next multi-window milestone needs product decisions in addition to code:
137137 application-level asynchronous source above.
1381383. Decide whether Touch Bar should stay primary-window scoped or follow the
139139 key window with separately owned item definitions and callbacks.
1404. Finish advanced Linux/Windows window actions and clarify which are portable
141 versus platform-specific, without conflating close semantics: macOS retains
142 a closed page, while Linux and Windows release it.
1435. Expand platform-native integration beyond the current named-window lifecycle
144 smokes. CI runs Linux WebKitGTK under Xvfb and Windows WebView2 on a native
145 runner, but advanced actions and packaged-app behavior still need coverage.
1404. Decide the portability contract for advanced actions beyond bounds,
141 centering, resizability, size limits and fullscreen. Closing still differs:
142 macOS retains a closed page, while Linux and Windows release it.
1435. Expand platform-native integration beyond named-window lifecycle and core
144 geometry/control smokes. CI runs Linux WebKitGTK under Xvfb and Windows
145 WebView2 on a native runner; packaged-app behavior still needs coverage.
146146
147147## Review checklist
148148
docs/features/window-management.mdmodified+17-3
Changes to docs/features/window-management.md
@@ -32,8 +32,10 @@ The `craft-native` SDK returns a typed `Window` handle. Runtime-created
3232windows are available on macOS, Linux, and Windows and must provide either
3333`html` or `url` content. The common create, close, title, geometry, and event
3434routes are cross-platform; some advanced window controls remain macOS-only.
35On Linux, the window manager may ignore position requests, especially before
36the window is shown.
35Bounds, centering, resizing constraints, resizability and fullscreen controls
36also work on the typed handle on all three desktop platforms. On Linux,
37position and fullscreen requests are advisory to the window manager (and
38global positioning can be unavailable under Wayland).
3739
3840```typescript
3941import { createWindow } from 'craft-native'
@@ -62,7 +64,19 @@ const settings = await createWindow({
6264})
6365
6466await settings.setTitle('Settings — Account')
65```
67await settings.setBounds({ x: 120, y: 80, width: 800 })
68await settings.setMinimumSize(480, 360)
69await settings.setMaximumSize(1600, 1200)
70await settings.setResizable(false)
71const canResize = await settings.isResizable()
72await settings.center()
73await settings.setFullscreen(true)
74await settings.toggleFullscreen()
75```
76
77The bounds update preserves omitted coordinates and dimensions. Native window
78managers can adjust requested geometry for decorations or screen constraints;
79read `getBounds()` after a resize event if you need the actual result.
6680
6781The older `createWindow(html, options)` overload remains available when the
6882content is already in a string.
scripts/verify-desktop-multi-window.tsmodified+62-1
Changes to scripts/verify-desktop-multi-window.ts
@@ -11,6 +11,7 @@ const platformName = isWindows ? 'Windows' : 'Linux'
1111
1212const mainPage = `<!doctype html><script>
1313(async () => {
14 const isWindows = ${isWindows}
1415 const report = (step) => fetch('/report?step=' + encodeURIComponent(step), { method: 'POST' })
1516 const waitFor = async (step) => {
1617 for (let attempt = 0; attempt < 200; attempt++) {
@@ -24,6 +25,23 @@ const mainPage = `<!doctype html><script>
2425 name: 'settings', title: 'Child ' + cycle,
2526 url: location.origin + '/child?cycle=' + cycle,
2627 })
28 const call = (action, data = {}, id = 'settings') => window.craft.window._call(action, data, id)
29 const waitSize = async (predicate, label) => {
30 for (let attempt = 0; attempt < 40; attempt++) {
31 const size = await call('getSize')
32 if (predicate(size)) return size
33 await new Promise(resolve => setTimeout(resolve, 100))
34 }
35 throw new Error(label + ': child size never reached expected bounds')
36 }
37 const waitWindowEvent = (name) => new Promise((resolve, reject) => {
38 const timeout = setTimeout(() => reject(new Error(name + ' event missing')), 10000)
39 window.addEventListener('craft:window:' + name, (event) => {
40 if (event.detail.windowId !== 'settings') return
41 clearTimeout(timeout)
42 resolve()
43 }, { once: true })
44 })
2745 try {
2846 if (!window.craft || !window.craft.window || !window.craft.window.open)
2947 throw new Error('document-start Craft bridge missing')
@@ -47,6 +65,49 @@ const mainPage = `<!doctype html><script>
4765 const title = await window.craft.window._call('getTitle', {}, 'settings')
4866 if (title !== 'Child 1') throw new Error('child title not routed to creator: ' + title)
4967
68 const mainBefore = await call('getBounds', {}, 'main')
69 await call('setBounds', { x: bounds.x + 20, y: bounds.y + 15, width: 700, height: 500 })
70 await waitSize(size => Math.abs(size.width - 700) <= 40 && Math.abs(size.height - 500) <= 40, 'setBounds')
71 const moved = await call('getBounds')
72 if (isWindows && (Math.abs(moved.x - bounds.x - 20) > 16 || Math.abs(moved.y - bounds.y - 15) > 16))
73 throw new Error('setBounds did not move the addressed Windows child')
74 await call('center')
75 const centered = await call('getBounds')
76 if (!Number.isFinite(centered.x) || !Number.isFinite(centered.y))
77 throw new Error('center returned invalid child coordinates')
78 await call('setResizable', { resizable: false })
79 if (await call('isResizable') !== false) throw new Error('child stayed resizable')
80 await call('setResizable', { resizable: true })
81 if (await call('isResizable') !== true) throw new Error('child stayed fixed-size')
82 await call('setMinimumSize', { width: 600, height: 420 })
83 await call('setMaximumSize', { width: 820, height: 620 })
84 await call('setSize', { width: 300, height: 200 })
85 await waitSize(size => size.width >= 580 && size.height >= 400, 'minimum size')
86 await call('setSize', { width: 1000, height: 800 })
87 await waitSize(size => size.width <= 860 && size.height <= 660, 'maximum size')
88 await call('setMinimumSize', { width: 1, height: 1 })
89 await call('setMaximumSize', { width: 4096, height: 4096 })
90 await call('setSize', { width: 700, height: 500 })
91 await waitSize(size => Math.abs(size.width - 700) <= 40 && Math.abs(size.height - 500) <= 40, 'restored size')
92 if (isWindows) {
93 const entered = waitWindowEvent('enter-fullscreen')
94 await call('setFullscreen', { fullscreen: true })
95 await entered
96 const left = waitWindowEvent('leave-fullscreen')
97 await call('toggleFullscreen')
98 await left
99 }
100 else {
101 // A bare Xvfb server has no window manager to honor fullscreen requests.
102 await call('setFullscreen', { fullscreen: true })
103 await call('toggleFullscreen')
104 await call('setFullscreen', { fullscreen: false })
105 }
106 const mainAfter = await call('getBounds', {}, 'main')
107 if (Math.abs(mainAfter.width - mainBefore.width) > 40 || Math.abs(mainAfter.height - mainBefore.height) > 40)
108 throw new Error('child controls changed the main window size')
109 await report('controls')
110
50111 const [queuedA, queuedB] = await Promise.all([
51112 window.craft.window.open({ name: 'queue-a', title: 'Child queue-a', url: location.origin + '/child?cycle=queue-a' }),
52113 window.craft.window.open({ name: 'queue-b', title: 'Child queue-b', url: location.origin + '/child?cycle=queue-b' }),
@@ -151,7 +212,7 @@ const server = createServer((request, response) => {
151212 if (step) steps.add(step)
152213 response.end('ok')
153214 if (step === 'done') {
154 const required = ['main', 'child-1', 'child-queue-a', 'child-queue-b', 'queued-closed', 'closed', 'child-2', 'done']
215 const required = ['main', 'child-1', 'controls', 'child-queue-a', 'child-queue-b', 'queued-closed', 'closed', 'child-2', 'done']
155216 if (required.every(name => steps.has(name))) resolveDone()
156217 else rejectDone(new Error(`incomplete smoke steps: ${[...steps].join(', ')}`))
157218 }