Relakkes Yang 98b79ce51a fix: restore Windows custom desktop chrome
Use frameless Electron chrome only on Windows and remove the native Windows application menu so the packaged app matches the previous Tauri-style desktop surface.

Add a Windows-only manual drag fallback for desktop drag regions, while excluding tab reorder targets and preserving macOS/Linux native chrome and menu behavior.

Tested: cd desktop && bun run test --run electron/services/menu.test.ts electron/services/windows.test.ts src/hooks/useElectronWindowDragRegions.test.tsx src/components/layout/TabBar.test.tsx src/components/layout/Sidebar.test.tsx src/lib/desktopHost/electronHost.test.ts electron/ipc/capabilities.test.ts

Tested: cd desktop && SKIP_INSTALL=1 bun run build:windows-x64

Tested: Computer Use Windows packaged app smoke verified no native menu, custom controls, drag regions, tab reorder, close-to-background, and deepseek-v4-pro provider response FINAL_WINDOWS_ELECTRON_REAL_PROVIDER_OK.

Not-tested: full bun run verify.

Constraint: keep custom frameless behavior scoped to win32 so macOS and Linux native chrome paths remain intact.

Confidence: high

Scope-risk: moderate
2026-06-03 23:24:30 +08:00

111 lines
3.1 KiB
TypeScript

import type { App, BrowserWindow, MenuItemConstructorOptions } from 'electron'
import { ELECTRON_EVENT_CHANNELS } from '../ipc/channels'
import { hideWindowSafely, toggleWindowFullScreen } from './windows'
export type NativeMenuDestination = 'about' | 'settings'
type ApplicationMenuActions = {
hide?: () => void
close?: () => void
toggleFullScreen?: () => void
}
export function buildApplicationMenuTemplate(
appName: string,
onNavigate: (destination: NativeMenuDestination) => void,
platform = process.platform,
actions: ApplicationMenuActions = {},
): MenuItemConstructorOptions[] {
const appMenu: MenuItemConstructorOptions[] = platform === 'darwin'
? [{
label: appName,
submenu: [
{ label: `About ${appName}`, click: () => onNavigate('about') },
{ type: 'separator' },
{ label: 'Settings...', accelerator: 'CmdOrCtrl+,', click: () => onNavigate('settings') },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ label: `Hide ${appName}`, accelerator: 'Command+H', click: () => actions.hide?.() },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
}]
: [{
label: 'File',
submenu: [
{ label: 'Settings...', accelerator: 'Ctrl+,', click: () => onNavigate('settings') },
{ type: 'separator' },
{ role: 'quit' },
],
}]
return [
...appMenu,
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' },
],
},
{
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: platform === 'darwin' ? 'Ctrl+Command+F' : 'F11',
click: () => actions.toggleFullScreen?.(),
},
],
},
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
{ label: 'Close Window', accelerator: 'CmdOrCtrl+W', click: () => actions.close?.() },
],
},
]
}
export async function installApplicationMenu(
app: App,
getMainWindow: () => BrowserWindow | null,
platform: NodeJS.Platform = process.platform,
) {
const { Menu } = await import('electron')
if (platform === 'win32') {
Menu.setApplicationMenu(null)
return
}
const template = buildApplicationMenuTemplate(app.name || 'Claude Code Haha', destination => {
getMainWindow()?.webContents.send(ELECTRON_EVENT_CHANNELS.nativeMenuNavigate, destination)
}, platform, {
hide: () => {
const window = getMainWindow()
if (!window) {
app.hide?.()
return
}
hideWindowSafely(window, () => app.hide?.())
},
close: () => {
getMainWindow()?.close()
},
toggleFullScreen: () => {
const window = getMainWindow()
if (window) toggleWindowFullScreen(window, platform)
},
})
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}