| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // electron/modules/constants.ts - 常量定义
- import type { SoftwareType } from './types'
- // 支持的最低 Node.js 主版本
- export const MIN_SUPPORTED_NODE_VERSION = 18
- // 保留的主版本数量
- export const MAX_MAJOR_VERSIONS = 4
- // 网络请求超时时间(毫秒)
- export const REQUEST_TIMEOUT = 15000
- // 重试次数
- export const MAX_RETRIES = 3
- // 重试延迟(毫秒)
- export const RETRY_DELAY = 1000
- // 版本缓存时间(毫秒)- 30分钟(优化后)
- export const VERSION_CACHE_TTL = 30 * 60 * 1000
- // 包管理器源更新缓存时间(毫秒)- 1天
- export const SOURCE_UPDATE_CACHE_TTL = 24 * 60 * 60 * 1000
- // 需要版本管理的软件类型
- export type VersionedSoftwareType = 'nodejs' | 'vscode' | 'git'
- // npm 镜像地址
- export const NPM_REGISTRY = 'https://registry.npmmirror.com'
- // 需要版本管理的软件列表
- export const VERSIONED_SOFTWARE_LIST: VersionedSoftwareType[] = ['nodejs', 'vscode', 'git']
- // 软件显示名称
- export const SOFTWARE_NAMES: Record<SoftwareType | 'all', string> = {
- nodejs: 'Node.js',
- pnpm: 'pnpm',
- vscode: 'VS Code',
- git: 'Git',
- claudeCode: 'Claude Code',
- all: '一键安装'
- }
- // 错误消息
- export const ERROR_MESSAGES = {
- NETWORK_ERROR: '网络连接失败,请检查网络设置',
- TIMEOUT_ERROR: '请求超时,请稍后重试',
- VERSION_FETCH_ERROR: '无法获取版本列表',
- INSTALL_ERROR: '安装失败',
- PERMISSION_ERROR: '权限不足,请以管理员身份运行',
- UNSUPPORTED_PLATFORM: '不支持的操作系统',
- UNKNOWN_SOFTWARE: '未知的软件',
- INVALID_URL: '无效的 URL 地址',
- PACKAGE_MANAGER_NOT_FOUND: '未检测到包管理器',
- INSTALL_CANCELLED: '安装已被用户取消',
- UNINSTALL_ERROR: '卸载失败'
- } as const
- // 状态消息
- export const STATUS_MESSAGES = {
- PREPARING: '正在准备安装...',
- INSTALLING: '正在安装',
- CONFIGURING: '正在配置',
- UPDATING_SOURCE: '正在更新软件源 (apt update)...',
- COMPLETE: '安装完成',
- READY: '就绪',
- LOADING: '加载中...',
- LOAD_FAILED: '加载失败',
- UNINSTALLING: '正在卸载',
- CHECKING_UPDATE: '正在检查更新'
- } as const
- // brew 包名映射
- export const BREW_PACKAGES = {
- nodejs: {
- default: 'node',
- 20: 'node@20',
- 18: 'node@18'
- },
- vscode: {
- stable: 'visual-studio-code',
- insiders: 'visual-studio-code-insiders'
- },
- git: {
- stable: 'git',
- lfs: 'git-lfs'
- }
- } as const
- // 应用名称(用于 sudo-prompt)
- export const APP_NAME = 'ApqInstaller'
- // 备用版本(当无法获取最新版本时使用)
- export const FALLBACK_VERSIONS = {
- nodejs: '22.12.0',
- vscode: '1.96.0',
- git: '2.47.1'
- } as const
- // Git for Windows 镜像配置
- export const GIT_MIRRORS = {
- // 华为云镜像(默认,国内推荐)
- huaweicloud: {
- name: '华为云镜像',
- // 华为云镜像下载地址格式: https://mirrors.huaweicloud.com/git-for-windows/v{version}.windows.1/Git-{version}-64-bit.exe
- getDownloadUrl: (version: string, arch: '64' | '32') =>
- `https://mirrors.huaweicloud.com/git-for-windows/v${version}.windows.1/Git-${version}-${arch}-bit.exe`,
- // 华为云镜像版本列表 API
- versionsUrl: 'https://mirrors.huaweicloud.com/git-for-windows/'
- },
- // GitHub 官方(需要代理)
- github: {
- name: 'GitHub 官方',
- getDownloadUrl: (version: string, arch: '64' | '32') =>
- `https://github.com/git-for-windows/git/releases/download/v${version}.windows.1/Git-${version}-${arch}-bit.exe`,
- // GitHub API 获取版本列表
- versionsUrl: 'https://api.github.com/repos/git-for-windows/git/releases'
- }
- } as const
- // 默认 Git 镜像
- export const DEFAULT_GIT_MIRROR: 'huaweicloud' | 'github' = 'huaweicloud'
- // Node.js 镜像配置
- export const NODEJS_MIRRORS = {
- // 官方源(默认)
- official: {
- name: 'Node.js 官方',
- // 版本列表 API
- versionsUrl: 'https://nodejs.org/dist/index.json',
- // 下载地址格式
- getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64') =>
- `https://nodejs.org/dist/v${version}/node-v${version}-win-${arch}.zip`
- },
- // npmmirror 镜像(国内推荐)
- npmmirror: {
- name: 'npmmirror 镜像',
- versionsUrl: 'https://registry.npmmirror.com/-/binary/node/index.json',
- getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64') =>
- `https://cdn.npmmirror.com/binaries/node/v${version}/node-v${version}-win-${arch}.zip`
- }
- } as const
- // 默认 Node.js 镜像
- export const DEFAULT_NODEJS_MIRROR: 'official' | 'npmmirror' = 'npmmirror'
- // VS Code 版本 API(官方,国内可访问)
- export const VSCODE_API = {
- // 版本列表 API
- versionsUrl: 'https://update.code.visualstudio.com/api/releases/stable',
- // 下载地址格式
- getDownloadUrl: (version: string, arch: 'x64' | 'x86' | 'arm64', type: 'user' | 'system' = 'user') =>
- `https://update.code.visualstudio.com/${version}/win32-${arch}-${type}/stable`
- } as const
|