From 95116e23388e6cd3be47b7ca1910a224e38b462c Mon Sep 17 00:00:00 2001 From: gmh01 Date: Thu, 23 Jul 2026 19:26:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B7=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=89=93=E5=8C=85=E6=94=AF=E6=8C=81=EF=BC=88Linux=20.?= =?UTF-8?q?deb=EF=BC=89=E3=80=81Docker=20=E6=9E=84=E5=BB=BA=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=8F=8A=E9=A1=B9=E7=9B=AE=E5=AE=98=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - electron/builder.js: 修复 Linux 平台 npm 命令、增加 .deb 安装包支持 - electron/main.js: 按平台动态设置保存对话框默认扩展名 - package.json: 添加 Linux deb 打包目标 - 新增 Dockerfile 用于 Linux 交叉构建 - 新增 build-linux-docker.ps1 / build-linux.sh 构建脚本 - 新增 site/ 项目官网页面 - .gitignore: 全面忽略二进制文件 - 新增 GitHub Actions CI 工作流 --- .github/workflows/build.yml | 58 +++++ .gitignore | 81 +++++++ Dockerfile | 23 ++ build-linux-docker.ps1 | 19 ++ build-linux.sh | 17 ++ electron/builder.js | 5 +- electron/main.js | 7 +- package.json | 14 +- site/index.html | 417 ++++++++++++++++++++++++++++++++++++ 9 files changed, 636 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 build-linux-docker.ps1 create mode 100644 build-linux.sh create mode 100644 site/index.html diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66afd0f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build Web2App + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + - run: npm run build + - run: npx electron-builder --config --win + - uses: actions/upload-artifact@v4 + with: + name: Web2App-Windows + path: release/*.exe + + build-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm ci + - run: npm run build + - run: npx electron-builder --config --mac + - uses: actions/upload-artifact@v4 + with: + name: Web2App-macOS + path: release/*.dmg + + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: | + sudo apt-get update + sudo apt-get install -y rpm libx11-dev libxkbfile-dev libsecret-1-dev + - run: npm ci + - run: npm run build + - run: npx electron-builder --config --linux + - uses: actions/upload-artifact@v4 + with: + name: Web2App-Linux + path: | + release/*.AppImage + release/*.deb diff --git a/.gitignore b/.gitignore index f206c76..867d2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,87 @@ node_modules/ dist/ .web2app/ +release/ + +# Binaries & executables +*.exe +*.dll +*.so +*.dylib +*.bin +*.pak +*.dat + +# Disk images & installers +*.dmg +*.iso +*.img +*.AppImage +*.deb +*.rpm + +# Archives +*.zip +*.7z +*.tar +*.gz +*.rar + +# Images (binary formats) +*.ico +*.icns +*.png +*.jpg +*.jpeg +*.gif +*.bmp +*.webp + +# Documents +*.pdf +*.doc +*.docx +*.xls +*.xlsx +*.ppt +*.pptx + +# Audio & Video +*.mp3 +*.mp4 +*.avi +*.mov +*.wav +*.flac +*.mkv + +# Fonts +*.ttf +*.otf +*.woff +*.woff2 + +# Database +*.db +*.sqlite +*.sqlite3 + +# Object & build artifacts +*.o +*.obj +*.class +*.lib +*.a +*.pdb +*.idb + +# Other binary +*.snap +*.crx + +# Logs *.log + +# OS .DS_Store Thumbs.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8daba98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM node:20-bullseye + +WORKDIR /app + +RUN apt-get update && apt-get install -y \ + rpm \ + libx11-dev \ + libxkbfile-dev \ + libsecret-1-dev \ + fakeroot \ + dpkg-dev \ + && rm -rf /var/lib/apt/lists/* + +COPY package.json package-lock.json ./ +RUN npm install + +COPY . . + +RUN npm run build + +RUN npx electron-builder --config --linux + +CMD ["cp", "-r", "release/*", "/output/"] diff --git a/build-linux-docker.ps1 b/build-linux-docker.ps1 new file mode 100644 index 0000000..a8f7eb1 --- /dev/null +++ b/build-linux-docker.ps1 @@ -0,0 +1,19 @@ +Write-Host "===== Web2App Linux Docker Build =====" +Write-Host "" +Write-Host "This script builds the Linux version using Docker." +Write-Host "Prerequisites: Docker Desktop with Linux container support" +Write-Host "" + +$imageName = "web2app-linux-builder" + +Write-Host "1. Building Docker image..." +docker build -t $imageName . + +Write-Host "2. Running build..." +$outputDir = Join-Path (Get-Location) "release-linux" +New-Item -ItemType Directory -Force -Path $outputDir +docker run --rm -v "${outputDir}:/output" $imageName + +Write-Host "" +Write-Host "===== Build Complete =====" +Write-Host "Output: $outputDir" diff --git a/build-linux.sh b/build-linux.sh new file mode 100644 index 0000000..ad629bc --- /dev/null +++ b/build-linux.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +echo "===== Web2App Linux Build Script =====" + +echo "1. Installing dependencies..." +npm install + +echo "2. Building frontend..." +npm run build + +echo "3. Building Linux package (AppImage + deb)..." +npx electron-builder --config --linux + +echo "===== Build Complete =====" +echo "Output: release/" +ls -lh release/ diff --git a/electron/builder.js b/electron/builder.js index 3a63ce4..5b092e3 100644 --- a/electron/builder.js +++ b/electron/builder.js @@ -94,7 +94,8 @@ async function startPack(projectPath, outputPath, onProgress) { onProgress({ stage: 'install', message: '安装依赖 (首次较慢)...', percent: 50 }) try { - execSync('npm.cmd install --production', { + const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm' + execSync(`${npmCmd} install --production`, { cwd: tempDir, stdio: 'pipe', timeout: 300000 @@ -155,7 +156,7 @@ async function startPack(projectPath, outputPath, onProgress) { let installerPath = null if (fs.existsSync(distDir)) { const files = fs.readdirSync(distDir) - .filter(f => f.endsWith('.exe') || f.endsWith('.dmg') || f.endsWith('.AppImage')) + .filter(f => f.endsWith('.exe') || f.endsWith('.dmg') || f.endsWith('.AppImage') || f.endsWith('.deb')) .sort((a, b) => fs.statSync(path.join(distDir, b)).mtimeMs - fs.statSync(path.join(distDir, a)).mtimeMs) if (files.length > 0) { installerPath = path.join(distDir, files[0]) diff --git a/electron/main.js b/electron/main.js index 5a57f42..d37065d 100644 --- a/electron/main.js +++ b/electron/main.js @@ -70,9 +70,14 @@ ipcMain.handle('dialog:selectIcon', async () => { }) ipcMain.handle('dialog:saveFile', async (_event, options) => { + const defaultFilters = process.platform === 'win32' + ? [{ name: '安装包', extensions: ['exe'] }] + : process.platform === 'darwin' + ? [{ name: '安装包', extensions: ['dmg'] }] + : [{ name: '安装包', extensions: ['AppImage', 'deb'] }] const result = await dialog.showSaveDialog(mainWindow, { defaultPath: options?.defaultPath, - filters: options?.filters || [{ name: '安装包', extensions: ['exe', 'dmg', 'AppImage'] }] + filters: options?.filters || defaultFilters }) if (!result.canceled && result.filePath) { return result.filePath diff --git a/package.json b/package.json index 71b7575..0b0719a 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,18 @@ "icon": null }, "linux": { - "target": ["AppImage"], - "icon": null + "target": [ + { + "target": "AppImage", + "arch": ["x64"] + }, + { + "target": "deb", + "arch": ["x64"] + } + ], + "icon": null, + "category": "Utility" } }, "dependencies": { diff --git a/site/index.html b/site/index.html new file mode 100644 index 0000000..db10f07 --- /dev/null +++ b/site/index.html @@ -0,0 +1,417 @@ + + + + + + Web2App - 将网站转化为独立的桌面应用 + + + + + + + +
+
+
+ v1.0.0 +
+

将任意网站
转化为独立的桌面应用

+

导入网站资源,配置应用信息,一键打包为跨平台安装包 —— 无需编写代码,无需配置运行环境。

+ +
+
+ + +
+
+ +

强大而简洁

+

从资源导入到打包发布,Web2App 提供一站式的网站转桌面应用解决方案。

+
+
+
📦
+

一键打包

+

将完整的网站资源(HTML、JS、CSS、图片等)打包为独立的安装包,内置 Electron 运行时,目标机无需任何预装环境。

+
+
+
🖥️
+

跨平台支持

+

一次打包,多平台分发。支持 Windows(.exe)、macOS(.dmg)、Linux(.AppImage)三大桌面平台。

+
+
+
⚙️
+

灵活配置

+

自定义应用名称、图标、版本号、窗口尺寸、作者版权信息,支持指定入口文件和后端服务入口。

+
+
+
🌐
+

内嵌后端服务

+

应用内嵌 HTTP 服务器与 SQLite 数据库,支持运行 Node.js 后端脚本,自动检测端口占用,无需外部 Web 服务器。

+
+
+
📂
+

资源管理

+

以目录树形式管理所有导入资源,支持批量导入、文件增删改、保留目录结构,资源状态一目了然。

+
+
+
🔒
+

离线可用 · 安全可靠

+

打包过程完全离线,不上传任何数据至外网。生成 SHA256 校验值确保安装包完整性,安装过程引导清晰。

+
+
+
+
+ + +
+
+ +

四步完成打包

+

从网站资源到可分发安装包,只需简单四步。

+
+
+
1
+

导入网站资源

+

导入 HTML、JS、CSS、图片等文件,自动检测入口文件,保留目录结构。

+ +
+
+
2
+

配置应用信息

+

设置名称、图标、版本、窗口尺寸、后端入口等,一切可视化操作。

+ +
+
+
3
+

一键打包

+

点击打包,实时查看进度与日志,自动嵌入 Electron 运行时生成安装包。

+ +
+
+
4
+

分发与运行

+

将安装包分发给用户,安装后即可独立运行,无需任何环境配置。

+
+
+
+
+ + +
+
+ +

选择你的平台

+

Web2App 支持主流桌面平台,下载对应版本即可开始使用。

+
+
+
🪟
+

Windows

+

v1.0.0 · x64

+ + + 下载便携版 + +
可执行安装包请通过 npm run electron:build 构建
+
+
+
🍎
+

macOS

+

v1.0.0 · Intel / Apple Silicon

+ 即将发布 +
+
+
🐧
+

Linux

+

v1.0.0 · .AppImage

+ 即将发布 +
+
+
+
+ + +
+
+ +

基于 Electron 构建

+

Web2App 生成的桌面应用采用分层架构设计,确保性能与可扩展性。

+
+
+
前端界面(用户网站 HTML / JS / CSS)
+
+ Chromium 渲染引擎 + Vue 3 / React +
+
+
⬇ HTTP 本地通信 ⬇
+
+
后端服务
+
+ Node.js 运行时 + Express 路由 + SQLite 数据库 +
+
+
+
+
Electron 主进程
+
+ 窗口管理 + 系统托盘 + 自动启动后端 +
+
+
+
+ 操作系统 (Windows / macOS / Linux) +
+
+
+
+ + + + +