Skip to content

Repository files navigation

Universal App Launcher

一个真正通用的桌面应用启动器,支持任意后端类型(Java、Node.js、Python、Go...),所有配置通过配置文件自定义,无需修改代码。

Build Status License: MIT

特性

  • 真正通用:支持 Java、Node.js、Python、Go 等任意后端
  • 配置驱动:端口、命令、参数全部通过配置文件设置
  • 多种健康检查:HTTP、TCP、文件检查或不检查
  • 环境变量支持:可设置后端进程的环境变量
  • 纯本地运行:前后端代码和 exe 放一起,更新就是替换文件
  • 跨平台:支持 Windows、macOS (Intel/ARM)、Linux
  • 开箱即用:下载 release 直接运行,无需配置

目录结构

MyApp/                          # 应用根目录(可以任意命名)
├── universal-app-launcher.exe   # Windows 启动器
├── universal-app-launcher.app   # macOS 启动器
├── universal-app-launcher       # Linux 启动器
├── launcher.yml                # 启动器配置文件
├── frontend/                   # 前端代码(你的 HTML/CSS/JS)
│   ├── index.html
│   └── assets/
└── backend/                    # 后端代码
    ├── app.jar                 # 或 server.js、app.py 等
    └── application.yml         # 后端配置(可选)

重要:前后端代码和启动器放在同一目录下,启动器会自动从这个目录加载配置和资源。

源码目录结构

universal-launcher/
├── src/                        # 前端源码 (Vue)
├── src-tauri/                  # Tauri/Rust 后端源码
│   ├── src/
│   │   └── main.rs            # Rust 主程序
│   ├── Cargo.toml             # Rust 依赖
│   ├── tauri.conf.json        # Tauri 配置
│   ├── build.rs               # 构建脚本
│   └── icons/                 # 应用图标
├── scripts/                    # 构建脚本
├── examples/                   # 配置示例
├── package.json
└── vite.config.js

快速开始

1. 下载预构建的启动器

GitHub Releases 下载对应平台的启动器:

平台 文件
Windows universal-app-launcher_x.x.x_x64-setup.exe
macOS ARM (Apple Silicon) universal-app-launcher_x.x.x_aarch64.dmg
Linux universal-app-launcher_x.x.x_amd64.AppImage

2. 创建应用目录并放置文件

创建一个目录,放入你的前后端代码:

Windows:

mkdir MyApp
copy universal-app-launcher.exe MyApp\
mkdir MyApp\frontend
copy your-frontend\index.html MyApp\frontend\
mkdir MyApp\backend
copy your-app.jar MyApp\backend\

macOS / Linux:

mkdir MyApp
cp universal-app-launcher.app MyApp/
mkdir MyApp/frontend
cp your-frontend/index.html MyApp/frontend/
mkdir MyApp/backend
cp your-app.jar MyApp/backend/

3. 创建配置文件

MyApp 目录下创建 launcher.yml

app_name: "MyApp"

backend:
  enabled: true
  command: "java"
  args:
    - "-jar"
    - "app.jar"
  work_dir: "backend"
  startup_timeout: 60
  
  health_check:
    enabled: false    # 如果没有健康检查接口,设为 false
    check_type: "http"
    url: "http://127.0.0.1:8080/actuator/health"

frontend:
  enabled: true
  directory: "frontend"
  index_file: "index.html"

window:
  title: "MyApp"
  width: 1200
  height: 800

4. 运行

Windows:

双击 MyApp\universal-app-launcher.exe

macOS:

# 方式一:终端直接运行(推荐,这样能看到日志)
open /Applications/MyApp/universal-app-launcher.app

# 方式二:如果你想把 app 放到 Applications 目录
# 需要创建软链接指向你的工作目录:
ln -s ~/MyApp/universal-app-launcher.app /Applications/MyApp.app
open /Applications/MyApp.app
# 然后把 launcher.yml、frontend、backend 放到 ~/MyApp/

Linux:

cd MyApp
./universal-app-launcher

macOS 重要说明

macOS 上 .app 文件本质是一个目录。如果你下载的是 .dmg,安装后会放在 /Applications/universal-app-launcher.app

推荐做法:创建工作目录,通过软链接使用:

# 创建工作目录
mkdir ~/MyApp

# 复制启动器
cp -r /Applications/universal-app-launcher.app ~/MyApp/

# 放入你的文件
cp your-frontend/index.html ~/MyApp/frontend/
cp your-app.jar ~/MyApp/backend/
cp launcher.yml ~/MyApp/

# 运行
open ~/MyApp/universal-app-launcher.app

从源码构建

环境要求

安装依赖

# 克隆项目
git clone https://github.com/javpower/universal-launcher.git
cd universal-launcher

# 安装前端依赖
npm install

# 安装 Tauri CLI(可选)
npm install -g @tauri-apps/cli

本地构建

# 构建当前平台的版本
npm run tauri:build

或使用脚本:

# 给脚本添加执行权限
chmod +x scripts/build-all.sh

# 构建当前平台的版本
./scripts/build-all.sh

# 构建特定平台(如果当前系统支持)
./scripts/build-all.sh windows
./scripts/build-all.sh macos
./scripts/build-all.sh macos-arm
./scripts/build-all.sh linux

平台特定依赖

Windows

无需额外依赖。

macOS

无需额外依赖,但需要 Xcode Command Line Tools:

xcode-select --install

Linux (Ubuntu/Debian)

sudo apt-get update
sudo apt-get install -y \
  libgtk-3-dev \
  libwebkit2gtk-4.0-dev \
  libappindicator3-dev \
  librsvg2-dev \
  patchelf

Linux (Fedora)

sudo dnf install \
  gtk3-devel \
  webkit2gtk4.0-devel \
  libappindicator-gtk3-devel \
  librsvg2-devel \
  patchelf

Linux (Arch)

sudo pacman -S \
  gtk3 \
  webkit2gtk \
  libappindicator-gtk3 \
  librsvg \
  patchelf

使用 GitHub Actions 自动构建

推送标签时自动构建所有平台:

# 创建新版本标签
git tag v1.0.0
git push origin v1.0.0

# GitHub Actions 会自动构建:
# - Windows (.msi, .exe)
# - macOS Intel (.dmg, .app)
# - macOS ARM (.dmg, .app)
# - Linux (.AppImage, .deb)

构建完成后,从 GitHub Releases 下载各平台安装包。

配置示例

Spring Boot 应用

backend:
  command: "java"
  args:
    - "-jar"
    - "app.jar"
  health_check:
    check_type: "http"
    url: "http://127.0.0.1:8080/actuator/health"

Node.js 应用

backend:
  command: "node"
  args:
    - "server.js"
  env:
    NODE_ENV: "production"
    PORT: "3000"
  health_check:
    check_type: "http"
    url: "http://127.0.0.1:3000/health"

Python Flask 应用

backend:
  command: "python"
  args:
    - "app.py"
  env:
    FLASK_PORT: "5000"
  health_check:
    check_type: "http"
    url: "http://127.0.0.1:5000/health"

Go 应用

backend:
  command: "./myapp"
  args: []
  health_check:
    check_type: "http"
    url: "http://127.0.0.1:8080/health"

纯前端应用(无后端)

backend:
  enabled: false

TCP 端口检查(无 HTTP 接口)

backend:
  command: "java"
  args:
    - "-jar"
    - "server.jar"
  health_check:
    check_type: "tcp"
    address: "127.0.0.1:8080"

不检查健康状态

backend:
  health_check:
    enabled: false

配置文件说明

完整配置项

# 应用名称
app_name: "MyApp"

# 后端配置
backend:
  enabled: true                    # 是否启用后端
  command: "java"                  # 启动命令
  args:                            # 启动参数
    - "-jar"
    - "app.jar"
  work_dir: "backend"              # 工作目录
  env:                             # 环境变量
    JAVA_OPTS: "-Xmx2g"
  startup_timeout: 60              # 启动超时(秒)
  
  health_check:
    enabled: true                  # 是否启用健康检查
    check_type: "http"             # 检查类型: http/tcp/file/none
    url: "http://127.0.0.1:8080/actuator/health"  # HTTP 检查 URL
    address: "127.0.0.1:8080"      # TCP 检查地址
    file_path: "backend/.ready"    # 文件检查路径
    interval_ms: 500               # 检查间隔(毫秒)
    timeout_secs: 60               # 超时时间(秒)

# 前端配置
frontend:
  enabled: true                    # 是否启用前端
  directory: "frontend"            # 前端目录
  index_file: "index.html"         # 入口文件

# 窗口配置
window:
  title: "MyApp"                   # 窗口标题
  width: 1200                      # 窗口宽度
  height: 800                      # 窗口高度
  min_width: 800                   # 最小宽度
  min_height: 600                  # 最小高度
  resizable: true                  # 是否可调整大小
  fullscreen: false                # 是否全屏
  center: true                     # 是否居中

配置文件位置

启动器会按以下顺序查找配置:

  1. launcher.yml(YAML 格式,推荐)
  2. launcher.json(JSON 格式)
  3. 使用默认配置

配置文件放在启动器(exe/app)同级目录,和 frontend、backend 目录平级。

MyApp/
├── universal-app-launcher.exe   # 或 .app
├── launcher.yml                 # ← 放这里
├── frontend/
└── backend/

更新方式

# 更新前端
cp -r new-frontend/* MyApp/frontend/

# 更新后端
cp new-backend.jar MyApp/backend/app.jar

# 更新配置
vim MyApp/launcher.yml

# 更新启动器(替换可执行文件)
# Windows:
cp new-launcher.exe MyApp/MyApp.exe

# macOS:
cp -r new-launcher.app MyApp/MyApp.app

# Linux:
cp new-launcher MyApp/my-app

输出文件说明

构建完成后,各平台的输出文件:

Windows

  • .msi - Windows 安装包(推荐)
  • .exe - 可执行文件

macOS

  • .dmg - 磁盘镜像安装包
  • .app - 应用程序包

Linux

  • .AppImage - 通用 Linux 可执行文件(推荐)
  • .deb - Debian/Ubuntu 安装包
  • .rpm - Fedora/RHEL 安装包

技术栈

  • 启动器框架: Tauri (Rust)
  • 前端: Vue 3
  • 构建工具: Vite

开发

# 克隆项目
git clone https://github.com/javpower/universal-launcher.git
cd universal-launcher

# 安装依赖
npm install

# 本地开发
npm run tauri:dev

# 构建发布版本
npm run tauri:build

常见问题

1. 界面一直显示"正在启动..."或空白

  • 检查终端输出的日志,看哪一步卡住了
  • 确认 launcher.yml 放在正确位置(和启动器同级)
  • 如果后端启动失败,检查 commandargs 是否正确
  • 如果健康检查超时,确保 health_check.enabled: false 或配置正确的 URL

2. macOS 上找不到配置文件

macOS 从 .dmg 安装后,启动器在 /Applications/ 目录,但配置文件需要放在运行目录

解决方案:

# 创建工作目录
mkdir ~/MyApp
cp -r /Applications/universal-app-launcher.app ~/MyApp/

# 在工作目录放置文件
cp launcher.yml ~/MyApp/
cp -r frontend backend ~/MyApp/

# 运行
open ~/MyApp/universal-app-launcher.app

3. 后端启动失败

  • 检查命令是否正确(如 javanodepython
  • 检查 work_dir 是否正确
  • 检查 args 参数是否正确
  • 从终端运行可以看到详细的错误信息

4. 前端显示空白

  • 确认 frontend/index.html 存在
  • 检查 frontend.directory 配置是否正确(默认是 frontend
  • 如果你的前端是 SPA(HBuilder/Vite 构建),确保 index.html 在正确位置

5. 查看日志调试

启动器会输出详细日志到终端:

macOS/Linux:

/Applications/MyApp.app/Contents/MacOS/universal-app-launcher

Windows: 直接双击运行,日志会输出到控制台窗口。

许可证

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages