Files
cc-switch/src/lib/platform.ts
T
Jason 64c068415e fix(linux): repair unresponsive UI on startup and full-screen panels
Linux users reported the window UI (including native title bar buttons)
couldn't receive clicks until manually maximizing and restoring the
window. Root causes: (1) Tauri webview did not acquire focus on startup
so first clicks were consumed by X11/Wayland click-to-activate
(Tauri #10746, wry #637); (2) GTK surface input region failed to
renegotiate on the visible:false + show() path under some
WebKitGTK/compositor combinations.

- Add linux_fix::nudge_main_window helper that performs set_focus plus
  a ±1px no-op resize after window show, with a 500ms reconciliation
  readback to compensate for dropped resize requests on slow
  compositors.
- Wire the helper into every window re-show path: normal startup,
  deeplink, single_instance, tray show_main, and lightweight exit.
- Set WEBKIT_DISABLE_COMPOSITING_MODE=1 at startup to avoid resize
  crashes and Wayland surface negotiation issues.
- Remove data-tauri-drag-region on Linux from App.tsx header and the
  shared FullScreenPanel (used by all provider/MCP/workspace forms)
  to avoid Tauri #13440 in Wayland sessions. Extract drag-region
  constants to src/lib/platform.ts for reuse.

All Rust changes are gated by #[cfg(target_os = "linux")]; frontend
changes preserve macOS/Windows behavior via runtime isLinux() checks.
Known limitation: tiling Wayland compositors ignore set_size, so
GDK_BACKEND=x11 remains the user-side workaround.
2026-04-09 16:49:13 +08:00

49 lines
1.5 KiB
TypeScript

// 轻量平台检测,避免在 SSR 或无 navigator 的环境报错
export const isMac = (): boolean => {
try {
const ua = navigator.userAgent || "";
const plat = (navigator.platform || "").toLowerCase();
return /mac/i.test(ua) || plat.includes("mac");
} catch {
return false;
}
};
export const isWindows = (): boolean => {
try {
const ua = navigator.userAgent || "";
return /windows|win32|win64/i.test(ua);
} catch {
return false;
}
};
export const isLinux = (): boolean => {
try {
const ua = navigator.userAgent || "";
// WebKitGTK/Chromium 在 Linux/Wayland/X11 下 UA 通常包含 Linux 或 X11
return (
/linux|x11/i.test(ua) && !/android/i.test(ua) && !isMac() && !isWindows()
);
} catch {
return false;
}
};
// Linux 上禁用所有 drag region,规避 Wayland 下 gtk_window_begin_move_drag
// 相关的窗口事件异常(Tauri #13440)。macOS 上保留原有拖动行为;Windows
// 项目原本就不依赖这个。
//
// 这些常量设计为通过 JSX 属性 spread 消费(`{...DRAG_REGION_ATTR}`),
// 因为 `data-tauri-drag-region` 是 wry 侧的 attribute 存在性检测,必须
// 完全不渲染属性才算禁用;空字符串或 "false" 仍会触发。
export const DRAG_REGION_ENABLED = !isLinux();
export const DRAG_REGION_ATTR: Record<string, unknown> = DRAG_REGION_ENABLED
? { "data-tauri-drag-region": true }
: {};
export const DRAG_REGION_STYLE: Record<string, unknown> = DRAG_REGION_ENABLED
? { WebkitAppRegion: "drag" }
: {};