types.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. path?: string | null
  58. }
  59. export interface AllInstalledInfo {
  60. nodejs: InstalledInfo
  61. pnpm: InstalledInfo
  62. vscode: InstalledInfo
  63. git: InstalledInfo
  64. claudeCode: InstalledInfo
  65. }
  66. export interface InstallHistoryItem {
  67. software: SoftwareTypeWithAll
  68. version: string
  69. options: InstallOptions
  70. success: boolean
  71. error?: string
  72. cancelled?: boolean
  73. duration?: number
  74. timestamp: number
  75. }
  76. // ==================== 系统相关 ====================
  77. export interface PackageManagerResult {
  78. exists: boolean
  79. manager: 'none' | 'brew' | 'apt'
  80. }
  81. export interface CommandResult {
  82. command: string
  83. args: string[]
  84. }
  85. export type LogCategory = 'app' | 'install'
  86. export interface LogEntry {
  87. level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'
  88. message: string
  89. timestamp: string
  90. category?: LogCategory
  91. data?: unknown
  92. }
  93. // ==================== 镜像配置 ====================
  94. export type GitMirrorType = 'huaweicloud' | 'github'
  95. export type NodejsMirrorType = 'huaweicloud' | 'official'
  96. export interface GitMirrorConfig {
  97. mirror: GitMirrorType
  98. }
  99. export interface NodejsMirrorConfig {
  100. mirror: NodejsMirrorType
  101. }
  102. // ==================== 自动更新 ====================
  103. export type UpdateStatus =
  104. | 'checking'
  105. | 'available'
  106. | 'not-available'
  107. | 'downloading'
  108. | 'downloaded'
  109. | 'error'
  110. export interface UpdateProgress {
  111. percent: number
  112. bytesPerSecond: number
  113. total: number
  114. transferred: number
  115. }
  116. export interface UpdateResult {
  117. status: UpdateStatus
  118. info?: {
  119. version: string
  120. releaseDate?: string
  121. releaseNotes?: string
  122. }
  123. progress?: UpdateProgress
  124. error?: string
  125. }
  126. // ==================== Electron API ====================
  127. export interface ElectronAPI {
  128. // 安装相关
  129. install: (software: SoftwareTypeWithAll, options: InstallOptions) => Promise<void>
  130. cancelInstall: () => Promise<boolean>
  131. checkInstalled: (software: SoftwareTypeWithAll) => Promise<InstalledInfo | AllInstalledInfo>
  132. uninstall: (software: SoftwareType) => Promise<boolean>
  133. // 系统检测
  134. checkAdmin: () => Promise<boolean>
  135. checkPackageManager: () => Promise<PackageManagerResult>
  136. installPackageManager: (manager: string) => Promise<{ success: boolean; error?: string }>
  137. getPlatform: () => Promise<Platform>
  138. checkNetwork: () => Promise<boolean>
  139. // 版本
  140. getVersions: (software: SoftwareType) => Promise<VersionResult>
  141. checkUpdate: (software: SoftwareType) => Promise<{ hasUpdate: boolean; latestVersion?: string }>
  142. // Git 镜像配置
  143. setGitMirror: (mirror: GitMirrorType) => Promise<void>
  144. getGitMirrorConfig: () => Promise<GitMirrorConfig>
  145. // Node.js 镜像配置
  146. setNodejsMirror: (mirror: NodejsMirrorType) => Promise<void>
  147. getNodejsMirrorConfig: () => Promise<NodejsMirrorConfig>
  148. // 历史和日志
  149. getInstallHistory: (limit?: number) => Promise<InstallHistoryItem[]>
  150. getLogs: () => Promise<LogEntry[]>
  151. writeInstallLog: (message: string, level?: 'info' | 'warn' | 'error') => Promise<void>
  152. getLogPaths: () => Promise<{ appLog: string; installLog: string }>
  153. // 文件夹选择
  154. selectDirectory: (defaultPath?: string) => Promise<{ canceled: boolean; path: string | null }>
  155. // 窗口操作
  156. setWindowTitle: (title: string) => Promise<void>
  157. windowMinimize: () => Promise<void>
  158. windowMaximize: () => Promise<boolean>
  159. windowClose: () => Promise<void>
  160. windowIsMaximized: () => Promise<boolean>
  161. saveWindowState: () => void
  162. saveWindowStateImmediate: () => Promise<void>
  163. startWindowStateListener: () => void
  164. restoreWindowState: () => Promise<void>
  165. // Claude Code
  166. checkClaudeCode: () => Promise<{ installed: boolean; version: string | null }>
  167. launchClaudeCode: () => Promise<{ success: boolean }>
  168. installClaudeCode: () => Promise<{ success: boolean; error?: string }>
  169. openClaudeCodeConfig: () => Promise<{ success: boolean; error?: string }>
  170. deleteClaudeEnvVars: () => Promise<{ success: boolean; error?: string; deleted_vars: string[] }>
  171. // VS Code Extensions
  172. checkVscodeExtension: (extensionId: string) => Promise<{ installed: boolean; version?: string }>
  173. installVscodeExtension: (extensionId: string) => Promise<{ success: boolean; error?: string }>
  174. uninstallVscodeExtension: (extensionId: string) => Promise<{ success: boolean; error?: string }>
  175. // 事件监听
  176. onInstallStatus: (callback: (data: InstallStatus) => void) => void
  177. onInstallComplete: (callback: (data: InstallResult) => void) => void
  178. onInstallError: (callback: (data: InstallResult) => void) => void
  179. onNetworkChange: (callback: (online: boolean) => void) => void
  180. removeAllListeners: () => void
  181. // 自动更新
  182. updaterCheck: () => Promise<UpdateResult>
  183. updaterDownload: () => Promise<UpdateResult>
  184. updaterInstall: () => Promise<void>
  185. updaterVersion: () => Promise<string>
  186. updaterIsPortable: () => Promise<boolean>
  187. onUpdaterStatus: (callback: (data: UpdateResult) => void) => void
  188. }
  189. // Window API 类型声明
  190. // 注意:在 Tauri 环境中,API 通过 @tauri-apps/api 导入
  191. // 这里保留 electronAPI 声明以兼容现有代码
  192. declare global {
  193. interface Window {
  194. electronAPI: ElectronAPI
  195. __TAURI__?: unknown
  196. }
  197. }