Skip to content

feat(desktop): support remote lite build mode without bundled JRE/JAR#417

Open
Joe0720 wants to merge 2 commits into
mateaix:devfrom
Joe0720:feat/desktop-remote-lite-build
Open

feat(desktop): support remote lite build mode without bundled JRE/JAR#417
Joe0720 wants to merge 2 commits into
mateaix:devfrom
Joe0720:feat/desktop-remote-lite-build

Conversation

@Joe0720

@Joe0720 Joe0720 commented Jun 25, 2026

Copy link
Copy Markdown

背景

当前桌面端打包会内置完整 JVM 运行时(JRE + Spring Boot JAR ~530MB),安装包体积大。企业用户大量使用 remote 远程连接模式,仅少数场景需要 local 本地内置服务,存在冗余打包开销与分发成本。

优化方案

构建脚本区分打包模式,新增 BUILD_MODE 环境变量,支持两种产出包:

Local 完整版 Remote 轻量版
DMG 体积 (arm64) 523 MB 97 MB (-81%)
内置 JRE
内置 JAR
本地内嵌后端
远程连接
连接选择页 显示两个选项 仅显示远程表单

使用方式

```bash

Local 完整版(默认,内置 JRE+JAR)

npm run package:mac:local

Remote 轻量版(仅客户端,连接远程服务器)

npm run package:mac:remote

Windows

npm run package:win:remote

全平台

npm run package:all:remote
```

  • electron-builder.jsonelectron-builder.cjs:动态配置,根据 BUILD_MODE 条件包含 extraResources(JRE/JAR)
  • electron/main/index.ts:运行时检测构建模式(JAR 是否存在),remote 模式下跳过本地后端启动,忽略已保存的 local 配置,新增 app:get-build-mode IPC handler
  • electron/preload/index.ts:暴露 getBuildMode() API
  • src/App.vue:remote 构建隐藏"本地运行"选项,直接显示远程连接表单,展示轻量版提示
  • src/env.d.ts:补充 buildMode 类型声明
  • package.json:新增 package:mac:local/package:mac:remote 等脚本,添加 cross-env 依赖
  • scripts/build.sh:构建 server JAR 并复制到 resources/
  • scripts/download-jre.sh:下载 Eclipse Temurin 21 JRE(支持 mac-arm64/mac-x64)
  • scripts/build-all-platforms.sh:全平台构建脚本,支持 --local/--remote 参数
  • scripts/trim-playwright-driver.cjs:afterPack hook 占位脚本

兼容性

  • BUILD_MODE 默认为 local,原有行为不变
  • 运行时通过检测 JAR 文件是否存在判断构建模式,无需构建时代码注入
  • 如果用户从 local 版本升级到 remote 版本,已保存的 local 配置会被忽略,自动显示远程连接选择器

qiaozhipeng added 2 commits June 25, 2026 17:02
Add a dual packaging mode system controlled by the BUILD_MODE env var:

- **local** (default): Full build bundling JRE + Spring Boot JAR, identical
  to the previous behavior.  Supports both embedded local backend and
  remote server connection.

- **remote** (lite): Omits the ~530 MB JRE/JAR resources, producing an
  installer that is ~81% smaller (97 MB vs 523 MB on macOS arm64).  The
  app only supports connecting to a remote server; the "local" option is
  hidden from the splash connection chooser.

Changes:
- Replace static electron-builder.json with dynamic electron-builder.cjs
  that conditionally includes extraResources based on BUILD_MODE
- Add build mode detection at runtime (checks JAR existence) with graceful
  fallback to remote-only mode
- Add IPC handler app:get-build-mode and expose via preload
- Hide "本地运行" option in splash when running a remote build
- Ignore stale 'local' saved config in remote builds
- Add package scripts: package:mac:local, package:mac:remote, etc.
- Add missing build scripts: build.sh, download-jre.sh, build-all-platforms.sh
- Add no-op afterPack hook (trim-playwright-driver.cjs) placeholder
- Add cross-env devDependency for cross-platform BUILD_MODE support
Add a Vite plugin (scripts/branding.cjs) that replaces hardcoded "MateClaw"
strings at build time, enabling white-label/OEM rebranding without modifying
any source code.

Configuration:
- Edit branding.config.json (name, tagline, team, copyright, appId, githubUrl)
- Or set BRAND_* env vars (BRAND_NAME, BRAND_TAGLINE, BRAND_TEAM, etc.)

Usage:
  # Default build (MateClaw brand)
  npm run package:mac

  # Custom brand via env vars
  BRAND_NAME=MyAI BRAND_TAGLINE="Smart AI Helper" npm run package:mac:remote

  # Or edit branding.config.json and build normally
  npm run package:mac:remote

Replacements applied at build time:
- Brand name (window title, About dialog, error messages, console logs)
- Tagline, team name, copyright line
- GitHub repo/issues URLs
- Logo file path
- electron-builder config (productName, appId, artifactName, dmg title, publish repo)

The branding plugin runs in Vite's transform hook, covering the renderer
(App.vue, index.html), electron main process, and preload script.

Server-coupled strings (H2 database name, Spring Boot property names) are
intentionally NOT replaced to avoid breaking backend compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant