feat: 初始化船长·HeiXiu 桌面应用项目(错误是svg的问题)
Electron + React 19 + TypeScript + Ant Design 6 + Tailwind CSS 4 【核心架构】 - Electron 主进程(窗口管理、平台检测、图标适配) - Vite 构建链(双产物 dist/ + dist-electron/) - 共享层 shared/(类型、常量、工具函数) - IPC 通信框架 + 安全守卫 【主题系统】 - 蓝紫渐变主题(亮色/暗色双模式) - Ant Design ConfigProvider 适配(lightAlgorithm / darkAlgorithm) - Tailwind CSS 4 @theme 指令 + CSS 变量 - 设计令牌三处同步(tokens.ts / globals.css / antd-theme.ts) 【导航栏】 - 自定义 H5 导航栏替代系统菜单 - 个人版/企业版双布局 - 未登录拦截 + 事件总线驱动登录弹窗 【登录注册】 - Modal 弹层(Portal)+ Tabs 切换 - 登录/注册表单动态字段渲染 - 记住密码 / 自动登录 / 用户协议 【更新系统】 - 自定义 API 版本检查(替代 electron-updater generic provider) - 手动下载 + SHA512 校验 + spawn NSIS 安装 - 渲染进程更新状态机 Hook(useUpdater) - 检查更新按钮 + 下载进度展示 【构建工具链】 - build.mjs 构建总管(--win/--mac/--linux --personal/--enterprise --build/--clean/--sign/--upload/--publish) - scripts/ 自动化脚本(clean / generate-update-info / upload-oss / publish-release) - electron-builder NSIS 安装器(可选路径、多版本打包) - update-info.json 自动生成(fileSize/sha512/changelog/releaseDate) 【代码质量】 - ESLint + TypeScript strict + Prettier - husky + lint-staged(提交前自动检查) - commitlint(规范提交信息) - Playwright E2E + Vitest 单元测试框架 - rollup-plugin-visualizer 打包体积分析 【文档】 - README.md(快速开始 + 目录结构 + 命令速查) - UpdateA.md(发布手册:API/签名/发版流程/数据库) - CHANGELOG.md(更新日志) - .env.example(构建环境变量模板)
This commit is contained in:
59
shared/constants/app.ts
Normal file
59
shared/constants/app.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
// ============================================================
|
||||
// 应用常量 —— 版本号、版本类型、窗口标题
|
||||
// 主进程 & 渲染进程共享
|
||||
// ============================================================
|
||||
|
||||
import type { Edition, Platform } from '../types';
|
||||
import { APP_VERSION } from './version';
|
||||
|
||||
/** 应用显示名称 */
|
||||
export const APP_NAME = '船长·HeiXiu';
|
||||
|
||||
// APP_VERSION 从 ./version.ts 导入(读取 package.json),不再硬编码
|
||||
|
||||
// ============================================================
|
||||
// 版本类型(企业版 / 个人版)
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* 解析版本类型字符串
|
||||
* @param raw - 环境变量值,如 "enterprise" / undefined
|
||||
* @returns 版本类型,默认 personal
|
||||
*/
|
||||
export function parseEdition(raw: string | undefined): Edition {
|
||||
if (raw === 'enterprise') return 'enterprise';
|
||||
return 'personal';
|
||||
}
|
||||
|
||||
/** 版本中文名称 */
|
||||
export function getEditionName(edition: Edition): string {
|
||||
return edition === 'enterprise' ? '企业版' : '个人版';
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 窗口标题构建
|
||||
// ============================================================
|
||||
|
||||
/** 平台中文名称(简写) */
|
||||
function platformShortName(platform: Platform): string {
|
||||
if (platform === 'darwin') return 'MAC';
|
||||
if (platform === 'win32') return 'Windows';
|
||||
return 'Linux';
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整窗口标题
|
||||
* 格式:船长·HeiXiu V{版本号} {平台}{版本}
|
||||
* 示例:"船长·HeiXiu V0.0.1 MAC企业版"
|
||||
* "船长·HeiXiu V0.0.1 Windows个人版"
|
||||
*
|
||||
* @param platform - 当前操作系统平台
|
||||
* @param edition - 版本类型
|
||||
* @param version - 可选覆盖版本号(默认 APP_VERSION)
|
||||
*/
|
||||
export function buildWindowTitle(platform: Platform, edition: Edition, version?: string): string {
|
||||
const ver = version ?? APP_VERSION;
|
||||
const os = platformShortName(platform);
|
||||
const edName = getEditionName(edition);
|
||||
return `${APP_NAME} V${ver} ${os}${edName}`;
|
||||
}
|
||||
43
shared/constants/ipc-channels.ts
Normal file
43
shared/constants/ipc-channels.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// ============================================================
|
||||
// IPC 通道名称常量 —— 避免魔法字符串
|
||||
// ============================================================
|
||||
|
||||
/** 主进程 → 渲染进程 */
|
||||
export const MAIN_TO_RENDERER = {
|
||||
/** 主进程消息推送 */
|
||||
MAIN_PROCESS_MESSAGE: 'main-process-message',
|
||||
/** 主题变更通知 */
|
||||
THEME_CHANGED: 'theme-changed',
|
||||
/** 窗口聚焦通知 */
|
||||
WINDOW_FOCUSED: 'window-focused',
|
||||
/** 窗口失焦通知 */
|
||||
WINDOW_BLURRED: 'window-blurred',
|
||||
} as const;
|
||||
|
||||
/** 渲染进程 → 主进程 */
|
||||
export const RENDERER_TO_MAIN = {
|
||||
/** 打开子窗口 */
|
||||
OPEN_SUB_WINDOW: 'open-sub-window',
|
||||
/** 关闭子窗口 */
|
||||
CLOSE_SUB_WINDOW: 'close-sub-window',
|
||||
/** 设置窗口标题 */
|
||||
SET_WINDOW_TITLE: 'set-window-title',
|
||||
/** 获取平台信息 */
|
||||
GET_PLATFORM_INFO: 'get-platform-info',
|
||||
/** 最小化窗口 */
|
||||
MINIMIZE_WINDOW: 'minimize-window',
|
||||
/** 最大化/还原窗口 */
|
||||
TOGGLE_MAXIMIZE: 'toggle-maximize',
|
||||
/** 关闭窗口 */
|
||||
CLOSE_WINDOW: 'close-window',
|
||||
} as const;
|
||||
|
||||
/** 双向通信通道 */
|
||||
export const BIDIRECTIONAL = {
|
||||
/** 读取应用配置 */
|
||||
READ_CONFIG: 'read-config',
|
||||
/** 写入应用配置 */
|
||||
WRITE_CONFIG: 'write-config',
|
||||
/** 文件对话框 */
|
||||
FILE_DIALOG: 'file-dialog',
|
||||
} as const;
|
||||
9
shared/constants/version.ts
Normal file
9
shared/constants/version.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// ============================================================
|
||||
// 版本号 — 从 package.json 动态读取,保持单一数据源
|
||||
// 主进程(Node.js)和渲染进程(Vite 打包)均可正常导入 JSON 模块
|
||||
// ============================================================
|
||||
|
||||
import pkg from '../../package.json';
|
||||
|
||||
/** 应用版本号,与 package.json 的 version 字段自动同步 */
|
||||
export const APP_VERSION: string = pkg.version;
|
||||
71
shared/types/index.ts
Normal file
71
shared/types/index.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// ============================================================
|
||||
// 共享类型定义 —— 主进程 & 渲染进程通用
|
||||
// ============================================================
|
||||
|
||||
/** 平台类型 */
|
||||
export type Platform = 'win32' | 'darwin' | 'linux';
|
||||
|
||||
/** 窗口标识 */
|
||||
export interface WindowIdentity {
|
||||
/** 窗口唯一 ID */
|
||||
id: number;
|
||||
/** 窗口类型标识 */
|
||||
type: 'main' | 'settings' | 'preview' | 'custom';
|
||||
/** 窗口标题 */
|
||||
title: string;
|
||||
}
|
||||
|
||||
/** IPC 响应包装 */
|
||||
export interface IpcResponse<T = unknown> {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** 主题模式 */
|
||||
export type ThemeMode = 'light' | 'dark' | 'system';
|
||||
|
||||
/** 版本类型 */
|
||||
export type Edition = 'enterprise' | 'personal';
|
||||
|
||||
/** 应用配置 */
|
||||
export interface AppConfig {
|
||||
themeMode: ThemeMode;
|
||||
language: string;
|
||||
autoLaunch: boolean;
|
||||
minimizeToTray: boolean;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 更新相关类型
|
||||
// ============================================================
|
||||
|
||||
/** 更新检查请求参数 */
|
||||
export interface UpdateCheckParams {
|
||||
platform: Platform;
|
||||
version: string;
|
||||
edition: Edition;
|
||||
channel?: 'stable' | 'beta' | 'alpha';
|
||||
}
|
||||
|
||||
/** 更新检查响应(API 返回的 data 字段) */
|
||||
export interface UpdateCheckResult {
|
||||
/** 是否有可用更新 */
|
||||
hasUpdate: boolean;
|
||||
/** 最新版本号 */
|
||||
latestVersion: string;
|
||||
/** 安装包下载地址 */
|
||||
downloadUrl: string;
|
||||
/** 安装包大小(字节) */
|
||||
fileSize: number;
|
||||
/** SHA512 校验值 */
|
||||
sha512: string;
|
||||
/** 更新日志(支持 Markdown) */
|
||||
changelog: string;
|
||||
/** 发布日期 */
|
||||
releaseDate: string;
|
||||
/** 是否强制更新 */
|
||||
forceUpdate: boolean;
|
||||
/** 最低兼容版本(低于此版本必须强制更新) */
|
||||
minimumVersion: string;
|
||||
}
|
||||
75
shared/utils/index.ts
Normal file
75
shared/utils/index.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
// ============================================================
|
||||
// 共享工具函数 —— 主进程 & 渲染进程通用(纯函数,不依赖平台 API)
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* 简单防抖函数
|
||||
* @param fn 目标函数
|
||||
* @param delay 延迟毫秒数
|
||||
*/
|
||||
export function debounce<T extends (...args: unknown[]) => void>(
|
||||
fn: T,
|
||||
delay: number,
|
||||
): (...args: Parameters<T>) => void {
|
||||
let timer: ReturnType<typeof setTimeout> | null = null;
|
||||
return (...args: Parameters<T>) => {
|
||||
if (timer !== null) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fn(...args);
|
||||
timer = null;
|
||||
}, delay);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 节流函数
|
||||
* @param fn 目标函数
|
||||
* @param interval 间隔毫秒数
|
||||
*/
|
||||
export function throttle<T extends (...args: unknown[]) => void>(
|
||||
fn: T,
|
||||
interval: number,
|
||||
): (...args: Parameters<T>) => void {
|
||||
let lastTime = 0;
|
||||
return (...args: Parameters<T>) => {
|
||||
const now = Date.now();
|
||||
if (now - lastTime >= interval) {
|
||||
lastTime = now;
|
||||
fn(...args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 语义化版本号比较
|
||||
* @returns 1 (v1 > v2), -1 (v1 < v2), 0 (相等)
|
||||
*/
|
||||
export function compareVersions(v1: string, v2: string): number {
|
||||
const parts1 = v1.split('.').map(Number);
|
||||
const parts2 = v2.split('.').map(Number);
|
||||
const maxLen = Math.max(parts1.length, parts2.length);
|
||||
|
||||
for (let i = 0; i < maxLen; i++) {
|
||||
const a = parts1[i] || 0;
|
||||
const b = parts2[i] || 0;
|
||||
if (a > b) return 1;
|
||||
if (a < b) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 深拷贝(JSON 安全类型)
|
||||
*/
|
||||
export function deepClone<T>(obj: T): T {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一 ID(简易版,不依赖 crypto)
|
||||
*/
|
||||
export function generateId(): string {
|
||||
return `${Date.now().toString(36)}-${Math.random().toString(36).substring(2, 9)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user