diff --git a/src/web-ui/index.html b/src/web-ui/index.html
index 1430d655f7..920f572f81 100644
--- a/src/web-ui/index.html
+++ b/src/web-ui/index.html
@@ -537,11 +537,11 @@
}, 1200);
}
+ var isWindows = (
+ (typeof navigator.userAgent === 'string' && navigator.userAgent.toUpperCase().includes('WINDOWS'))
+ || (typeof navigator.platform === 'string' && navigator.platform.toUpperCase().includes('WIN'))
+ );
if (controls && window.__OPENBITFUN_SHOW_STARTUP_WINDOW_CONTROLS__) {
- var isWindows = (
- (typeof navigator.userAgent === 'string' && navigator.userAgent.toUpperCase().includes('WINDOWS'))
- || (typeof navigator.platform === 'string' && navigator.platform.toUpperCase().includes('WIN'))
- );
controls.classList.toggle('window-controls--windows', isWindows);
controls.querySelectorAll('[data-startup-window-control-platform]').forEach(function (glyph) {
if (glyph.getAttribute('data-startup-window-control-platform') !== (isWindows ? 'windows' : 'generic')) {
@@ -570,12 +570,17 @@
});
}
}
+ function isStartupOverlayInteractive() {
+ return startupOverlay && startupOverlay.isConnected && !startupOverlay.hasAttribute('inert');
+ }
function invokeWindowControl(action) {
if (!tauri || typeof tauri.invoke !== 'function') return;
var requestVersion = ++stateRequestVersion;
tauri.invoke('startup_window_control', { request: { action: action } })
.then(function (response) {
- if (requestVersion === stateRequestVersion) applyWindowState(response);
+ if (requestVersion === stateRequestVersion && isStartupOverlayInteractive()) {
+ applyWindowState(response);
+ }
})
.catch(function () {});
}
@@ -588,8 +593,7 @@
var windowLabel = currentWindow.label;
function canUseStartupWindowGesture(event) {
return !event.defaultPrevented && event.button === 0
- && event.target === startupOverlay && startupOverlay.isConnected
- && !startupOverlay.hasAttribute('inert');
+ && event.target === startupOverlay && isStartupOverlayInteractive();
}
startupOverlay.addEventListener('mousedown', function (event) {
if (!canUseStartupWindowGesture(event) || event.detail > 1) return;
@@ -597,8 +601,8 @@
tauri.invoke('plugin:window|is_maximized', { label: windowLabel }),
tauri.invoke('plugin:window|is_fullscreen', { label: windowLabel })
]).then(function (states) {
- if (states[0] !== false || states[1] !== false
- || !startupOverlay.isConnected || startupOverlay.hasAttribute('inert')) return;
+ if (typeof states[0] !== 'boolean' || (states[0] && !isWindows) || states[1] !== false
+ || !isStartupOverlayInteractive()) return;
return tauri.invoke('plugin:window|start_dragging', { label: windowLabel });
}).catch(function () {});
});
@@ -617,10 +621,26 @@
invokeWindowControl(action);
});
});
- invokeWindowControl('get_state');
- window.setTimeout(function () {
- if (controls.isConnected) invokeWindowControl('get_state');
- }, 120);
+ function refreshWindowState() {
+ if (isStartupOverlayInteractive()) invokeWindowControl('get_state');
+ }
+ // The native caption drag can restore or snap the window after IPC returns.
+ var resizeFrame = null;
+ function scheduleWindowStateRefresh() {
+ if (resizeFrame !== null || !isStartupOverlayInteractive()) return;
+ resizeFrame = window.requestAnimationFrame(function () {
+ resizeFrame = null;
+ refreshWindowState();
+ });
+ }
+ refreshWindowState();
+ var initialStateTimer = window.setTimeout(refreshWindowState, 120);
+ window.addEventListener('resize', scheduleWindowStateRefresh);
+ window.addEventListener('openbitfun:startup-overlay-hidden', function () {
+ window.removeEventListener('resize', scheduleWindowStateRefresh);
+ window.clearTimeout(initialStateTimer);
+ if (resizeFrame !== null) window.cancelAnimationFrame(resizeFrame);
+ }, { once: true });
}
})();
diff --git a/src/web-ui/src/app/components/SceneTopBar/SceneTopBar.test.tsx b/src/web-ui/src/app/components/SceneTopBar/SceneTopBar.test.tsx
index bc0f8b02f3..f642017f24 100644
--- a/src/web-ui/src/app/components/SceneTopBar/SceneTopBar.test.tsx
+++ b/src/web-ui/src/app/components/SceneTopBar/SceneTopBar.test.tsx
@@ -49,6 +49,7 @@ describe('SceneTopBar', () => {
vi.clearAllMocks();
isMaximized.mockResolvedValue(false);
isFullscreen.mockResolvedValue(false);
+ vi.stubGlobal('navigator', { platform: 'Linux x86_64', userAgent: 'Linux' });
vi.stubGlobal('__TAURI_INTERNALS__', {
invoke: vi.fn(),
metadata: { currentWindow: { label: 'main' } },
@@ -189,7 +190,9 @@ describe('SceneTopBar', () => {
expect(maximize).toHaveBeenCalledTimes(3);
});
- it('excludes the whole tab from window gestures as other tabs open and close', async () => {
+ it.each([false, true])('excludes the whole tab on Windows with maximized=%s as other tabs open and close', async maximized => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ isMaximized.mockResolvedValue(maximized);
for (const tabCount of [1, 2, 1]) {
const toolbar = renderBar(tabCount);
const tab = toolbar.querySelector('[role="tab"]')!;
@@ -204,7 +207,9 @@ describe('SceneTopBar', () => {
}
});
- it('leaves multi-tab labels and item padding to tab interaction', async () => {
+ it.each([false, true])('leaves Windows multi-tab labels and item padding to tab interaction with maximized=%s', async maximized => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ isMaximized.mockResolvedValue(maximized);
const toolbar = renderBar(2);
const tab = toolbar.querySelector('[role="tab"][data-openbitfun-value="1"]')!;
for (const target of [tab, tab.querySelector('span')!, tab.closest('[data-openbitfun-part="item"]')!]) {
@@ -217,7 +222,9 @@ describe('SceneTopBar', () => {
expect(maximize).not.toHaveBeenCalled();
});
- it.each([1, 2])('excludes close buttons, nested SVGs, scene actions and editable fields with %i tabs', async tabCount => {
+ it.each([1, 2])('excludes close buttons, nested SVGs, scene actions and editable fields with %i tabs on maximized Windows', async tabCount => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ isMaximized.mockResolvedValue(true);
const toolbar = renderBar(tabCount);
for (const target of toolbar.querySelectorAll('button:not([role="tab"]), svg, path, input, [contenteditable] span')) {
await mouseDown(target);
@@ -229,6 +236,58 @@ describe('SceneTopBar', () => {
expect(maximize).not.toHaveBeenCalled();
});
+ it('keeps maximized Windows panel tabs, padding and close icons outside window gestures', async () => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ isMaximized.mockResolvedValue(true);
+ const { TabGroup } = await import('@openbitfun/ui');
+ const select = vi.fn();
+ const close = vi.fn();
+ act(() => root.render(First panel },
+ { value: '1', label: Second panel, endAction:
+ },
+ ]} />
+ } />));
+ const panel = host.querySelector('.openbitfun-scene-top-bar__panel-region')!;
+ for (const target of panel.querySelectorAll('[role="tab"], [data-openbitfun-part="item"], span, button, svg, path')) {
+ await mouseDown(target);
+ doubleClick(target);
+ }
+ act(() => panel.querySelector('[role="tab"][data-openbitfun-value="1"]')!.click());
+ act(() => panel.querySelector('[aria-label="Close panel"]')!.click());
+ expect(select).toHaveBeenCalledWith('1');
+ expect(close).toHaveBeenCalledOnce();
+ expect(startDragging).not.toHaveBeenCalled();
+ expect(maximize).not.toHaveBeenCalled();
+ });
+
+ it('delegates maximized Windows blank chrome to native dragging without rerendering', async () => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ const toolbar = renderBar(2);
+ await mouseDown(toolbar);
+ expect(startDragging).toHaveBeenCalledOnce();
+
+ isMaximized.mockResolvedValue(true);
+ await mouseDown(toolbar);
+ expect(startDragging).toHaveBeenCalledTimes(2);
+ expect(isMaximized).toHaveBeenCalledTimes(2);
+ expect(isFullscreen).toHaveBeenCalledTimes(2);
+ });
+
+ it.each([false, true])('blocks Windows fullscreen with maximized=%s and allows dragging after leaving it without rerendering', async maximized => {
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+ isMaximized.mockResolvedValue(maximized);
+ isFullscreen.mockResolvedValue(true);
+ const toolbar = renderBar(2);
+ await mouseDown(toolbar);
+ expect(startDragging).not.toHaveBeenCalled();
+
+ isFullscreen.mockResolvedValue(false);
+ await mouseDown(toolbar);
+ expect(startDragging).toHaveBeenCalledOnce();
+ });
+
it('uses click detail to preserve double-click maximize without blocking separate drags', async () => {
const toolbar = renderBar(2);
await mouseDown(toolbar);
@@ -245,7 +304,7 @@ describe('SceneTopBar', () => {
{ maximized: true, fullscreen: false },
{ maximized: false, fullscreen: true },
{ maximized: true, fullscreen: true },
- ])('blocks dragging while maximized=$maximized/fullscreen=$fullscreen and restores it without rerendering', async ({ maximized, fullscreen }) => {
+ ])('keeps non-Windows dragging blocked while maximized=$maximized/fullscreen=$fullscreen and restores it without rerendering', async ({ maximized, fullscreen }) => {
const toolbar = renderBar(2);
await mouseDown(toolbar);
expect(startDragging).toHaveBeenCalledOnce();
diff --git a/src/web-ui/src/app/startup/startupPreload.test.ts b/src/web-ui/src/app/startup/startupPreload.test.ts
index 908fae294d..b82fb75183 100644
--- a/src/web-ui/src/app/startup/startupPreload.test.ts
+++ b/src/web-ui/src/app/startup/startupPreload.test.ts
@@ -153,12 +153,84 @@ describe('startup preload shell', () => {
dom.window.close();
});
+ it('refreshes the maximize button when a Windows caption drag restores the startup window', async () => {
+ let isMaximized = true;
+ const invoke = vi.fn(async (command: string, payload: { request?: { action: string } }) => {
+ if (command === 'startup_window_control' && payload.request?.action === 'get_state') return { isMaximized };
+ if (command === 'plugin:window|is_maximized') return isMaximized;
+ if (command === 'plugin:window|is_fullscreen') return false;
+ if (command === 'plugin:window|start_dragging') return;
+ throw new Error(`Unexpected window command: ${command}`);
+ });
+ const dom = new JSDOM(readIndexHtml(), {
+ url: 'http://localhost:1422/',
+ runScripts: 'dangerously',
+ pretendToBeVisual: true,
+ beforeParse(window) {
+ Object.defineProperty(window.navigator, 'platform', { value: 'Win32' });
+ Object.assign(window, {
+ __OPENBITFUN_BOOTSTRAP_LOCALE__: 'en-US',
+ __OPENBITFUN_SHOW_STARTUP_WINDOW_CONTROLS__: true,
+ __TAURI_INTERNALS__: { invoke, metadata: { currentWindow: { label: 'main' } } },
+ });
+ },
+ });
+
+ try {
+ const { window } = dom;
+ const overlay = window.document.getElementById('openbitfun-startup-overlay')!;
+ const controls = overlay.querySelector('[data-startup-window-controls]')!;
+ const button = controls.querySelector('[data-startup-window-action="toggle_maximize"]')!;
+ const getStateCalls = () => invoke.mock.calls.filter(([command, payload]) =>
+ command === 'startup_window_control' && payload.request?.action === 'get_state',
+ );
+ const resize = () => window.dispatchEvent(new window.Event('resize'));
+ const nextFrame = () => new Promise(resolve => window.requestAnimationFrame(() => resolve()));
+
+ await vi.waitFor(() => expect(getStateCalls()).toHaveLength(2));
+ expect(button.getAttribute('aria-label')).toBe('Restore');
+ expect(button.querySelector('svg:not([style*="display: none"])')?.classList).toContain('lucide-copy');
+
+ overlay.dispatchEvent(new window.MouseEvent('mousedown', { bubbles: true, button: 0, detail: 1 }));
+ await vi.waitFor(() => expect(invoke).toHaveBeenCalledWith('plugin:window|start_dragging', { label: 'main' }));
+
+ // The native window changes size after the drag request has been accepted.
+ isMaximized = false;
+ resize();
+ resize();
+ await nextFrame();
+ expect(controls.hasAttribute('data-openbitfun-state')).toBe(false);
+ expect(button.getAttribute('aria-label')).toBe('Maximize');
+ expect(button.getAttribute('title')).toBe('Maximize');
+ expect(button.querySelector('svg:not([style*="display: none"])')?.classList).toContain('lucide-square');
+ expect(getStateCalls()).toHaveLength(3);
+
+ resize();
+ overlay.setAttribute('inert', '');
+ await nextFrame();
+ expect(getStateCalls()).toHaveLength(3);
+
+ resize();
+ window.dispatchEvent(new window.Event('openbitfun:startup-overlay-hidden'));
+ overlay.remove();
+ resize();
+ await nextFrame();
+ expect(getStateCalls()).toHaveLength(3);
+ } finally {
+ dom.window.close();
+ }
+ });
+
it.each([
- { maximized: true, fullscreen: false, showControls: true },
- { maximized: false, fullscreen: true, showControls: true },
- { maximized: true, fullscreen: true, showControls: true },
- { maximized: true, fullscreen: false, showControls: false },
- ])('guards pre-React dragging with maximized=$maximized/fullscreen=$fullscreen/controls=$showControls', async ({ maximized, fullscreen, showControls }) => {
+ ...['Win32', 'Linux x86_64', 'MacIntel'].flatMap(platform => [
+ { platform, maximized: false, fullscreen: false, showControls: true },
+ { platform, maximized: true, fullscreen: false, showControls: true },
+ { platform, maximized: false, fullscreen: true, showControls: true },
+ { platform, maximized: true, fullscreen: true, showControls: true },
+ ]),
+ { platform: 'Win32', maximized: true, fullscreen: false, showControls: false },
+ { platform: 'Win32', maximized: true, fullscreen: true, showControls: false },
+ ])('guards pre-React $platform dragging with maximized=$maximized/fullscreen=$fullscreen/controls=$showControls', async ({ platform, maximized, fullscreen, showControls }) => {
const state = { maximized, fullscreen };
const invoke = vi.fn(async (command: string, payload: { request?: { action: string } }) => {
if (command === 'plugin:window|is_maximized') return state.maximized;
@@ -174,6 +246,8 @@ describe('startup preload shell', () => {
url: 'http://localhost:1422/',
runScripts: 'dangerously',
beforeParse(window) {
+ Object.defineProperty(window.navigator, 'platform', { value: platform });
+ Object.defineProperty(window.navigator, 'userAgent', { value: '' });
Object.assign(window, {
__OPENBITFUN_SHOW_STARTUP_WINDOW_CONTROLS__: showControls,
__TAURI_INTERNALS__: { invoke, metadata: { currentWindow: { label: 'main' } } },
@@ -192,7 +266,9 @@ describe('startup preload shell', () => {
expect(dom.window.document.querySelector('[data-tauri-drag-region]')).toBeNull();
mouseDown(overlay);
await flush();
- expect(dragCalls()).toHaveLength(0);
+ const initiallyAllowed = !fullscreen && (!maximized || platform === 'Win32');
+ const initialDragCount = initiallyAllowed ? 1 : 0;
+ expect(dragCalls()).toHaveLength(initialDragCount);
// Restore through the static shell, without React or a cached resize update.
state.fullscreen = false;
@@ -202,20 +278,85 @@ describe('startup preload shell', () => {
expect(state.maximized).toBe(false);
mouseDown(overlay);
await flush();
- expect(dragCalls()).toEqual([['plugin:window|start_dragging', { label: 'main' }]]);
+ expect(dragCalls()).toEqual(Array.from({ length: initialDragCount + 1 }, () =>
+ ['plugin:window|start_dragging', { label: 'main' }],
+ ));
mouseDown(overlay, { button: 1 });
mouseDown(overlay, { button: 2 });
mouseDown(overlay, { detail: 2 });
mouseDown(overlay.querySelector('[data-startup-window-action="toggle_maximize"] svg')!);
await flush();
- expect(dragCalls()).toHaveLength(1);
+ expect(dragCalls()).toHaveLength(initialDragCount + 1);
// A pending state read must not start dragging after the startup handoff.
mouseDown(overlay);
overlay.setAttribute('inert', '');
await flush();
- expect(dragCalls()).toHaveLength(1);
+ expect(dragCalls()).toHaveLength(initialDragCount + 1);
+
+ overlay.removeAttribute('inert');
+ mouseDown(overlay);
+ overlay.remove();
+ await flush();
+ expect(dragCalls()).toHaveLength(initialDragCount + 1);
+ } finally {
+ dom.window.close();
+ }
+ });
+
+ it.each(['browser', 'missing-metadata'])('does not expose startup gestures in a %s runtime', async runtime => {
+ const invoke = vi.fn(async () => false);
+ const dom = new JSDOM(readIndexHtml(), {
+ url: 'http://localhost:1422/',
+ runScripts: 'dangerously',
+ beforeParse(window) {
+ Object.defineProperty(window.navigator, 'platform', { value: 'Win32' });
+ if (runtime === 'missing-metadata') {
+ Object.assign(window, { __TAURI_INTERNALS__: { invoke } });
+ }
+ },
+ });
+ try {
+ const overlay = dom.window.document.getElementById('openbitfun-startup-overlay')!;
+ overlay.dispatchEvent(new dom.window.MouseEvent('mousedown', { bubbles: true, button: 0, detail: 1 }));
+ overlay.dispatchEvent(new dom.window.MouseEvent('dblclick', { bubbles: true, button: 0, detail: 2 }));
+ await new Promise(resolve => setTimeout(resolve, 0));
+ expect(invoke).not.toHaveBeenCalled();
+ } finally {
+ dom.window.close();
+ }
+ });
+
+ it.each([
+ { maximized: undefined, fullscreen: false },
+ { maximized: 'false', fullscreen: false },
+ { maximized: false, fullscreen: undefined },
+ { maximized: false, fullscreen: 'false' },
+ ])('requires boolean startup window state with maximized=$maximized/fullscreen=$fullscreen', async ({ maximized, fullscreen }) => {
+ const invoke = vi.fn(async (command: string) => {
+ if (command === 'plugin:window|is_maximized') return maximized;
+ if (command === 'plugin:window|is_fullscreen') return fullscreen;
+ if (command === 'plugin:window|start_dragging') return;
+ throw new Error(`Unexpected window command: ${command}`);
+ });
+ const dom = new JSDOM(readIndexHtml(), {
+ url: 'http://localhost:1422/',
+ runScripts: 'dangerously',
+ beforeParse(window) {
+ Object.defineProperty(window.navigator, 'platform', { value: 'Win32' });
+ Object.assign(window, {
+ __TAURI_INTERNALS__: { invoke, metadata: { currentWindow: { label: 'main' } } },
+ });
+ },
+ });
+ try {
+ const overlay = dom.window.document.getElementById('openbitfun-startup-overlay')!;
+ overlay.dispatchEvent(new dom.window.MouseEvent('mousedown', { bubbles: true, button: 0, detail: 1 }));
+ await new Promise(resolve => setTimeout(resolve, 0));
+ expect(invoke.mock.calls.map(([command]) => command)).toEqual([
+ 'plugin:window|is_maximized', 'plugin:window|is_fullscreen',
+ ]);
} finally {
dom.window.close();
}
diff --git a/src/web-ui/src/infrastructure/runtime/window.test.ts b/src/web-ui/src/infrastructure/runtime/window.test.ts
new file mode 100644
index 0000000000..6207e52efc
--- /dev/null
+++ b/src/web-ui/src/infrastructure/runtime/window.test.ts
@@ -0,0 +1,58 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { startNativeWindowDragging } from './window';
+
+const nativeWindow = vi.hoisted(() => ({
+ isMaximized: vi.fn(async () => false),
+ isFullscreen: vi.fn(async () => false),
+ startDragging: vi.fn(async () => {}),
+}));
+const getCurrentWindow = vi.hoisted(() => vi.fn(() => nativeWindow));
+vi.mock('@tauri-apps/api/window', () => ({ getCurrentWindow }));
+
+describe('native window dragging', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.stubGlobal('window', {
+ __TAURI_INTERNALS__: {
+ invoke: vi.fn(),
+ metadata: { currentWindow: { label: 'main' } },
+ },
+ });
+ });
+
+ afterEach(() => vi.unstubAllGlobals());
+
+ it.each(['Win32', 'Linux x86_64', 'MacIntel'].flatMap(platform => [
+ { platform, maximized: false, fullscreen: false },
+ { platform, maximized: true, fullscreen: false },
+ { platform, maximized: false, fullscreen: true },
+ { platform, maximized: true, fullscreen: true },
+ ]))('uses local $platform policy for maximized=$maximized/fullscreen=$fullscreen', async ({ platform, maximized, fullscreen }) => {
+ vi.stubGlobal('navigator', { platform, userAgent: '' });
+ nativeWindow.isMaximized.mockResolvedValue(maximized);
+ nativeWindow.isFullscreen.mockResolvedValue(fullscreen);
+
+ await startNativeWindowDragging();
+
+ expect(getCurrentWindow).toHaveBeenCalledOnce();
+ expect(nativeWindow.isMaximized).toHaveBeenCalledOnce();
+ expect(nativeWindow.isFullscreen).toHaveBeenCalledOnce();
+ expect(nativeWindow.startDragging).toHaveBeenCalledTimes(
+ !fullscreen && (!maximized || platform === 'Win32') ? 1 : 0,
+ );
+ });
+
+ it.each([
+ { name: 'server', localWindow: undefined },
+ { name: 'browser', localWindow: {} },
+ { name: 'host without current-window metadata', localWindow: { __TAURI_INTERNALS__: { invoke: vi.fn() } } },
+ ])('does not call native APIs in a $name', async ({ localWindow }) => {
+ vi.stubGlobal('window', localWindow);
+ vi.stubGlobal('navigator', { platform: 'Win32', userAgent: 'Windows' });
+
+ await startNativeWindowDragging();
+
+ expect(getCurrentWindow).not.toHaveBeenCalled();
+ expect(nativeWindow.startDragging).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/web-ui/src/infrastructure/runtime/window.ts b/src/web-ui/src/infrastructure/runtime/window.ts
index 8b00f5a2bf..6e91f92f70 100644
--- a/src/web-ui/src/infrastructure/runtime/window.ts
+++ b/src/web-ui/src/infrastructure/runtime/window.ts
@@ -1,4 +1,4 @@
-import { supportsNativeWindowDragging } from './environment';
+import { isWindowsDesktopRuntime, supportsNativeWindowDragging } from './environment';
/** Window chrome always belongs to the controller, including Peer Device Mode. */
export async function startNativeWindowDragging(): Promise {
@@ -11,7 +11,8 @@ export async function startNativeWindowDragging(): Promise {
appWindow.isMaximized(),
appWindow.isFullscreen(),
]);
- if (isMaximized || isFullscreen) return;
+ // Windows caption dragging restores maximized windows and follows the pointer.
+ if (isFullscreen || (isMaximized && !isWindowsDesktopRuntime())) return;
await appWindow.startDragging();
}