mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Introduce the Electron desktop shell alongside the existing React renderer and local Bun server boundary. The migration keeps the DesktopHost contract explicit across Tauri, Electron, and browser runtimes while adding Electron main/preload services for dialogs, shell, notifications, updates, tray/window lifecycle, terminal, preview WebContentsView, app mode, and release/package validation.
The commit also carries the latest local main desktop command updates, including agent slash entries and hidden-by-default markdown thinking details, so the packaged Electron build matches the current main UX surface.
Constraint: React renderer, local Bun server, REST/WebSocket, and sidecar boundaries must remain reusable during the migration
Constraint: macOS dev packages are ad-hoc signed and cannot prove Developer ID notarization or Gatekeeper release launch
Rejected: Browser-only smoke validation | it cannot exercise native dialogs, keychain prompts, notification behavior, or packaged app startup
Confidence: medium
Scope-risk: broad
Directive: Do not remove Tauri host support until signed Electron release artifacts pass native OS smoke on macOS, Windows, and Linux
Tested: bun run check:desktop
Tested: cd desktop && bun run check:electron
Tested: CSC_IDENTITY_AUTO_DISCOVERY=false bun run electron📦dir
Tested: bun run test:package-smoke --platform macos --package-kind dir --artifacts-dir desktop/build-artifacts/electron
Tested: Computer Use read packaged Electron app window at desktop/build-artifacts/electron/mac-arm64/Claude Code Haha.app
Not-tested: Developer ID signed/notarized Gatekeeper launch
Not-tested: Real OS notification click-to-session action
Not-tested: Windows and Linux packaged app smoke on real hosts
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { realpathSync, statSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const ALLOWED_EXTERNAL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:'])
|
|
const ALLOWED_SYSTEM_SETTINGS_URLS = new Set([
|
|
'ms-settings:notifications',
|
|
'x-apple.systempreferences:com.apple.preference.notifications',
|
|
])
|
|
const BLOCKED_EXECUTABLE_EXTENSIONS = new Set([
|
|
'.app',
|
|
'.bat',
|
|
'.cmd',
|
|
'.com',
|
|
'.exe',
|
|
'.msi',
|
|
'.ps1',
|
|
'.scr',
|
|
'.sh',
|
|
])
|
|
|
|
export function normalizeExternalUrl(target: string): string {
|
|
let url: URL
|
|
try {
|
|
url = new URL(target)
|
|
} catch {
|
|
throw new Error('External shell targets must be absolute URLs')
|
|
}
|
|
|
|
if (!ALLOWED_EXTERNAL_PROTOCOLS.has(url.protocol)) {
|
|
throw new Error(`Unsupported external URL scheme: ${url.protocol}`)
|
|
}
|
|
return url.toString()
|
|
}
|
|
|
|
export function normalizeOpenPath(target: string): string {
|
|
const filePath = target.startsWith('file://') ? fileURLToPath(target) : target
|
|
if (!path.isAbsolute(filePath)) {
|
|
throw new Error('System file paths must be absolute')
|
|
}
|
|
const realPath = realpathSync(filePath)
|
|
const stat = statSync(realPath)
|
|
if (!stat.isFile() && !stat.isDirectory()) {
|
|
throw new Error('System file paths must point to a file or directory')
|
|
}
|
|
if (isBlockedExecutablePath(realPath, stat.isDirectory())) {
|
|
throw new Error('System file paths must not point to executable apps or scripts')
|
|
}
|
|
return realPath
|
|
}
|
|
|
|
function isBlockedExecutablePath(realPath: string, isDirectory: boolean) {
|
|
const ext = path.extname(realPath).toLowerCase()
|
|
if (BLOCKED_EXECUTABLE_EXTENSIONS.has(ext)) return true
|
|
if (isDirectory) return false
|
|
if (process.platform === 'win32') return false
|
|
return (statSync(realPath).mode & 0o111) !== 0
|
|
}
|
|
|
|
export async function openExternalUrl(target: string): Promise<void> {
|
|
const { shell } = await import('electron')
|
|
await shell.openExternal(normalizeExternalUrl(target))
|
|
}
|
|
|
|
export function normalizeSystemSettingsUrl(target: string): string {
|
|
if (!ALLOWED_SYSTEM_SETTINGS_URLS.has(target)) {
|
|
throw new Error(`Unsupported system settings URL: ${target}`)
|
|
}
|
|
return target
|
|
}
|
|
|
|
export async function openSystemSettingsUrl(target: string): Promise<boolean> {
|
|
const { shell } = await import('electron')
|
|
await shell.openExternal(normalizeSystemSettingsUrl(target))
|
|
return true
|
|
}
|
|
|
|
export async function openSystemPath(target: string): Promise<void> {
|
|
const { shell } = await import('electron')
|
|
const error = await shell.openPath(normalizeOpenPath(target))
|
|
if (error) throw new Error(error)
|
|
}
|