types.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // shared/types.ts - 共享类型定义
  2. // 此文件在 Electron 主进程和 Vue 渲染进程之间共享
  3. // ==================== 基础类型 ====================
  4. export type SoftwareType = 'nodejs' | 'pnpm' | 'vscode' | 'git' | 'claudeCode'
  5. export type SoftwareTypeWithAll = SoftwareType | 'all'
  6. export type Platform = 'win32' | 'darwin' | 'linux'
  7. export type ToastType = 'success' | 'warning' | 'error' | 'info'
  8. export type SystemStatusType = 'success' | 'warning' | 'error'
  9. // Tab ID 类型
  10. export type TabId = 'intro' | 'nodejs' | 'vscode' | 'git' | 'claudeCode' | 'all'
  11. // ==================== 版本相关 ====================
  12. export interface VersionItem {
  13. value: string
  14. label: string
  15. lts?: boolean
  16. disabled?: boolean
  17. separator?: boolean
  18. }
  19. export interface VersionResult {
  20. versions: VersionItem[]
  21. warning: string | null
  22. }
  23. // ==================== 安装相关 ====================
  24. export interface InstallOptions {
  25. version?: string
  26. installPnpm?: boolean
  27. installNodejs?: boolean
  28. nodejsVersion?: string
  29. nodejsPath?: string // Node.js 自定义安装路径 (仅 Windows)
  30. installVscode?: boolean
  31. vscodeVersion?: string
  32. vscodePath?: string // VS Code 自定义安装路径 (仅 Windows)
  33. installGit?: boolean
  34. gitVersion?: string
  35. gitPath?: string // Git 自定义安装路径 (仅 Windows)
  36. installClaudeCode?: boolean
  37. installClaudeCodeExt?: boolean // Claude Code for VS Code 扩展
  38. customPath?: string
  39. }
  40. export interface InstallStatus {
  41. software: SoftwareTypeWithAll
  42. message: string
  43. progress: number
  44. i18nKey?: string
  45. i18nParams?: Record<string, string>
  46. skipLog?: boolean
  47. }
  48. export interface InstallResult {
  49. software: SoftwareTypeWithAll
  50. message: string
  51. i18nKey?: string
  52. i18nParams?: Record<string, string>
  53. }
  54. export interface InstalledInfo {
  55. installed: boolean
  56. version: string | null
  57. }
  58. export interface AllInstalledInfo {
  59. nodejs: InstalledInfo
  60. pnpm: InstalledInfo
  61. vscode: InstalledInfo
  62. git: InstalledInfo
  63. claudeCode: InstalledInfo
  64. }
  65. export interface InstallHistoryItem {
  66. software: SoftwareTypeWithAll
  67. version: string
  68. options: InstallOptions
  69. success: boolean
  70. error?: string
  71. cancelled?: boolean
  72. duration?: number
  73. timestamp: number
  74. }
  75. // ==================== 系统相关 ====================
  76. export interface PackageManagerResult {
  77. exists: boolean
  78. manager: 'none' | 'brew' | 'apt'
  79. }
  80. export interface CommandResult {
  81. command: string
  82. args: string[]
  83. }
  84. export type LogCategory = 'app' | 'install'
  85. export interface LogEntry {
  86. level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'
  87. message: string
  88. timestamp: string
  89. category?: LogCategory
  90. data?: unknown
  91. }
  92. // ==================== 镜像配置 ====================
  93. export type GitMirrorType = 'huaweicloud' | 'github'
  94. export type NodejsMirrorType = 'official' | 'npmmirror'
  95. export interface GitMirrorConfig {
  96. mirror: GitMirrorType
  97. }
  98. export interface NodejsMirrorConfig {
  99. mirror: NodejsMirrorType
  100. }
  101. // ==================== 自动更新 ====================
  102. export type UpdateStatus =
  103. | 'checking'
  104. | 'available'
  105. | 'not-available'
  106. | 'downloading'
  107. | 'downloaded'
  108. | 'error'
  109. export interface UpdateProgress {
  110. percent: number
  111. bytesPerSecond: number
  112. total: number
  113. transferred: number
  114. }
  115. export interface UpdateResult {
  116. status: UpdateStatus
  117. info?: {
  118. version: string
  119. releaseDate?: string
  120. releaseNotes?: string
  121. }
  122. progress?: UpdateProgress
  123. error?: string
  124. }
  125. // ==================== Electron API ====================
  126. export interface ElectronAPI {
  127. // 安装相关
  128. install: (software: SoftwareTypeWithAll, options: InstallOptions) => Promise<void>
  129. cancelInstall: () => Promise<boolean>
  130. checkInstalled: (software: SoftwareTypeWithAll) => Promise<InstalledInfo | AllInstalledInfo>
  131. uninstall: (software: SoftwareType) => Promise<boolean>
  132. // 系统检测
  133. checkAdmin: () => Promise<boolean>
  134. checkPackageManager: () => Promise<PackageManagerResult>
  135. installPackageManager: (manager: string) => Promise<{ success: boolean; error?: string }>
  136. getPlatform: () => Promise<Platform>
  137. checkNetwork: () => Promise<boolean>
  138. // 版本
  139. getVersions: (software: SoftwareType) => Promise<VersionResult>
  140. checkUpdate: (software: SoftwareType) => Promise<{ hasUpdate: boolean; latestVersion?: string }>
  141. // Git 镜像配置
  142. setGitMirror: (mirror: GitMirrorType) => Promise<void>
  143. getGitMirrorConfig: () => Promise<GitMirrorConfig>
  144. // Node.js 镜像配置
  145. setNodejsMirror: (mirror: NodejsMirrorType) => Promise<void>
  146. getNodejsMirrorConfig: () => Promise<NodejsMirrorConfig>
  147. // 历史和日志
  148. getInstallHistory: (limit?: number) => Promise<InstallHistoryItem[]>
  149. getLogs: () => Promise<LogEntry[]>
  150. writeInstallLog: (message: string, level?: 'info' | 'warn' | 'error') => Promise<void>
  151. getLogPaths: () => Promise<{ appLog: string; installLog: string }>
  152. // 文件夹选择
  153. selectDirectory: (defaultPath?: string) => Promise<{ canceled: boolean; path: string | null }>
  154. // 窗口操作
  155. setWindowTitle: (title: string) => Promise<void>
  156. windowMinimize: () => Promise<void>
  157. windowMaximize: () => Promise<boolean>
  158. windowClose: () => Promise<void>
  159. windowIsMaximized: () => Promise<boolean>
  160. // Claude Code
  161. checkClaudeCode: () => Promise<{ installed: boolean; version: string | null }>
  162. launchClaudeCode: () => Promise<{ success: boolean }>
  163. installClaudeCode: () => Promise<{ success: boolean; error?: string }>
  164. // VS Code Extensions
  165. checkVscodeExtension: (extensionId: string) => Promise<{ installed: boolean; version?: string }>
  166. installVscodeExtension: (extensionId: string) => Promise<{ success: boolean; error?: string }>
  167. // 事件监听
  168. onInstallStatus: (callback: (data: InstallStatus) => void) => void
  169. onInstallComplete: (callback: (data: InstallResult) => void) => void
  170. onInstallError: (callback: (data: InstallResult) => void) => void
  171. onNetworkChange: (callback: (online: boolean) => void) => void
  172. removeAllListeners: () => void
  173. // 自动更新
  174. updaterCheck: () => Promise<UpdateResult>
  175. updaterDownload: () => Promise<UpdateResult>
  176. updaterInstall: () => Promise<void>
  177. updaterVersion: () => Promise<string>
  178. updaterIsPortable: () => Promise<boolean>
  179. onUpdaterStatus: (callback: (data: UpdateResult) => void) => void
  180. }
  181. // Window.electronAPI 类型声明
  182. declare global {
  183. interface Window {
  184. electronAPI: ElectronAPI
  185. }
  186. }