// shared/types.ts - 共享类型定义 // 此文件在 Electron 主进程和 Vue 渲染进程之间共享 // ==================== 基础类型 ==================== export type SoftwareType = 'nodejs' | 'pnpm' | 'vscode' | 'git' | 'claudeCode' export type SoftwareTypeWithAll = SoftwareType | 'all' export type Platform = 'win32' | 'darwin' | 'linux' export type ToastType = 'success' | 'warning' | 'error' | 'info' export type SystemStatusType = 'success' | 'warning' | 'error' // Tab ID 类型 export type TabId = 'intro' | 'nodejs' | 'vscode' | 'git' | 'claudeCode' | 'all' // ==================== 版本相关 ==================== export interface VersionItem { value: string label: string lts?: boolean disabled?: boolean separator?: boolean } export interface VersionResult { versions: VersionItem[] warning: string | null } // ==================== 安装相关 ==================== export interface InstallOptions { version?: string installPnpm?: boolean installNodejs?: boolean nodejsVersion?: string nodejsPath?: string // Node.js 自定义安装路径 (仅 Windows) installVscode?: boolean vscodeVersion?: string vscodePath?: string // VS Code 自定义安装路径 (仅 Windows) installGit?: boolean gitVersion?: string gitPath?: string // Git 自定义安装路径 (仅 Windows) installClaudeCode?: boolean installClaudeCodeExt?: boolean // Claude Code for VS Code 扩展 customPath?: string } export interface InstallStatus { software: SoftwareTypeWithAll message: string progress: number i18nKey?: string i18nParams?: Record skipLog?: boolean } export interface InstallResult { software: SoftwareTypeWithAll message: string i18nKey?: string i18nParams?: Record } export interface InstalledInfo { installed: boolean version: string | null path?: string | null } export interface AllInstalledInfo { nodejs: InstalledInfo pnpm: InstalledInfo vscode: InstalledInfo git: InstalledInfo claudeCode: InstalledInfo } export interface InstallHistoryItem { software: SoftwareTypeWithAll version: string options: InstallOptions success: boolean error?: string cancelled?: boolean duration?: number timestamp: number } // ==================== 系统相关 ==================== export interface PackageManagerResult { exists: boolean manager: 'none' | 'brew' | 'apt' } export interface CommandResult { command: string args: string[] } export type LogCategory = 'app' | 'install' export interface LogEntry { level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' message: string timestamp: string category?: LogCategory data?: unknown } // ==================== 镜像配置 ==================== export type GitMirrorType = 'huaweicloud' | 'github' export type NodejsMirrorType = 'huaweicloud' | 'official' export interface GitMirrorConfig { mirror: GitMirrorType } export interface NodejsMirrorConfig { mirror: NodejsMirrorType } // ==================== 自动更新 ==================== export type UpdateStatus = | 'checking' | 'available' | 'not-available' | 'downloading' | 'downloaded' | 'error' export interface UpdateProgress { percent: number bytesPerSecond: number total: number transferred: number } export interface UpdateResult { status: UpdateStatus info?: { version: string releaseDate?: string releaseNotes?: string } progress?: UpdateProgress error?: string } // ==================== Electron API ==================== export interface ElectronAPI { // 安装相关 install: (software: SoftwareTypeWithAll, options: InstallOptions) => Promise cancelInstall: () => Promise checkInstalled: (software: SoftwareTypeWithAll) => Promise uninstall: (software: SoftwareType) => Promise // 系统检测 checkAdmin: () => Promise checkPackageManager: () => Promise installPackageManager: (manager: string) => Promise<{ success: boolean; error?: string }> getPlatform: () => Promise checkNetwork: () => Promise // 版本 getVersions: (software: SoftwareType) => Promise checkUpdate: (software: SoftwareType) => Promise<{ hasUpdate: boolean; latestVersion?: string }> // Git 镜像配置 setGitMirror: (mirror: GitMirrorType) => Promise getGitMirrorConfig: () => Promise // Node.js 镜像配置 setNodejsMirror: (mirror: NodejsMirrorType) => Promise getNodejsMirrorConfig: () => Promise // 历史和日志 getInstallHistory: (limit?: number) => Promise getLogs: () => Promise writeInstallLog: (message: string, level?: 'info' | 'warn' | 'error') => Promise getLogPaths: () => Promise<{ appLog: string; installLog: string }> // 文件夹选择 selectDirectory: (defaultPath?: string) => Promise<{ canceled: boolean; path: string | null }> // 窗口操作 setWindowTitle: (title: string) => Promise windowMinimize: () => Promise windowMaximize: () => Promise windowClose: () => Promise windowIsMaximized: () => Promise saveWindowState: () => void saveWindowStateImmediate: () => Promise startWindowStateListener: () => void restoreWindowState: () => Promise // Claude Code checkClaudeCode: () => Promise<{ installed: boolean; version: string | null }> launchClaudeCode: () => Promise<{ success: boolean }> installClaudeCode: () => Promise<{ success: boolean; error?: string }> openClaudeCodeConfig: () => Promise<{ success: boolean; error?: string }> deleteClaudeEnvVars: () => Promise<{ success: boolean; error?: string; deleted_vars: string[] }> // VS Code Extensions checkVscodeExtension: (extensionId: string) => Promise<{ installed: boolean; version?: string }> installVscodeExtension: (extensionId: string) => Promise<{ success: boolean; error?: string }> uninstallVscodeExtension: (extensionId: string) => Promise<{ success: boolean; error?: string }> // 事件监听 onInstallStatus: (callback: (data: InstallStatus) => void) => void onInstallComplete: (callback: (data: InstallResult) => void) => void onInstallError: (callback: (data: InstallResult) => void) => void onNetworkChange: (callback: (online: boolean) => void) => void removeAllListeners: () => void // 自动更新 updaterCheck: () => Promise updaterDownload: () => Promise updaterInstall: () => Promise updaterVersion: () => Promise updaterIsPortable: () => Promise onUpdaterStatus: (callback: (data: UpdateResult) => void) => void } // Window API 类型声明 // 注意:在 Tauri 环境中,API 通过 @tauri-apps/api 导入 // 这里保留 electronAPI 声明以兼容现有代码 declare global { interface Window { electronAPI: ElectronAPI __TAURI__?: unknown } }