feat(desktop): enable Electron migration path

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:package: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
This commit is contained in:
程序员阿江(Relakkes)
2026-06-01 22:43:16 +08:00
parent ebc78befbe
commit 386a41e606
203 changed files with 14661 additions and 1439 deletions
+20 -18
View File
@@ -1,6 +1,6 @@
import { create } from 'zustand'
import type { Update } from '@tauri-apps/plugin-updater'
import { isTauriRuntime } from '../lib/desktopRuntime'
import { getDesktopHost } from '../lib/desktopHost'
import type { DesktopHost, DesktopUpdate } from '../lib/desktopHost'
import type { UpdateProxySettings } from '../types/settings'
import { useSettingsStore } from './settingsStore'
@@ -33,13 +33,13 @@ type UpdateStore = {
checkedAt: number | null
shouldPrompt: boolean
initialize: () => Promise<void>
checkForUpdates: (options?: CheckOptions) => Promise<Update | null>
checkForUpdates: (options?: CheckOptions) => Promise<DesktopUpdate | null>
downloadUpdate: () => Promise<void>
installUpdate: () => Promise<void>
dismissPrompt: () => void
}
let pendingUpdate: Update | null = null
let pendingUpdate: DesktopUpdate | null = null
let pendingUpdateProxyKey: string | null = null
let pendingUpdateDownloaded = false
let downloadPromise: Promise<void> | null = null
@@ -86,7 +86,12 @@ function getUpdateCheckOptions() {
return proxy ? { proxy } : undefined
}
async function setPendingUpdate(next: Update | null, proxyKey: string | null) {
function getUpdateHost(): DesktopHost | null {
const host = getDesktopHost()
return host.capabilities.updates ? host : null
}
async function setPendingUpdate(next: DesktopUpdate | null, proxyKey: string | null) {
const previous = pendingUpdate
pendingUpdate = next
pendingUpdateProxyKey = next ? proxyKey : null
@@ -124,7 +129,7 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
shouldPrompt: false,
initialize: async () => {
if (!isTauriRuntime()) return
if (!getUpdateHost()) return
if (!startupCheckPromise) {
startupCheckPromise = (async () => {
await new Promise((resolve) => setTimeout(resolve, 5000))
@@ -138,7 +143,8 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
},
checkForUpdates: async ({ silent = false, autoDownload = true } = {}) => {
if (!isTauriRuntime()) return null
const host = getUpdateHost()
if (!host) return null
if (downloadPromise && get().status === 'downloading' && pendingUpdate) return pendingUpdate
set((state) => ({
@@ -148,9 +154,8 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
}))
try {
const { check } = await import('@tauri-apps/plugin-updater')
const updateProxyKey = getUpdateProxyKey()
const update = await check(getUpdateCheckOptions())
const update = await host.updates.check(getUpdateCheckOptions())
await setPendingUpdate(update, updateProxyKey)
const checkedAt = Date.now()
@@ -214,7 +219,7 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
},
downloadUpdate: async () => {
if (!isTauriRuntime()) return
if (!getUpdateHost()) return
let update = pendingUpdate
if (update && pendingUpdateProxyKey !== getUpdateProxyKey()) {
@@ -332,7 +337,8 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
},
installUpdate: async () => {
if (!isTauriRuntime()) return
const host = getUpdateHost()
if (!host) return
let update = pendingUpdate
if (update && pendingUpdateProxyKey !== getUpdateProxyKey()) {
@@ -352,9 +358,6 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
}
if (!pendingUpdateDownloaded) return
const { invoke } = await import('@tauri-apps/api/core')
const { relaunch } = await import('@tauri-apps/plugin-process')
set((state) => ({
...state,
status: 'installing',
@@ -364,7 +367,7 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
}))
prepareInstallAttempted = true
await invoke('prepare_for_update_install')
await host.updates.prepareInstall()
await update.install()
set((state) => ({
@@ -373,12 +376,11 @@ export const useUpdateStore = create<UpdateStore>((set, get) => ({
progressPercent: 100,
}))
await relaunch()
await host.updates.relaunch()
} catch (error) {
if (prepareInstallAttempted) {
try {
const { invoke } = await import('@tauri-apps/api/core')
await invoke('cancel_update_install')
await host.updates.cancelInstall()
} catch {
// Best effort: keep the update prompt recoverable even if native reset fails.
}