types.ts 6.8 KB

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