constants.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // electron/modules/constants.ts - 常量定义
  2. import type { SoftwareType } from './types'
  3. // 支持的最低 Node.js 主版本
  4. export const MIN_SUPPORTED_NODE_VERSION = 18
  5. // 保留的主版本数量
  6. export const MAX_MAJOR_VERSIONS = 4
  7. // 网络请求超时时间(毫秒)
  8. export const REQUEST_TIMEOUT = 15000
  9. // 重试次数
  10. export const MAX_RETRIES = 3
  11. // 重试延迟(毫秒)
  12. export const RETRY_DELAY = 1000
  13. // 版本缓存时间(毫秒)- 30分钟(优化后)
  14. export const VERSION_CACHE_TTL = 30 * 60 * 1000
  15. // 包管理器源更新缓存时间(毫秒)- 1天
  16. export const SOURCE_UPDATE_CACHE_TTL = 24 * 60 * 60 * 1000
  17. // 需要版本管理的软件类型
  18. export type VersionedSoftwareType = 'nodejs' | 'vscode' | 'git'
  19. // npm 镜像地址
  20. export const NPM_REGISTRY = 'https://registry.npmmirror.com'
  21. // 需要版本管理的软件列表
  22. export const VERSIONED_SOFTWARE_LIST: VersionedSoftwareType[] = ['nodejs', 'vscode', 'git']
  23. // 软件显示名称
  24. export const SOFTWARE_NAMES: Record<SoftwareType | 'all', string> = {
  25. nodejs: 'Node.js',
  26. pnpm: 'pnpm',
  27. vscode: 'VS Code',
  28. git: 'Git',
  29. claudeCode: 'Claude Code',
  30. all: '一键安装'
  31. }
  32. // 错误消息
  33. export const ERROR_MESSAGES = {
  34. NETWORK_ERROR: '网络连接失败,请检查网络设置',
  35. TIMEOUT_ERROR: '请求超时,请稍后重试',
  36. VERSION_FETCH_ERROR: '无法获取版本列表',
  37. INSTALL_ERROR: '安装失败',
  38. PERMISSION_ERROR: '权限不足,请以管理员身份运行',
  39. UNSUPPORTED_PLATFORM: '不支持的操作系统',
  40. UNKNOWN_SOFTWARE: '未知的软件',
  41. INVALID_URL: '无效的 URL 地址',
  42. PACKAGE_MANAGER_NOT_FOUND: '未检测到包管理器',
  43. INSTALL_CANCELLED: '安装已被用户取消',
  44. UNINSTALL_ERROR: '卸载失败'
  45. } as const
  46. // 状态消息
  47. export const STATUS_MESSAGES = {
  48. PREPARING: '正在准备安装...',
  49. INSTALLING: '正在安装',
  50. CONFIGURING: '正在配置',
  51. UPDATING_SOURCE: '正在更新软件源 (apt update)...',
  52. COMPLETE: '安装完成',
  53. READY: '就绪',
  54. LOADING: '加载中...',
  55. LOAD_FAILED: '加载失败',
  56. UNINSTALLING: '正在卸载',
  57. CHECKING_UPDATE: '正在检查更新'
  58. } as const
  59. // brew 包名映射
  60. export const BREW_PACKAGES = {
  61. nodejs: {
  62. default: 'node',
  63. 20: 'node@20',
  64. 18: 'node@18'
  65. },
  66. vscode: {
  67. stable: 'visual-studio-code',
  68. insiders: 'visual-studio-code-insiders'
  69. },
  70. git: {
  71. stable: 'git',
  72. lfs: 'git-lfs'
  73. }
  74. } as const
  75. // 应用名称(用于 sudo-prompt)
  76. export const APP_NAME = 'ApqInstaller'
  77. // 备用版本(当无法获取最新版本时使用)
  78. export const FALLBACK_VERSIONS = {
  79. nodejs: '22.12.0',
  80. vscode: '1.96.0',
  81. git: '2.47.1'
  82. } as const
  83. // Git for Windows 镜像配置
  84. export const GIT_MIRRORS = {
  85. // 华为云镜像(默认,国内推荐)
  86. huaweicloud: {
  87. name: '华为云镜像',
  88. // 华为云镜像下载地址格式: https://mirrors.huaweicloud.com/git-for-windows/v{version}.windows.1/Git-{version}-64-bit.exe
  89. getDownloadUrl: (version: string, arch: '64' | '32') =>
  90. `https://mirrors.huaweicloud.com/git-for-windows/v${version}.windows.1/Git-${version}-${arch}-bit.exe`,
  91. // 华为云镜像版本列表 API
  92. versionsUrl: 'https://mirrors.huaweicloud.com/git-for-windows/'
  93. },
  94. // GitHub 官方(需要代理)
  95. github: {
  96. name: 'GitHub 官方',
  97. getDownloadUrl: (version: string, arch: '64' | '32') =>
  98. `https://github.com/git-for-windows/git/releases/download/v${version}.windows.1/Git-${version}-${arch}-bit.exe`,
  99. // GitHub API 获取版本列表
  100. versionsUrl: 'https://api.github.com/repos/git-for-windows/git/releases'
  101. }
  102. } as const
  103. // 默认 Git 镜像
  104. export const DEFAULT_GIT_MIRROR: 'huaweicloud' | 'github' = 'huaweicloud'
  105. // Node.js 镜像配置
  106. export const NODEJS_MIRRORS = {
  107. // 官方源(默认)
  108. official: {
  109. name: 'Node.js 官方',
  110. // 版本列表 API
  111. versionsUrl: 'https://nodejs.org/dist/index.json',
  112. // 下载地址格式
  113. getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64') =>
  114. `https://nodejs.org/dist/v${version}/node-v${version}-win-${arch}.zip`
  115. },
  116. // npmmirror 镜像(国内推荐)
  117. npmmirror: {
  118. name: 'npmmirror 镜像',
  119. versionsUrl: 'https://registry.npmmirror.com/-/binary/node/index.json',
  120. getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64') =>
  121. `https://cdn.npmmirror.com/binaries/node/v${version}/node-v${version}-win-${arch}.zip`
  122. }
  123. } as const
  124. // 默认 Node.js 镜像
  125. export const DEFAULT_NODEJS_MIRROR: 'official' | 'npmmirror' = 'npmmirror'
  126. // VS Code 版本 API(官方,国内可访问)
  127. export const VSCODE_API = {
  128. // 版本列表 API
  129. versionsUrl: 'https://update.code.visualstudio.com/api/releases/stable',
  130. // 下载地址格式
  131. getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64', type: 'user' | 'system' = 'user') =>
  132. `https://update.code.visualstudio.com/${version}/win32-${arch}-${type}/stable`
  133. } as const