Файли
openidea/src/windowBoot.tsx
T
科里亚таl0ng-ai 13b8024588 fix(titlebar): do not start a stuck window drag when activating on Windows (#7146)
* fix(titlebar): do not start a stuck window drag when activating on Windows (#7142)

A click on the title bar of a background window raised it and also started
Tauri's caption drag. start_dragging posts WM_NCLBUTTONDOWN/HTCAPTION; if
the button is already up when that message runs, Win32 follows the cursor
until the next click.

On Windows the title bar now uses the same custom drag path as macOS: a
press only arms the drag, and the native drag starts on a move while the
button is still held. window_start_drag also checks GetAsyncKeyState.
Double-click zoom still happens on the second press. Linux is unchanged.

* chore(bindings): regenerate windowStartDrag docs for the Windows drag fix

`cargo test -p openidea --test export_bindings` copies the new
window_start_drag rustdoc into src/bindings.ts. commands.snap is unchanged.

* fix(titlebar): preserve native Windows maximize, swapped mouse buttons, and drag state cleanup

---------

Co-authored-by: l0ng-ai <[email protected]>
2026-12-05 22:16:16 +08:00

116 рядки
4.9 KiB
TypeScript

import React, { useEffect, type ComponentType } from "react";
import ReactDOM from "react-dom/client";
import "./styles/global.css";
import { installRepeatedDoubleClick } from "./platform/doubleClick";
import { installErrorLogging, logError } from "./platform/errorLog";
import { installImeKeyGuard } from "./platform/ime";
import { installMiddleClickLinks } from "./platform/openUrl";
import { call, commands, isTauri } from "./platform/ipc";
import { installPageSwipeTracking } from "./platform/pageSwipe";
import { guessOs } from "./platform/platformInfo";
import { installPointerFocus } from "./platform/pointerFocus";
import { installReorderedTapClick } from "./platform/reordered-tap-click";
import { hideSplash } from "./platform/splash";
import { isWebMode } from "./platform/webBridge";
import { installMiddleClickPasteGuard, installWebKitClipboardGuard } from "./platform/webkitClipboard";
import { installMacCmdInputGuard } from "./platform/webkitCmdInput";
import { prefetchLazyComponents } from "./ui";
import { installFullscreenDragGuard, installWindowDrag, trackFullscreen } from "./workbench/window-drag";
export type Activate = () => void | (() => void);
export function activateList(what: string, list: ReadonlyArray<readonly [string, Activate]>): () => void {
const disposers: Array<() => void> = [];
for (const [name, activate] of list) {
try {
const d = activate();
if (d) disposers.push(d);
} catch (e) {
console.error(`${what} of ${name} failed to activate`, e);
}
}
return () => disposers.reverse().forEach((d) => d());
}
export async function installCommonWindowBoot(): Promise<void> {
const os = guessOs();
document.documentElement.dataset.os = os;
const desktop = isTauri() && !isWebMode();
if (import.meta.env.DEV && desktop) {
// The Tauri MCP bridge returns eval results via `window.__TAURI__` on Windows/Linux
// (macOS evaluates natively). Dev only, so release builds keep withGlobalTauri off.
const [{ invoke }, { emit }] = await Promise.all([import("@tauri-apps/api/core"), import("@tauri-apps/api/event")]);
(window as unknown as { __TAURI__?: unknown }).__TAURI__ ??= { core: { invoke }, event: { emit } };
}
installRepeatedDoubleClick();
// WebKit only (bug 219670 and spurious ⌘-punctuation text insertion). In Chromium (the e2e
// browser) a scripted double-click stamps its second press like the release before it, which the
// shim would take for a reordered tap and click twice.
if (os === "macos" && !/Chrome|Firefox/.test(navigator.userAgent)) {
installReorderedTapClick();
installMacCmdInputGuard();
}
if (os === "linux" && desktop) {
installWebKitClipboardGuard();
installMiddleClickPasteGuard();
}
if (desktop) {
const fullscreen = os !== "macos" ? trackFullscreen() : () => false;
// On macOS, a double click on the title bar fills the work area; the backend steps the frame
// once per presented webview frame, because AppKit's own zoom hides the page until the resize
// ends. On Windows, leave toggleMaximize unset to use native Win32 maximize/restore.
installWindowDrag({
toggleMaximize:
os === "macos"
? () => call(commands.windowToggleZoom()).catch((e) => console.warn("cannot zoom the window", e))
: undefined,
// Windows title-bar drag must not run in full screen (#6029).
isFullscreen: os === "windows" ? fullscreen : undefined,
});
if (os !== "macos") installFullscreenDragGuard(fullscreen);
}
installPointerFocus();
installMiddleClickLinks();
installImeKeyGuard();
installErrorLogging();
installPageSwipeTracking(window);
}
export function mountWindowRoot(View: ComponentType, { prefetchLazy = false }: { prefetchLazy?: boolean } = {}): void {
function App() {
useEffect(() => {
hideSplash();
if (!prefetchLazy) return;
// The first file opened would otherwise also build the editor setup cold.
const warm = () => {
if (!document.querySelector(".cm-editor"))
void import("./editor/core/cm/prewarm").then((m) => m.prewarmEditor());
};
const idle =
typeof requestIdleCallback === "function"
? requestIdleCallback(warm, { timeout: 2000 })
: window.setTimeout(warm, 500);
// Views split out of the start-up bundle load in the background once the UI is up.
const stopPrefetch = prefetchLazyComponents();
return () => {
if (typeof cancelIdleCallback === "function") cancelIdleCallback(idle);
else window.clearTimeout(idle);
stopPrefetch();
};
}, []);
return <View />;
}
ReactDOM.createRoot(document.getElementById("root") as HTMLElement, {
onUncaughtError: (error) => {
logError("Uncaught render error", error);
window.dispatchEvent(new CustomEvent("openidea:boot-error", { detail: error }));
},
}).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
}