Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Thanks to the following open-source projects and community practices for referen
- [Electron](https://github.com/electron/electron): cross-platform desktop app capabilities and engineering practices.
- [agent-desktop](https://github.com/vercel-labs/agent-desktop) by Vercel Labs: a reference and directly reused native implementation for Windows / Linux Computer Use. Pinned to **1.0.2**, commit [`9eb9b296192fcb70bda25e918cd6dd66abfa3d0d`](https://github.com/vercel-labs/agent-desktop/tree/9eb9b296192fcb70bda25e918cd6dd66abfa3d0d), with the [Apache-2.0 license](native/agent-desktop/LICENSE), [provenance and file hashes](native/agent-desktop/UPSTREAM.json), and [local changes](native/agent-desktop/PATCHES.md) retained.
- [cc-switch](https://github.com/farion1231/cc-switch): reference for model provider configuration.
- [t3code](https://github.com/pingdotgg/t3code): visual texture and interaction design reference for the desktop UI.
- [LINUX DO](https://linux.do/): a new ideal developer community.
- [AtomGit](https://atomgit.com/NanmiCoder/cc-haha): code hosting for this project in China.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ cc-haha 是一个**桌面端 Claude Code 工作台**:多会话与全局搜索
- [Electron](https://github.com/electron/electron):跨端桌面应用能力与工程实践。
- [agent-desktop](https://github.com/vercel-labs/agent-desktop)(Vercel Labs):Windows / Linux Computer Use 参考并直接复用其原生实现。固定版本 **1.0.2**,commit [`9eb9b296192fcb70bda25e918cd6dd66abfa3d0d`](https://github.com/vercel-labs/agent-desktop/tree/9eb9b296192fcb70bda25e918cd6dd66abfa3d0d);保留 [Apache-2.0 许可](native/agent-desktop/LICENSE)、[来源与文件摘要](native/agent-desktop/UPSTREAM.json)及[本地改动说明](native/agent-desktop/PATCHES.md)。
- [cc-switch](https://github.com/farion1231/cc-switch):模型供应商配置能力参考。
- [t3code](https://github.com/pingdotgg/t3code):桌面端 UI 质感与交互设计参考。
- [LINUX DO](https://linux.do/):新的理想型开发者社区。
- [AtomGit](https://atomgit.com/NanmiCoder/cc-haha):为本项目提供国内代码托管。

Expand Down
15 changes: 11 additions & 4 deletions desktop/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ import {
} from './services/pets'
import {
installFullScreenKey,
installMacosWindowButtonsSync,
installWindowLifecycle,
readWindowState,
refreshWindowsDragHitTest,
restoreWindowMaximized,
saveWindowState,
showMainWindow,
syncMacosWindowButtons,
windowChromeOptionsForPlatform,
windowOptionsFromState,
MIN_WINDOW_HEIGHT,
Expand Down Expand Up @@ -991,10 +993,14 @@ function registerIpcHandlers() {
registerHandler(ELECTRON_IPC_CHANNELS.adaptersRestartSidecar, (_event, payload) => getServerRuntime().restartAdaptersSidecars((payload as { target?: 'wechat' } | undefined)?.target))
registerHandler(ELECTRON_IPC_CHANNELS.zoomSet, (event, payload) => {
const window = currentWindow(event)
window.webContents.setZoomFactor(normalizeZoomFactor(payload))
// Electron pushes the embedder's zoom into every browser guest; app zoom
// must not change the pages' own zoom.
if (window === mainWindow) workspaceBrowserService?.restorePageZoom()
const factor = normalizeZoomFactor(payload)
window.webContents.setZoomFactor(factor)
if (window === mainWindow) {
syncMacosWindowButtons(window, process.platform, factor)
// Electron pushes the embedder's zoom into every browser guest; app zoom
// must not change the pages' own zoom.
workspaceBrowserService?.restorePageZoom()
}
})
registerHandler(ELECTRON_IPC_CHANNELS.appearanceSetApplied, (_event, payload) => {
if (!isAppliedAppearance(payload)) return
Expand Down Expand Up @@ -1080,6 +1086,7 @@ async function createMainWindow() {
shouldQuit: () => isQuitting,
})
installFullScreenKey(mainWindow, process.platform)
installMacosWindowButtonsSync(mainWindow, process.platform)

const window = mainWindow
setNotificationBadge = createNotificationBadge({
Expand Down
27 changes: 24 additions & 3 deletions desktop/electron/services/nativeAppearance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const WARM_LIGHT = '#F6F0E1'
function appearance(overrides: Partial<AppliedAppearance> = {}): AppliedAppearance {
return {
isDark: false,
background: '#FFFFFF',
lightBackground: '#FFFFFF',
background: LIGHT_WINDOW_BACKGROUND,
lightBackground: LIGHT_WINDOW_BACKGROUND,
darkBackground: DARK_WINDOW_BACKGROUND,
followSystem: false,
...overrides,
Expand Down Expand Up @@ -234,6 +234,25 @@ describe('applyAppliedAppearance', () => {
expect(JSON.parse(readFileSync(appearanceStatePath(app, env), 'utf-8'))).toEqual(state)
})

it('repaints every live window cleanly for OLED dark and cold porcelain light themes', () => {
const { app, env } = makeApp()
const win = fakeWindow()

applyAppliedAppearance(
appearance({ isDark: true, background: '#000000', lightBackground: '#FCFCFC', darkBackground: '#000000' }),
{ app, windows: () => [win], env },
)
expect(win.setBackgroundColor).toHaveBeenLastCalledWith('#000000')
expect(startupWindowBackground(readAppearanceState(app, env), true)).toBe('#000000')

applyAppliedAppearance(
appearance({ isDark: false, background: '#FCFCFC', lightBackground: '#FCFCFC', darkBackground: '#000000' }),
{ app, windows: () => [win], env },
)
expect(win.setBackgroundColor).toHaveBeenLastCalledWith('#FCFCFC')
expect(startupWindowBackground(readAppearanceState(app, env), false)).toBe('#FCFCFC')
})

it('skips windows that were already torn down', () => {
// quit/quitAndInstall can leave destroyed windows in the list; touching
// one throws "Object has been destroyed".
Expand Down Expand Up @@ -267,8 +286,10 @@ describe('window background constants', () => {
// CSS and bootstrapScript.test.ts binds it to index.html, but the main
// process had its own copies. Without this, changing the palette would
// leave the pre-paint window color silently behind.
expect(LIGHT_WINDOW_BACKGROUND).toBe('#FCFCFC')
expect(DARK_WINDOW_BACKGROUND).toBe('#000000')
expect(LIGHT_WINDOW_BACKGROUND).toBe(THEME_BACKGROUNDS.white)
expect(DARK_WINDOW_BACKGROUND).toBe(THEME_BACKGROUNDS.dark)
expect(DARK_WINDOW_BACKGROUND).toBe(THEME_BACKGROUNDS['neutral-dark'])
// The defaults of each half — what a first launch paints before the
// renderer has reported a preference.
expect(THEME_BACKGROUNDS[DEFAULT_LIGHT_THEME]).toBe(LIGHT_WINDOW_BACKGROUND)
Expand Down
7 changes: 4 additions & 3 deletions desktop/electron/services/nativeAppearance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export const APPEARANCE_STATE_FILE = 'appearance-state.json'

/**
* Grounds used before the renderer has reported anything — the defaults of
* each half. Pinned to THEME_BACKGROUNDS by nativeAppearance.test.ts.
* each half (`white` = `#FCFCFC`, `neutral-dark` = `#000000`). Pinned to
* THEME_BACKGROUNDS by nativeAppearance.test.ts.
*/
export const LIGHT_WINDOW_BACKGROUND = '#FFFFFF'
export const DARK_WINDOW_BACKGROUND = '#201D17'
export const LIGHT_WINDOW_BACKGROUND = '#FCFCFC'
export const DARK_WINDOW_BACKGROUND = '#000000'

export type AppliedAppearance = {
isDark: boolean
Expand Down
171 changes: 170 additions & 1 deletion desktop/electron/services/windows.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { tmpdir } from 'node:os'
import { describe, expect, it, vi } from 'vitest'
import {
clampWindowStateToVisibleWorkArea,
captureWindowState,
computeMacosTrafficLightPosition,
hideWindowSafely,
hasMeaningfulIntersection,
installFullScreenKey,
installMacosWindowButtonsSync,
installWindowLifecycle,
isPersistableWindowState,
isWindowStateVisibleOnAnyDisplay,
readWindowState,
refreshWindowsDragHitTest,
restoreWindowMaximized,
showMainWindow,
syncMacosWindowButtons,
toggleWindowFullScreen,
windowChromeOptionsForPlatform,
windowOptionsFromState,
Expand Down Expand Up @@ -257,6 +260,7 @@ describe('Electron window service', () => {
// fullscreenable off, macOS demotes it to a zoom that only fills the desktop.
expect(windowChromeOptionsForPlatform('darwin')).toEqual({
titleBarStyle: 'hiddenInset',
trafficLightPosition: { x: 16, y: 19 },
fullscreenable: true,
})
expect(windowChromeOptionsForPlatform('linux')).toEqual({
Expand All @@ -265,6 +269,171 @@ describe('Electron window service', () => {
})
})

describe('macOS optical traffic-light centering', () => {
it.each([
[1.0, { x: 16, y: 19 }],
[1.25, { x: 16, y: 26 }],
[0.8, { x: 16, y: 14 }],
[1.5, { x: 16, y: 32 }],
[Number.NaN, { x: 16, y: 19 }],
[0, { x: 16, y: 19 }],
])('computes optical traffic-light position for zoom %s', (zoomFactor, expected) => {
expect(computeMacosTrafficLightPosition(zoomFactor)).toEqual(expected)
})

it.each([
[1.0, { x: 16, y: 19 }],
[1.25, { x: 16, y: 26 }],
[0.8, { x: 16, y: 14 }],
])('syncMacosWindowButtons centers buttons from webContents zoom %s on darwin', (zoomFactor, expected) => {
const setWindowButtonPosition = vi.fn()
const window = {
isDestroyed: () => false,
isFullScreen: () => false,
setWindowButtonPosition,
webContents: {
isDestroyed: () => false,
getZoomFactor: () => zoomFactor,
},
}

syncMacosWindowButtons(window as never, 'darwin')
expect(setWindowButtonPosition).toHaveBeenCalledWith(expected)
})

it('uses an explicit zoomFactor override when provided', () => {
const setWindowButtonPosition = vi.fn()
const window = {
isDestroyed: () => false,
isFullScreen: () => false,
setWindowButtonPosition,
webContents: {
isDestroyed: () => false,
getZoomFactor: () => 1.0,
},
}

syncMacosWindowButtons(window as never, 'darwin', 1.25)
expect(setWindowButtonPosition).toHaveBeenCalledWith({ x: 16, y: 26 })
})

it('is a no-op outside darwin', () => {
for (const platform of ['win32', 'linux'] as const) {
const setWindowButtonPosition = vi.fn()
const window = {
isDestroyed: () => false,
isFullScreen: () => false,
setWindowButtonPosition,
webContents: {
isDestroyed: () => false,
getZoomFactor: () => 1.25,
},
}

syncMacosWindowButtons(window as never, platform)
expect(setWindowButtonPosition).not.toHaveBeenCalled()
}
})

it('guards against destroyed, fullscreen, or non-supporting windows', () => {
const destroyedWindow = {
isDestroyed: () => true,
isFullScreen: vi.fn(),
setWindowButtonPosition: vi.fn(),
webContents: { getZoomFactor: vi.fn(() => 1.25) },
}
syncMacosWindowButtons(destroyedWindow as never, 'darwin')
expect(destroyedWindow.setWindowButtonPosition).not.toHaveBeenCalled()

const fullscreenWindow = {
isDestroyed: () => false,
isFullScreen: () => true,
setWindowButtonPosition: vi.fn(),
webContents: { getZoomFactor: vi.fn(() => 1.25) },
}
syncMacosWindowButtons(fullscreenWindow as never, 'darwin')
expect(fullscreenWindow.setWindowButtonPosition).not.toHaveBeenCalled()

const unsupportedWindow = {
isDestroyed: () => false,
isFullScreen: () => false,
webContents: { getZoomFactor: vi.fn(() => 1.25) },
}
expect(() => syncMacosWindowButtons(unsupportedWindow as never, 'darwin')).not.toThrow()
})

it('syncs on creation and re-syncs on leave-full-screen, did-finish-load, and zoom-changed on darwin', () => {
let zoomFactor = 1.0
const windowHandlers = new Map<string, () => void>()
const webContentsHandlers = new Map<string, () => void>()
const setWindowButtonPosition = vi.fn()
const window = {
isDestroyed: () => false,
isFullScreen: () => false,
setWindowButtonPosition,
on: vi.fn((event: string, handler: () => void) => {
windowHandlers.set(event, handler)
}),
webContents: {
isDestroyed: () => false,
getZoomFactor: () => zoomFactor,
on: vi.fn((event: string, handler: () => void) => {
webContentsHandlers.set(event, handler)
}),
},
}

installMacosWindowButtonsSync(window as never, 'darwin')
expect(setWindowButtonPosition).toHaveBeenLastCalledWith({ x: 16, y: 19 })

zoomFactor = 1.25
webContentsHandlers.get('zoom-changed')?.()
expect(setWindowButtonPosition).toHaveBeenLastCalledWith({ x: 16, y: 26 })

zoomFactor = 0.8
webContentsHandlers.get('did-finish-load')?.()
expect(setWindowButtonPosition).toHaveBeenLastCalledWith({ x: 16, y: 14 })

zoomFactor = 1.5
windowHandlers.get('leave-full-screen')?.()
expect(setWindowButtonPosition).toHaveBeenLastCalledWith({ x: 16, y: 32 })
})

it('does not attach traffic-light sync listeners outside darwin', () => {
for (const platform of ['win32', 'linux'] as const) {
const window = {
isDestroyed: () => false,
isFullScreen: () => false,
setWindowButtonPosition: vi.fn(),
on: vi.fn(),
webContents: {
isDestroyed: () => false,
getZoomFactor: () => 1.0,
on: vi.fn(),
},
}

installMacosWindowButtonsSync(window as never, platform)
expect(window.setWindowButtonPosition).not.toHaveBeenCalled()
expect(window.on).not.toHaveBeenCalled()
expect(window.webContents.on).not.toHaveBeenCalled()
}
})

it('wires traffic-light sync into main window creation and zoom IPC in main.ts', () => {
const desktopRoot = existsSync(path.resolve(process.cwd(), 'electron', 'main.ts'))
? process.cwd()
: path.resolve(process.cwd(), 'desktop')
const mainSource = readFileSync(path.join(desktopRoot, 'electron', 'main.ts'), 'utf-8')
const zoomHandler = mainSource.slice(
mainSource.indexOf('ELECTRON_IPC_CHANNELS.zoomSet'),
mainSource.indexOf('ELECTRON_IPC_CHANNELS.appearanceSetApplied'),
)
expect(zoomHandler).toContain('syncMacosWindowButtons(')
expect(mainSource).toContain('installMacosWindowButtonsSync(mainWindow, process.platform)')
})
})

it('refreshes Windows drag hit testing after the first frameless show', () => {
vi.useFakeTimers()
try {
Expand Down
Loading
Loading