@flighthq/application 0.5.0-next.1944.cd6b6e7 → 0.5.1-next.597.ab004dd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/application.d.ts +3 -10
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +11 -83
- package/dist/application.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/window.d.ts +50 -52
- package/dist/window.d.ts.map +1 -1
- package/dist/window.js +176 -303
- package/dist/window.js.map +1 -1
- package/package.json +4 -4
- package/src/application.test.ts +150 -269
- package/src/window.test.ts +837 -363
package/dist/window.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
1
2
|
import { connectSignal, createSignal, disconnectSignal, emitSignal } from '@flighthq/signals/contract';
|
|
2
3
|
const kClose = Symbol();
|
|
3
4
|
const kDropFile = Symbol();
|
|
@@ -9,113 +10,68 @@ const kRenderContext = Symbol();
|
|
|
9
10
|
const kRenderState = Symbol();
|
|
10
11
|
const kResize = Symbol();
|
|
11
12
|
const kVisibility = Symbol();
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// Attaches an existing native window without requiring an Application. A false result leaves the
|
|
14
|
+
// window's current lifecycle unchanged; success pins its eventual close to this exact host backend.
|
|
15
|
+
export function attachWindow(host, win, handle, ownership) {
|
|
16
|
+
const backend = host.window;
|
|
17
|
+
const attached = backend.attach(win, handle, ownership);
|
|
18
|
+
if (attached) {
|
|
19
|
+
_windowBackends.set(win, backend);
|
|
20
|
+
_terminalWindows.delete(win);
|
|
21
|
+
}
|
|
22
|
+
return attached;
|
|
23
|
+
}
|
|
24
|
+
// Wires the host's close-request and terminal-close sources to the window's signals. A vetoed
|
|
25
|
+
// request is reported back to the host so it can keep the native window alive. Idempotent.
|
|
26
|
+
export function attachWindowClose(host, win) {
|
|
16
27
|
const observers = getApplicationWindowObservers(win);
|
|
17
28
|
observers.get(kClose)?.();
|
|
18
|
-
|
|
19
|
-
return;
|
|
20
|
-
const onBeforeUnload = (e) => {
|
|
29
|
+
observers.set(kClose, host.window.subscribeClose(() => {
|
|
21
30
|
emitSignal(win.onCloseRequest);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
e.returnValue = '';
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const onPageHide = () => emitSignal(win.onClose);
|
|
28
|
-
window.addEventListener('beforeunload', onBeforeUnload);
|
|
29
|
-
window.addEventListener('pagehide', onPageHide);
|
|
30
|
-
observers.set(kClose, () => {
|
|
31
|
-
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
32
|
-
window.removeEventListener('pagehide', onPageHide);
|
|
33
|
-
});
|
|
31
|
+
return win.onCloseRequest.data?.cancelled === true;
|
|
32
|
+
}, () => notifyWindowClosed(win)));
|
|
34
33
|
}
|
|
35
|
-
export function attachWindowDropFile(win,
|
|
34
|
+
export function attachWindowDropFile(host, win, target) {
|
|
36
35
|
const observers = getApplicationWindowObservers(win);
|
|
37
36
|
observers.get(kDropFile)?.();
|
|
38
|
-
|
|
39
|
-
const onDrop = (e) => {
|
|
40
|
-
e.preventDefault();
|
|
41
|
-
for (const file of Array.from(e.dataTransfer?.files ?? [])) {
|
|
42
|
-
emitSignal(win.onDropFile, file.name);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
element.addEventListener('dragover', onDragOver);
|
|
46
|
-
element.addEventListener('drop', onDrop);
|
|
47
|
-
observers.set(kDropFile, () => {
|
|
48
|
-
element.removeEventListener('dragover', onDragOver);
|
|
49
|
-
element.removeEventListener('drop', onDrop);
|
|
50
|
-
});
|
|
37
|
+
observers.set(kDropFile, host.input.dropFile.subscribe(target, (path) => emitSignal(win.onDropFile, path)));
|
|
51
38
|
}
|
|
52
|
-
export function attachWindowFocus(win,
|
|
39
|
+
export function attachWindowFocus(host, win, target) {
|
|
53
40
|
const observers = getApplicationWindowObservers(win);
|
|
54
41
|
observers.get(kFocus)?.();
|
|
55
|
-
|
|
56
|
-
const onBlur = () => emitSignal(win.onFocusOut);
|
|
57
|
-
element.addEventListener('focus', onFocus);
|
|
58
|
-
element.addEventListener('blur', onBlur);
|
|
59
|
-
observers.set(kFocus, () => {
|
|
60
|
-
element.removeEventListener('focus', onFocus);
|
|
61
|
-
element.removeEventListener('blur', onBlur);
|
|
62
|
-
});
|
|
42
|
+
observers.set(kFocus, host.input.focus.subscribe(target, () => emitSignal(win.onFocusIn), () => emitSignal(win.onFocusOut)));
|
|
63
43
|
}
|
|
64
|
-
export function attachWindowFullscreen(win) {
|
|
44
|
+
export function attachWindowFullscreen(host, win) {
|
|
65
45
|
const observers = getApplicationWindowObservers(win);
|
|
66
46
|
observers.get(kFullscreen)?.();
|
|
67
|
-
const handler = () =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
47
|
+
const handler = (fullscreen) => {
|
|
48
|
+
win.fullscreen = fullscreen;
|
|
49
|
+
emitSignal(win.onFullscreenChanged);
|
|
50
|
+
};
|
|
51
|
+
host.ui.fullscreen.subscribe(handler);
|
|
52
|
+
observers.set(kFullscreen, () => host.ui.fullscreen.unsubscribe(handler));
|
|
53
|
+
}
|
|
54
|
+
// Wires host-originated window movement to the entity and its onMove signal.
|
|
55
|
+
export function attachWindowMove(host, win) {
|
|
75
56
|
const observers = getApplicationWindowObservers(win);
|
|
76
57
|
observers.get(kMove)?.();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const x = window.screenX;
|
|
83
|
-
const y = window.screenY;
|
|
84
|
-
if (win.x !== x || win.y !== y) {
|
|
85
|
-
win.x = x;
|
|
86
|
-
win.y = y;
|
|
87
|
-
emitSignal(win.onMove);
|
|
88
|
-
}
|
|
58
|
+
observers.set(kMove, host.window.subscribeMove((x, y) => {
|
|
59
|
+
if (win.x !== x || win.y !== y) {
|
|
60
|
+
win.x = x;
|
|
61
|
+
win.y = y;
|
|
62
|
+
emitSignal(win.onMove);
|
|
89
63
|
}
|
|
90
|
-
};
|
|
91
|
-
// Both 'resize' and a polling listener on 'pointermove' are imperfect; 'resize' fires more
|
|
92
|
-
// reliably across browsers as a proxy for page layout change that includes moves.
|
|
93
|
-
window.addEventListener('resize', handler);
|
|
94
|
-
observers.set(kMove, () => window.removeEventListener('resize', handler));
|
|
64
|
+
}));
|
|
95
65
|
}
|
|
96
|
-
export function attachWindowOrientation(win) {
|
|
66
|
+
export function attachWindowOrientation(host, win) {
|
|
97
67
|
const observers = getApplicationWindowObservers(win);
|
|
98
68
|
observers.get(kOrientation)?.();
|
|
99
|
-
|
|
100
|
-
return;
|
|
101
|
-
const handler = () => emitSignal(win.onOrientationChanged);
|
|
102
|
-
screen.orientation.addEventListener('change', handler);
|
|
103
|
-
observers.set(kOrientation, () => screen.orientation.removeEventListener('change', handler));
|
|
69
|
+
observers.set(kOrientation, host.window.subscribeOrientation(() => emitSignal(win.onOrientationChanged)));
|
|
104
70
|
}
|
|
105
|
-
export function attachWindowRenderContext(win,
|
|
71
|
+
export function attachWindowRenderContext(host, win, target) {
|
|
106
72
|
const observers = getApplicationWindowObservers(win);
|
|
107
73
|
observers.get(kRenderContext)?.();
|
|
108
|
-
|
|
109
|
-
e.preventDefault();
|
|
110
|
-
emitSignal(win.onRenderContextLost);
|
|
111
|
-
};
|
|
112
|
-
const onContextRestored = () => emitSignal(win.onRenderContextRestored);
|
|
113
|
-
canvas.addEventListener('webglcontextlost', onContextLost);
|
|
114
|
-
canvas.addEventListener('webglcontextrestored', onContextRestored);
|
|
115
|
-
observers.set(kRenderContext, () => {
|
|
116
|
-
canvas.removeEventListener('webglcontextlost', onContextLost);
|
|
117
|
-
canvas.removeEventListener('webglcontextrestored', onContextRestored);
|
|
118
|
-
});
|
|
74
|
+
observers.set(kRenderContext, host.graphics.renderContext.subscribe(target, () => emitSignal(win.onRenderContextLost), () => emitSignal(win.onRenderContextRestored)));
|
|
119
75
|
}
|
|
120
76
|
// Binds a canvas render state to the window's size and devicePixelRatio: sizes the canvas backing
|
|
121
77
|
// store and writes the device transform (renderTransform2D), then keeps both in sync on every
|
|
@@ -123,12 +79,12 @@ export function attachWindowRenderContext(win, canvas) {
|
|
|
123
79
|
// — it is the source of the size/DPI updates this reacts to. The render state must have an
|
|
124
80
|
// initialized renderTransform2D (every create*RenderState factory does). DOM render states need no
|
|
125
81
|
// device transform (the browser rasterizes DOM at device resolution), so this is for canvas/Gl.
|
|
126
|
-
export function attachWindowRenderState(win, state,
|
|
82
|
+
export function attachWindowRenderState(host, win, state, target) {
|
|
127
83
|
const observers = getApplicationWindowObservers(win);
|
|
128
84
|
observers.get(kRenderState)?.();
|
|
85
|
+
const renderSurface = host.graphics.renderSurface;
|
|
129
86
|
const apply = () => {
|
|
130
|
-
|
|
131
|
-
canvas.height = Math.round(win.height * win.devicePixelRatio);
|
|
87
|
+
renderSurface.resize(target, Math.round(win.width * win.devicePixelRatio), Math.round(win.height * win.devicePixelRatio));
|
|
132
88
|
if (state.renderTransform2D !== null)
|
|
133
89
|
computeWindowDeviceTransform(win, state.renderTransform2D);
|
|
134
90
|
};
|
|
@@ -136,46 +92,37 @@ export function attachWindowRenderState(win, state, canvas) {
|
|
|
136
92
|
connectSignal(win.onResize, apply);
|
|
137
93
|
observers.set(kRenderState, () => disconnectSignal(win.onResize, apply));
|
|
138
94
|
}
|
|
139
|
-
export function attachWindowResize(win,
|
|
95
|
+
export function attachWindowResize(host, win, target) {
|
|
140
96
|
const observers = getApplicationWindowObservers(win);
|
|
141
97
|
observers.get(kResize)?.();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
observer.observe(element);
|
|
151
|
-
observers.set(kResize, () => observer.disconnect());
|
|
152
|
-
}
|
|
153
|
-
export function attachWindowVisibility(win) {
|
|
98
|
+
observers.set(kResize, host.window.subscribeResize(target, (width, height, devicePixelRatio) => {
|
|
99
|
+
win.width = width;
|
|
100
|
+
win.height = height;
|
|
101
|
+
win.devicePixelRatio = devicePixelRatio;
|
|
102
|
+
emitSignal(win.onResize);
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
export function attachWindowVisibility(host, win) {
|
|
154
106
|
const observers = getApplicationWindowObservers(win);
|
|
155
107
|
observers.get(kVisibility)?.();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
emitSignal(win.onActivate);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
document.addEventListener('visibilitychange', handler);
|
|
165
|
-
observers.set(kVisibility, () => document.removeEventListener('visibilitychange', handler));
|
|
108
|
+
observers.set(kVisibility, host.window.subscribeVisibility((visible) => {
|
|
109
|
+
emitSignal(visible ? win.onActivate : win.onDeactivate);
|
|
110
|
+
}));
|
|
166
111
|
}
|
|
167
112
|
// Centers the window on its current display via the backend.
|
|
168
|
-
export function centerWindow(win) {
|
|
169
|
-
|
|
113
|
+
export function centerWindow(host, win) {
|
|
114
|
+
host.window.center(win);
|
|
170
115
|
}
|
|
171
116
|
// Closes the window. First emits onCloseRequest; if a listener vetoes (cancelSignal), the close is
|
|
172
117
|
// aborted and this returns false. Otherwise the backend closes the window, onClose fires, and it
|
|
173
118
|
// returns true.
|
|
174
|
-
export function closeWindow(win) {
|
|
119
|
+
export function closeWindow(host, win) {
|
|
120
|
+
if (_terminalWindows.has(win))
|
|
121
|
+
return true;
|
|
175
122
|
if (!requestWindowClose(win))
|
|
176
123
|
return false;
|
|
177
|
-
|
|
178
|
-
|
|
124
|
+
(_windowBackends.get(win) ?? host.window).close(win);
|
|
125
|
+
notifyWindowClosed(win);
|
|
179
126
|
return true;
|
|
180
127
|
}
|
|
181
128
|
// Writes the window's device transform — a uniform scale by devicePixelRatio — into out and returns
|
|
@@ -192,7 +139,7 @@ export function computeWindowDeviceTransform(win, out) {
|
|
|
192
139
|
return out;
|
|
193
140
|
}
|
|
194
141
|
export function createApplicationWindow() {
|
|
195
|
-
return {
|
|
142
|
+
return createEntity({
|
|
196
143
|
alwaysOnTop: false,
|
|
197
144
|
devicePixelRatio: 1,
|
|
198
145
|
focused: false,
|
|
@@ -229,7 +176,7 @@ export function createApplicationWindow() {
|
|
|
229
176
|
onRenderContextRestored: createSignal(),
|
|
230
177
|
onResize: createSignal(),
|
|
231
178
|
onRestore: createSignal(),
|
|
232
|
-
};
|
|
179
|
+
});
|
|
233
180
|
}
|
|
234
181
|
export function detachWindowClose(win) {
|
|
235
182
|
const observers = getApplicationWindowObservers(win);
|
|
@@ -287,107 +234,85 @@ export function disposeApplicationWindow(win) {
|
|
|
287
234
|
cleanup();
|
|
288
235
|
observers.clear();
|
|
289
236
|
}
|
|
290
|
-
export function exitApplicationFullscreen() {
|
|
291
|
-
return
|
|
237
|
+
export function exitApplicationFullscreen(host) {
|
|
238
|
+
return host.ui.fullscreen.exit();
|
|
292
239
|
}
|
|
293
|
-
// Releases the Pointer Lock
|
|
294
|
-
export function exitApplicationPointerLock() {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return
|
|
240
|
+
// Releases the host's active Pointer Lock, restoring cursor movement.
|
|
241
|
+
export async function exitApplicationPointerLock(host) {
|
|
242
|
+
const backend = _pointerLockBackend ?? host.input.pointerLock;
|
|
243
|
+
const outcome = await backend.exit();
|
|
244
|
+
if (outcome.reason === 'ok' && _pointerLockBackend === backend)
|
|
245
|
+
_pointerLockBackend = null;
|
|
246
|
+
return outcome;
|
|
300
247
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (_host !== null) {
|
|
306
|
-
return {
|
|
307
|
-
conflict: _hostConflict,
|
|
308
|
-
layer: 'host',
|
|
309
|
-
operation: _hostObservation !== null ? _hostObservation.operation : null,
|
|
310
|
-
viability: _hostObservation !== null ? _hostObservation.viability : 'unobserved',
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
return { conflict: false, layer: 'host-not-enabled', operation: null, viability: 'unobserved' };
|
|
314
|
-
}
|
|
315
|
-
// Briefly flashes the window frame to attract attention. No-op on web; native hosts implement via
|
|
316
|
-
// the WindowBackend (e.g. Electron window.flashFrame(true)).
|
|
317
|
-
export function flashWindowFrame(win) {
|
|
318
|
-
getWindowBackend().flashWindowFrame(win);
|
|
248
|
+
// Briefly flashes the window frame to attract attention. Native hosts may implement it via the
|
|
249
|
+
// WindowBackend (for example Electron window.flashFrame(true)).
|
|
250
|
+
export function flashWindowFrame(host, win) {
|
|
251
|
+
host.window.flashWindowFrame(win);
|
|
319
252
|
}
|
|
320
253
|
// Brings the window to the foreground and marks it focused.
|
|
321
|
-
export function focusWindow(win) {
|
|
254
|
+
export function focusWindow(host, win) {
|
|
322
255
|
win.focused = true;
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
// The active window backend: custom > host > sentinel. There is always a backend.
|
|
326
|
-
export function getWindowBackend() {
|
|
327
|
-
return _custom ?? _host ?? _sentinel;
|
|
328
|
-
}
|
|
329
|
-
// Fills `out` with the window's current screen bounds and returns it.
|
|
330
|
-
export function getWindowBounds(win, out) {
|
|
331
|
-
return getWindowBackend().getBounds(win, out);
|
|
256
|
+
host.window.focus(win);
|
|
332
257
|
}
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
337
|
-
export function getWindowDisplay(win) {
|
|
338
|
-
return -1;
|
|
258
|
+
// Fills `out` with the host window's current screen bounds and returns it.
|
|
259
|
+
export function getWindowBounds(host, win, out) {
|
|
260
|
+
return host.window.getBounds(win, out);
|
|
339
261
|
}
|
|
340
262
|
// Hides the window without closing it.
|
|
341
|
-
export function hideWindow(win) {
|
|
263
|
+
export function hideWindow(host, win) {
|
|
342
264
|
if (!win.visible)
|
|
343
265
|
return;
|
|
344
266
|
win.visible = false;
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// browser denies (requires a prior user gesture). Use exitApplicationPointerLock to release.
|
|
358
|
-
export function lockApplicationPointer(element) {
|
|
359
|
-
if (typeof element.requestPointerLock !== 'function')
|
|
360
|
-
return Promise.resolve();
|
|
361
|
-
const result = element.requestPointerLock();
|
|
362
|
-
// requestPointerLock returns a Promise in newer browsers and undefined in older ones.
|
|
363
|
-
return (result instanceof Promise ? result : Promise.resolve());
|
|
267
|
+
host.window.hide(win);
|
|
268
|
+
}
|
|
269
|
+
// Requests Pointer Lock on an opaque target, hiding and confining the cursor so raw mouse deltas are
|
|
270
|
+
// delivered via pointermove events. Expected target, availability, denial, and operation failures are
|
|
271
|
+
// returned as method-tight outcomes. Only successful acquisition pins its eventual exit to this exact
|
|
272
|
+
// provider even if the caller later supplies a different Host.
|
|
273
|
+
export async function lockApplicationPointer(host, target) {
|
|
274
|
+
const backend = host.input.pointerLock;
|
|
275
|
+
const outcome = await backend.request(target);
|
|
276
|
+
if (outcome.reason === 'ok')
|
|
277
|
+
_pointerLockBackend = backend;
|
|
278
|
+
return outcome;
|
|
364
279
|
}
|
|
365
280
|
// Maximizes the window. Updates state and emits onMaximize when the state changes.
|
|
366
|
-
export function maximizeWindow(win) {
|
|
281
|
+
export function maximizeWindow(host, win) {
|
|
367
282
|
if (win.maximized)
|
|
368
283
|
return;
|
|
369
284
|
win.maximized = true;
|
|
370
|
-
|
|
285
|
+
host.window.maximize(win);
|
|
371
286
|
emitSignal(win.onMaximize);
|
|
372
287
|
}
|
|
373
288
|
// Minimizes the window. Updates state and emits onMinimize when the state changes.
|
|
374
|
-
export function minimizeWindow(win) {
|
|
289
|
+
export function minimizeWindow(host, win) {
|
|
375
290
|
if (win.minimized)
|
|
376
291
|
return;
|
|
377
292
|
win.minimized = true;
|
|
378
|
-
|
|
293
|
+
host.window.minimize(win);
|
|
379
294
|
emitSignal(win.onMinimize);
|
|
380
295
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
296
|
+
// The single terminal-close choke point for both app-driven and host-driven closes. Native callbacks may
|
|
297
|
+
// fire synchronously inside backend.close; whichever path arrives first emits and every later path no-ops.
|
|
298
|
+
// After the terminal signal is delivered, application-side observers are drained even when a listener
|
|
299
|
+
// throws. This state belongs to the ApplicationWindow entity, never to an Application or per-app registry.
|
|
300
|
+
export function notifyWindowClosed(win) {
|
|
301
|
+
if (_terminalWindows.has(win))
|
|
302
|
+
return;
|
|
303
|
+
_terminalWindows.add(win);
|
|
304
|
+
_windowBackends.delete(win);
|
|
305
|
+
try {
|
|
306
|
+
emitSignal(win.onClose);
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
disposeApplicationWindow(win);
|
|
310
|
+
}
|
|
386
311
|
}
|
|
387
312
|
// Opens (or configures) the window from options, applying each provided field to the entity and
|
|
388
313
|
// delegating to the backend. Returns whether the host opened a window. On web this configures the
|
|
389
314
|
// existing page-window; native hosts create a real OS window.
|
|
390
|
-
export function openWindow(win, options = {}) {
|
|
315
|
+
export function openWindow(host, win, options = {}) {
|
|
391
316
|
if (options.title !== undefined)
|
|
392
317
|
win.title = options.title;
|
|
393
318
|
if (options.x !== undefined)
|
|
@@ -418,31 +343,28 @@ export function openWindow(win, options = {}) {
|
|
|
418
343
|
win.maxWidth = options.maxWidth;
|
|
419
344
|
if (options.maxHeight !== undefined)
|
|
420
345
|
win.maxHeight = options.maxHeight;
|
|
421
|
-
const
|
|
346
|
+
const backend = host.window;
|
|
347
|
+
const result = backend.open(win, options);
|
|
348
|
+
if (result) {
|
|
349
|
+
_windowBackends.set(win, backend);
|
|
350
|
+
_terminalWindows.delete(win);
|
|
351
|
+
}
|
|
422
352
|
// Apply center after open so the backend has registered the OS window before moving it.
|
|
423
|
-
if (options.center === true)
|
|
424
|
-
|
|
353
|
+
if (result && options.center === true)
|
|
354
|
+
backend.center?.(win);
|
|
425
355
|
return result;
|
|
426
356
|
}
|
|
427
|
-
// Prepares
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
export function prepareElementForInput(element) {
|
|
432
|
-
element.style.touchAction = 'none';
|
|
433
|
-
element.style.userSelect = 'none';
|
|
434
|
-
element.style.webkitUserSelect = 'none';
|
|
435
|
-
element.style.webkitTapHighlightColor = 'transparent';
|
|
436
|
-
if (element instanceof HTMLCanvasElement) {
|
|
437
|
-
element.style.transform = 'translateZ(0)';
|
|
438
|
-
}
|
|
357
|
+
// Prepares a provider-bound target for direct input. The provider owns platform details such as
|
|
358
|
+
// browser CSS and canvas compositing; the application contract only carries opaque identity.
|
|
359
|
+
export function prepareElementForInput(host, target) {
|
|
360
|
+
host.input.target.prepare(target);
|
|
439
361
|
}
|
|
440
|
-
export function requestApplicationFullscreen(
|
|
441
|
-
return
|
|
362
|
+
export function requestApplicationFullscreen(host, target) {
|
|
363
|
+
return host.ui.fullscreen.request(target);
|
|
442
364
|
}
|
|
443
365
|
// Requests user attention on the window (taskbar flash / dock bounce); pass false to stop.
|
|
444
|
-
export function requestWindowAttention(win, attention) {
|
|
445
|
-
|
|
366
|
+
export function requestWindowAttention(host, win, attention) {
|
|
367
|
+
host.window.requestAttention(win, attention);
|
|
446
368
|
}
|
|
447
369
|
// Emits onCloseRequest and returns whether the close may proceed (false when a listener vetoed by
|
|
448
370
|
// calling cancelSignal(win.onCloseRequest)). Use to gate an app-driven close without closing.
|
|
@@ -450,163 +372,114 @@ export function requestWindowClose(win) {
|
|
|
450
372
|
emitSignal(win.onCloseRequest);
|
|
451
373
|
return win.onCloseRequest.data?.cancelled !== true;
|
|
452
374
|
}
|
|
453
|
-
export function resetWindowBackendForTest() {
|
|
454
|
-
_custom = null;
|
|
455
|
-
_host = null;
|
|
456
|
-
_hostConflict = false;
|
|
457
|
-
_hostObservation = null;
|
|
458
|
-
}
|
|
459
375
|
// Restores the window from a minimized/maximized state. Emits onRestore when state changed.
|
|
460
|
-
export function restoreWindow(win) {
|
|
376
|
+
export function restoreWindow(host, win) {
|
|
461
377
|
if (!win.minimized && !win.maximized)
|
|
462
378
|
return;
|
|
463
379
|
win.minimized = false;
|
|
464
380
|
win.maximized = false;
|
|
465
|
-
|
|
381
|
+
host.window.restore(win);
|
|
466
382
|
emitSignal(win.onRestore);
|
|
467
383
|
}
|
|
468
384
|
// Sets whether the window floats above others.
|
|
469
|
-
export function setWindowAlwaysOnTop(win, alwaysOnTop) {
|
|
385
|
+
export function setWindowAlwaysOnTop(host, win, alwaysOnTop) {
|
|
470
386
|
win.alwaysOnTop = alwaysOnTop;
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
// Installs a custom window backend; pass null to fall back to host or sentinel.
|
|
474
|
-
export function setWindowBackend(backend) {
|
|
475
|
-
_custom = backend;
|
|
387
|
+
host.window.setAlwaysOnTop(win, alwaysOnTop);
|
|
476
388
|
}
|
|
477
389
|
// Prevents (or allows) the window contents from being captured in screenshots or screen sharing.
|
|
478
|
-
//
|
|
479
|
-
export function setWindowContentProtection(win, enabled) {
|
|
480
|
-
|
|
390
|
+
// Native hosts may implement it via the WindowBackend (for example Electron setContentProtection).
|
|
391
|
+
export function setWindowContentProtection(host, win, enabled) {
|
|
392
|
+
host.window.setContentProtection(win, enabled);
|
|
481
393
|
}
|
|
482
394
|
// Sets fullscreen state. Updates state and emits onFullscreenChanged when the state changes.
|
|
483
|
-
export function setWindowFullscreen(win, fullscreen) {
|
|
395
|
+
export function setWindowFullscreen(host, win, fullscreen) {
|
|
484
396
|
if (win.fullscreen === fullscreen)
|
|
485
397
|
return;
|
|
486
398
|
win.fullscreen = fullscreen;
|
|
487
|
-
|
|
399
|
+
host.window.setFullscreen(win, fullscreen);
|
|
488
400
|
emitSignal(win.onFullscreenChanged);
|
|
489
401
|
}
|
|
490
|
-
// Shows or hides the native drop shadow around the window
|
|
491
|
-
export function setWindowHasShadow(win, hasShadow) {
|
|
492
|
-
|
|
402
|
+
// Shows or hides the native drop shadow around the window when the host supports it.
|
|
403
|
+
export function setWindowHasShadow(host, win, hasShadow) {
|
|
404
|
+
host.window.setHasShadow(win, hasShadow);
|
|
493
405
|
}
|
|
494
406
|
// Sets the window icon (path/URL). On web this updates the page favicon.
|
|
495
|
-
export function setWindowIcon(win, icon) {
|
|
407
|
+
export function setWindowIcon(host, win, icon) {
|
|
496
408
|
win.icon = icon;
|
|
497
|
-
|
|
409
|
+
host.window.setIcon(win, icon);
|
|
498
410
|
}
|
|
499
411
|
// Sets the maximum window size in logical pixels (-1 for unbounded).
|
|
500
|
-
export function setWindowMaximumSize(win, width, height) {
|
|
412
|
+
export function setWindowMaximumSize(host, win, width, height) {
|
|
501
413
|
win.maxWidth = width;
|
|
502
414
|
win.maxHeight = height;
|
|
503
|
-
|
|
415
|
+
host.window.setMaximumSize(win, width, height);
|
|
504
416
|
}
|
|
505
|
-
// Shows or hides the window's menu bar
|
|
506
|
-
export function setWindowMenuBarVisible(win, visible) {
|
|
507
|
-
|
|
417
|
+
// Shows or hides the window's menu bar when the host supports it.
|
|
418
|
+
export function setWindowMenuBarVisible(host, win, visible) {
|
|
419
|
+
host.window.setMenuBarVisible(win, visible);
|
|
508
420
|
}
|
|
509
421
|
// Sets the minimum window size in logical pixels.
|
|
510
|
-
export function setWindowMinimumSize(win, width, height) {
|
|
422
|
+
export function setWindowMinimumSize(host, win, width, height) {
|
|
511
423
|
win.minWidth = width;
|
|
512
424
|
win.minHeight = height;
|
|
513
|
-
|
|
425
|
+
host.window.setMinimumSize(win, width, height);
|
|
514
426
|
}
|
|
515
427
|
// Sets the window opacity in [0, 1].
|
|
516
|
-
export function setWindowOpacity(win, opacity) {
|
|
428
|
+
export function setWindowOpacity(host, win, opacity) {
|
|
517
429
|
win.opacity = opacity;
|
|
518
|
-
|
|
430
|
+
host.window.setOpacity(win, opacity);
|
|
519
431
|
}
|
|
520
432
|
// Sets the window's parent (for modal/child relationships); pass null to detach. Native hosts only.
|
|
521
|
-
export function setWindowParent(win, parent) {
|
|
522
|
-
|
|
433
|
+
export function setWindowParent(host, win, parent) {
|
|
434
|
+
host.window.setParent(win, parent);
|
|
523
435
|
}
|
|
524
436
|
// Moves the window's top-left to (x, y) in screen coordinates. Updates state and emits onMove.
|
|
525
|
-
export function setWindowPosition(win, x, y) {
|
|
437
|
+
export function setWindowPosition(host, win, x, y) {
|
|
526
438
|
win.x = x;
|
|
527
439
|
win.y = y;
|
|
528
|
-
|
|
440
|
+
host.window.setPosition(win, x, y);
|
|
529
441
|
emitSignal(win.onMove);
|
|
530
442
|
}
|
|
531
443
|
// Sets the taskbar/dock progress indicator in [0, 1]; a negative value clears it.
|
|
532
|
-
export function setWindowProgress(win, progress) {
|
|
533
|
-
|
|
444
|
+
export function setWindowProgress(host, win, progress) {
|
|
445
|
+
host.window.setProgress(win, progress);
|
|
534
446
|
}
|
|
535
447
|
// Sets whether the user can resize the window.
|
|
536
|
-
export function setWindowResizable(win, resizable) {
|
|
448
|
+
export function setWindowResizable(host, win, resizable) {
|
|
537
449
|
win.resizable = resizable;
|
|
538
|
-
|
|
450
|
+
host.window.setResizable(win, resizable);
|
|
539
451
|
}
|
|
540
452
|
// Resizes the window to width x height (logical pixels). Updates state and emits onResize.
|
|
541
|
-
export function setWindowSize(win, width, height) {
|
|
453
|
+
export function setWindowSize(host, win, width, height) {
|
|
542
454
|
win.width = width;
|
|
543
455
|
win.height = height;
|
|
544
|
-
|
|
456
|
+
host.window.setSize(win, width, height);
|
|
545
457
|
emitSignal(win.onResize);
|
|
546
458
|
}
|
|
547
459
|
// Sets whether the window is hidden from the taskbar/dock switcher.
|
|
548
|
-
export function setWindowSkipTaskbar(win, skip) {
|
|
460
|
+
export function setWindowSkipTaskbar(host, win, skip) {
|
|
549
461
|
win.skipTaskbar = skip;
|
|
550
|
-
|
|
462
|
+
host.window.setSkipTaskbar(win, skip);
|
|
551
463
|
}
|
|
552
464
|
// Sets the window title text.
|
|
553
|
-
export function setWindowTitle(win, title) {
|
|
465
|
+
export function setWindowTitle(host, win, title) {
|
|
554
466
|
win.title = title;
|
|
555
|
-
|
|
467
|
+
host.window.setTitle(win, title);
|
|
556
468
|
}
|
|
557
469
|
// Shows a hidden window.
|
|
558
|
-
export function showWindow(win) {
|
|
470
|
+
export function showWindow(host, win) {
|
|
559
471
|
if (win.visible)
|
|
560
472
|
return;
|
|
561
473
|
win.visible = true;
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
const _sentinel = {
|
|
565
|
-
center() { },
|
|
566
|
-
close() { },
|
|
567
|
-
flashWindowFrame() { },
|
|
568
|
-
focus() { },
|
|
569
|
-
getBounds(win, out) {
|
|
570
|
-
out.x = win.x;
|
|
571
|
-
out.y = win.y;
|
|
572
|
-
out.width = win.width;
|
|
573
|
-
out.height = win.height;
|
|
574
|
-
return out;
|
|
575
|
-
},
|
|
576
|
-
hide() { },
|
|
577
|
-
maximize() { },
|
|
578
|
-
minimize() { },
|
|
579
|
-
open() {
|
|
580
|
-
return false;
|
|
581
|
-
},
|
|
582
|
-
requestAttention() { },
|
|
583
|
-
restore() { },
|
|
584
|
-
setAlwaysOnTop() { },
|
|
585
|
-
setContentProtection() { },
|
|
586
|
-
setFullscreen() { },
|
|
587
|
-
setHasShadow() { },
|
|
588
|
-
setIcon() { },
|
|
589
|
-
setMaximumSize() { },
|
|
590
|
-
setMenuBarVisible() { },
|
|
591
|
-
setMinimumSize() { },
|
|
592
|
-
setOpacity() { },
|
|
593
|
-
setParent() { },
|
|
594
|
-
setPosition() { },
|
|
595
|
-
setProgress() { },
|
|
596
|
-
setResizable() { },
|
|
597
|
-
setSize() { },
|
|
598
|
-
setSkipTaskbar() { },
|
|
599
|
-
setTitle() { },
|
|
600
|
-
show() { },
|
|
601
|
-
};
|
|
474
|
+
host.window.show(win);
|
|
475
|
+
}
|
|
602
476
|
// Internal teardown registry, kept off the public ApplicationWindow entity (a side table like
|
|
603
477
|
// input's binding map). attach/detach/dispose track cleanup closures internally so callers hold
|
|
604
478
|
// nothing.
|
|
605
479
|
const _applicationWindowObservers = new WeakMap();
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
let
|
|
609
|
-
let _hostObservation = null;
|
|
480
|
+
const _terminalWindows = new WeakSet();
|
|
481
|
+
const _windowBackends = new WeakMap();
|
|
482
|
+
let _pointerLockBackend = null;
|
|
610
483
|
function getApplicationWindowObservers(win) {
|
|
611
484
|
let observers = _applicationWindowObservers.get(win);
|
|
612
485
|
if (observers === undefined) {
|