feat(electron): 引入 Electron 桌面应用支持

- 添加 Electron 主进程入口文件 main.ts
- 配置 Vite 插件以支持 Electron 构建
- 更新 package.json 添加 Electron 相关依赖和构建脚本
- 修改路由历史模式为 HashHistory 以兼容 Electron 环境
- 调整构建流程分离服务端与客户端打包任务
- 新增 Electron 应用图标和基础窗口配置
- 集成开发服务器 URL 加载逻辑与静态文件加载 fallback
- 更新构建日期并设置主进程入口点字段
- 添加 Windows 安装包构建目标及输出目录配置
- 优化依赖预构建列表以提升启动性能
- 分离 release 资源收集路径并增强跨平台兼容性
- 升级部分工具链版本以获得最新功能支持
This commit is contained in:
coolxitech
2025-12-14 12:06:56 +08:00
parent 9f5a873513
commit fef38d40ee
7 changed files with 3560 additions and 97 deletions

View File

@@ -6,116 +6,112 @@ on:
- main
jobs:
build:
name: Build for ${{ matrix.os }} (${{ matrix.goarch }})
runs-on: ${{ matrix.os }}
# 任务 1: 专门构建 Go 服务端程序
build-server:
name: Build Go Server for ${{ matrix.goos }}-${{ matrix.goarch }}
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Windows x64
- os: windows-latest
executable: ogame-windows-amd64.exe
goos: windows
- goos: windows
goarch: amd64
# Linux x64
- os: ubuntu-latest
executable: ogame-linux-amd64
goos: linux
executable: ogame-server-windows-amd64.exe
- goos: linux
goarch: amd64
# Linux ARM64 (如树莓派、高性能 ARM 服务器)
- os: ubuntu-latest
executable: ogame-linux-arm64
goos: linux
executable: ogame-server-linux-amd64
- goos: linux
goarch: arm64
# macOS Apple Silicon (M1/M2/M3 芯片)
- os: macos-latest
executable: ogame-macos-arm64
goos: darwin
goarch: arm64
# macOS Intel
- os: macos-latest
executable: ogame-macos-amd64
goos: darwin
goarch: amd64
executable: ogame-server-linux-arm64
steps:
- uses: actions/checkout@v4
# 1. 设置 Bun 环境构建 Vue 前端
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# 2. 设置 Go 环境
- uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v5
uses: actions/setup-go@v6
with:
go-version: '1.21'
go-version: '1.25'
# 3. 获取版本号
- name: Get version
id: get_version
shell: bash
- name: Compile Server
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=v$VERSION" >> $GITHUB_OUTPUT
- name: Install Dependencies
run: bun install
# 4. 执行前端打包,生成 docs 目录
- name: Build Vue Frontend
run: bun run build
# 5. Go 交叉编译
- name: Compile Single Executable
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
shell: bash # 强制指定使用 bash解决 Windows 下的语法错误
run: |
# 初始化 go.mod (如果不存在)
if [ ! -f go.mod ]; then
go mod init ogame-app
fi
# 整理依赖(确保编译环境干净)
if [ ! -f go.mod ]; then go mod init ogame-app; fi
go mod tidy
# 编译命令,保留控制台
go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-s -w" -o ${{ matrix.executable }} main.go
# 6. 上传构建产物
- name: Upload Artifact
- name: Upload Server Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.executable }}
path: ${{ matrix.executable }}
outputs:
app_version: ${{ steps.get_version.outputs.VERSION }}
# 任务 2: 专门构建 Electron 客户端
build-electron:
name: Build Electron for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: windows-latest
platform: win
- os: macos-latest
platform: mac
- os: ubuntu-latest
platform: linux
steps:
- uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Dependencies
run: bun install
- name: Build Vue Frontend
run: bun run build
- name: Build Electron App
run: bun run build:electron --${{ matrix.platform }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Electron Artifact
uses: actions/upload-artifact@v4
with:
name: electron-${{ matrix.platform }}
# 仅上传 pkg 目录下的安装包产物
path: |
pkg/*.exe
pkg/*.dmg
pkg/*.AppImage
pkg/*.zip
# 任务 3: 汇总发布
release:
needs: build
needs: [build-server, build-electron]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./release-assets
- name: Get version
id: get_version
run: |
# 假设版本号仍在 package.json 中
echo "VERSION=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
shell: bash
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.build.outputs.app_version }}
name: Release ${{ needs.build.outputs.app_version }}
files: |
ogame-windows-amd64.exe/ogame-windows-amd64.exe
ogame-linux-amd64/ogame-linux-amd64
ogame-linux-arm64/ogame-linux-arm64
ogame-macos-arm64/ogame-macos-arm64
ogame-macos-amd64/ogame-macos-amd64
tag_name: ${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }}
# 收集所有子目录下的文件
files: ./release-assets/**/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}