Added desktop app builder
This commit is contained in:
parent
8edcfb1746
commit
04990583a6
11 changed files with 4927 additions and 27 deletions
66
.github/workflows/desktop-build.yml
vendored
Normal file
66
.github/workflows/desktop-build.yml
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
name: Desktop build
|
||||
|
||||
# Builds downloadable installers for Windows, macOS and Linux.
|
||||
# - Push a tag like v1.3.3 to produce artifacts (and, if configured, a Release).
|
||||
# - Or run manually from the Actions tab (workflow_dispatch).
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: windows-latest
|
||||
script: dist:win
|
||||
- os: macos-latest
|
||||
script: dist:mac
|
||||
- os: ubuntu-latest
|
||||
script: dist:linux
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
# electron-builder rebuilds native modules (sqlite3) for Electron's ABI.
|
||||
# The hosted runners already include the required build toolchains.
|
||||
- name: Build installers
|
||||
run: npm run ${{ matrix.script }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# macOS signing/notarization (optional): add these repo secrets to
|
||||
# produce a signed, notarized .dmg. Without them the build still
|
||||
# succeeds but the app is unsigned.
|
||||
# CSC_LINK: ${{ secrets.MAC_CSC_LINK }}
|
||||
# CSC_KEY_PASSWORD: ${{ secrets.MAC_CSC_KEY_PASSWORD }}
|
||||
# APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||
# APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
||||
# APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||
|
||||
- name: Upload installers
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: 3dgenstudio-${{ matrix.os }}
|
||||
path: |
|
||||
release/*.exe
|
||||
release/*.dmg
|
||||
release/*.zip
|
||||
release/*.AppImage
|
||||
release/*.deb
|
||||
if-no-files-found: warn
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,6 +4,9 @@ node_modules/
|
|||
# Build outputs
|
||||
dist/
|
||||
|
||||
# Electron packaged installers
|
||||
release/
|
||||
|
||||
# Local database and assets (Portable Data)
|
||||
data/
|
||||
|
||||
|
|
|
|||
16
build/README.md
Normal file
16
build/README.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Desktop build resources
|
||||
|
||||
electron-builder looks in this directory (`buildResources`) for platform icons.
|
||||
|
||||
Currently:
|
||||
- **Windows** uses `public/3dgenstudio.ico` (configured in `electron-builder.yml`).
|
||||
- **macOS** and **Linux** fall back to the default Electron icon.
|
||||
|
||||
To brand the macOS and Linux builds, add:
|
||||
|
||||
- `build/icon.icns` — macOS icon (1024×1024 source recommended).
|
||||
- `build/icon.png` — Linux icon, **512×512** (electron-builder requires ≥256×256).
|
||||
|
||||
Then set `mac.icon: build/icon.icns` and `linux.icon: build/icon.png` in
|
||||
`electron-builder.yml`. You can generate both from a single PNG with tools like
|
||||
`electron-icon-builder` or `png2icns`.
|
||||
89
docs/DESKTOP_BUILD.md
Normal file
89
docs/DESKTOP_BUILD.md
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
# Desktop builds (Windows / macOS / Linux)
|
||||
|
||||
3D Gen Studio can be packaged as a downloadable desktop app using **Electron**
|
||||
and **electron-builder**. The desktop app wraps the existing stack: the
|
||||
Electron main process starts the Node/Express backend and the Python mesh-tools
|
||||
service as child processes, then opens a window pointed at the local backend
|
||||
(which serves the built UI + API on one port).
|
||||
|
||||
## What the app includes and what it does not
|
||||
|
||||
| Bundled in the installer | Provided by the user's machine |
|
||||
| --- | --- |
|
||||
| The UI (Vite build), Node/Express backend, and Electron's own Node runtime | **Python 3.10+** (used to create the mesh-tools venv on first launch) |
|
||||
| The Python mesh-tools source + requirements | **ComfyUI** and its models (external, GPU-heavy — configured by URL) |
|
||||
| Example ComfyUI workflows, wiki, tools | Cloud API keys (Tencent / Tripo / Hitem3D), entered in the app |
|
||||
|
||||
> The **Python service** uses the "require Python" model: on first launch the
|
||||
> app finds a system Python, creates a virtualenv under the user's data folder,
|
||||
> and installs `python-server/requirements.txt` (CPU-only). This first run takes
|
||||
> a few minutes; Auto UV / Auto Retopo are unavailable until it finishes. If no
|
||||
> Python 3 is found, the rest of the app still works — only mesh-tools are off.
|
||||
>
|
||||
> **ComfyUI is not bundled** (models are many GB and GPU-specific). The desktop
|
||||
> app points at the user's existing ComfyUI server, same as the web version.
|
||||
|
||||
## Data location
|
||||
|
||||
The backend keys its `data/` directory off the working directory. In the
|
||||
desktop app that is set to the per-user data folder:
|
||||
|
||||
- Windows: `%APPDATA%\3DGenStudio`
|
||||
- macOS: `~/Library/Application Support/3DGenStudio`
|
||||
- Linux: `~/.config/3DGenStudio`
|
||||
|
||||
(Set by `app.setName('3DGenStudio')` in `electron/main.cjs`.)
|
||||
|
||||
Logs (`desktop.log`, `backend.log`, `python.log`) live in the `logs/`
|
||||
subfolder there. Override the data root with `GENSTUDIO_DATA_ROOT`.
|
||||
|
||||
## Building locally
|
||||
|
||||
Prerequisites: Node 20+, and platform native-build tools for the `sqlite3`
|
||||
rebuild (VS Build Tools on Windows, Xcode Command Line Tools on macOS,
|
||||
`build-essential` + `python3` on Linux).
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dist # build for the current OS → release/
|
||||
# or target one platform explicitly:
|
||||
npm run dist:win
|
||||
npm run dist:mac # must run on macOS
|
||||
npm run dist:linux
|
||||
npm run dist:dir # unpacked build for quick testing (no installer)
|
||||
```
|
||||
|
||||
`npm run electron:dev` builds the UI and launches the app without packaging —
|
||||
useful for iterating on the shell.
|
||||
|
||||
Outputs land in `release/`:
|
||||
- Windows: NSIS installer `.exe` + portable `.exe`
|
||||
- macOS: `.dmg` + `.zip` (x64 + arm64)
|
||||
- Linux: `.AppImage` + `.deb`
|
||||
|
||||
### Cross-platform note
|
||||
|
||||
Windows and Linux installers can be built from their respective OSes (or CI).
|
||||
**macOS `.dmg` must be built on macOS** (local Mac or a macOS CI runner).
|
||||
|
||||
## Building all platforms in CI
|
||||
|
||||
`.github/workflows/desktop-build.yml` runs a matrix across
|
||||
`windows-latest`, `macos-latest`, and `ubuntu-latest`. Trigger it by pushing a
|
||||
`v*` tag or running it manually from the Actions tab; installers are uploaded as
|
||||
build artifacts.
|
||||
|
||||
## Code signing (recommended for a clean install)
|
||||
|
||||
Unsigned builds work but show "unknown developer" warnings.
|
||||
|
||||
- **macOS**: enroll in the Apple Developer Program ($99/yr), then set
|
||||
`CSC_LINK`, `CSC_KEY_PASSWORD`, `APPLE_ID`, `APPLE_APP_SPECIFIC_PASSWORD`, and
|
||||
`APPLE_TEAM_ID` (uncomment them in the workflow) to sign + notarize.
|
||||
- **Windows**: an Authenticode certificate avoids SmartScreen warnings.
|
||||
|
||||
## Auto-update (optional, later)
|
||||
|
||||
electron-builder integrates with `electron-updater`. Uncomment the `publish:`
|
||||
block in `electron-builder.yml` (GitHub provider) to publish releases and wire
|
||||
in auto-updates — this pairs with the existing `version.json` flow.
|
||||
88
electron-builder.yml
Normal file
88
electron-builder.yml
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
# electron-builder configuration for 3D Gen Studio desktop builds.
|
||||
# Produces installers for Windows, macOS and Linux.
|
||||
#
|
||||
# Prereq: run `npm run build` (vite build → dist/) BEFORE packaging — the
|
||||
# backend serves dist/ and the packaged app loads it. `npm run dist` does both.
|
||||
#
|
||||
# Native modules (sqlite3): electron-builder rebuilds them against Electron's
|
||||
# ABI automatically (npmRebuild). CI runners have the required build tools; on a
|
||||
# local machine you need platform build tools (VS Build Tools on Windows,
|
||||
# Xcode CLT on macOS, build-essential/python3 on Linux).
|
||||
|
||||
appId: com.3dgenstudio.app
|
||||
productName: 3D Gen Studio
|
||||
copyright: Copyright © 2026 3D Gen Studio
|
||||
|
||||
directories:
|
||||
output: release
|
||||
buildResources: build
|
||||
|
||||
# asar:false keeps files on disk unpacked so the Express backend can require
|
||||
# its modules and serve dist/ with plain fs paths (no asar path shims).
|
||||
asar: false
|
||||
|
||||
# Explicit include list — the repo has large dirs (.kilo, data/, docs/,
|
||||
# designs/, python-server/.venv) we must NOT ship. node_modules production
|
||||
# deps are always included by electron-builder automatically.
|
||||
files:
|
||||
- server.js
|
||||
- storage.js
|
||||
- wikiStorage.js
|
||||
- version.json
|
||||
- package.json
|
||||
- dist/**/*
|
||||
- electron/**/*
|
||||
- comfyui_workflows/**/*
|
||||
- setup/**/*
|
||||
- tools/**/*
|
||||
- wiki/**/*
|
||||
- python-server/**/*
|
||||
- "!python-server/.venv/**"
|
||||
- "!python-server/**/__pycache__/**"
|
||||
- "!python-server/*.log"
|
||||
- "!**/*.map"
|
||||
|
||||
win:
|
||||
icon: public/3dgenstudio.ico
|
||||
target:
|
||||
- target: nsis
|
||||
arch: [x64]
|
||||
- target: portable
|
||||
arch: [x64]
|
||||
|
||||
nsis:
|
||||
oneClick: false
|
||||
perMachine: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
createDesktopShortcut: true
|
||||
createStartMenuShortcut: true
|
||||
|
||||
mac:
|
||||
# TODO: add build/icon.icns for a branded icon (falls back to default now).
|
||||
category: public.app-category.graphics-design
|
||||
target:
|
||||
- target: dmg
|
||||
arch: [x64, arm64]
|
||||
- target: zip
|
||||
arch: [x64, arm64]
|
||||
# Signing/notarization: set CSC_LINK + CSC_KEY_PASSWORD (Developer ID cert)
|
||||
# and APPLE_ID / APPLE_APP_SPECIFIC_PASSWORD / APPLE_TEAM_ID env vars in CI.
|
||||
# Without them the .dmg is unsigned and macOS shows a Gatekeeper warning.
|
||||
hardenedRuntime: true
|
||||
gatekeeperAssess: false
|
||||
|
||||
linux:
|
||||
# TODO: add build/icon.png (512x512) for a branded icon.
|
||||
category: Graphics
|
||||
target:
|
||||
- target: AppImage
|
||||
arch: [x64]
|
||||
- target: deb
|
||||
arch: [x64]
|
||||
|
||||
# Optional auto-update feed. Point at your GitHub releases to enable
|
||||
# electron-updater later (pairs with your existing version.json flow).
|
||||
# publish:
|
||||
# provider: github
|
||||
# owner: visualbruno
|
||||
# repo: 3DGenStudio
|
||||
234
electron/main.cjs
Normal file
234
electron/main.cjs
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
// Electron main process for 3D Gen Studio.
|
||||
//
|
||||
// Responsibilities:
|
||||
// 1. Resolve the app root + a writable data directory.
|
||||
// 2. Spawn the Node/Express backend (server.js) using Electron's own Node
|
||||
// runtime (ELECTRON_RUN_AS_NODE) so users don't need Node installed.
|
||||
// 3. Spawn the Python mesh-tools service (optional; Auto UV / Auto Retopo).
|
||||
// On first launch it creates a venv and installs requirements — this is
|
||||
// the "require Python on the machine" model (fastest to ship).
|
||||
// 4. Wait for the backend to answer, then open the window pointing at it.
|
||||
// 5. Kill both child processes on quit.
|
||||
//
|
||||
// The window loads http://localhost:<PORT>, where the backend serves the Vite
|
||||
// production build (dist/) and the API from the same origin — see server.js.
|
||||
|
||||
const { app, BrowserWindow, shell, dialog } = require('electron');
|
||||
const path = require('node:path');
|
||||
const http = require('node:http');
|
||||
const fs = require('node:fs');
|
||||
const { spawn } = require('node:child_process');
|
||||
const { startPythonService } = require('./python.cjs');
|
||||
|
||||
// Force a stable, brandable name BEFORE any getPath('userData') call so the
|
||||
// per-user data folder is ".../3DGenStudio" instead of ".../app" (which came
|
||||
// from package.json "name"). Applies to both dev and packaged builds.
|
||||
app.setName('3DGenStudio');
|
||||
|
||||
const BACKEND_PORT = Number(process.env.PORT) || 3001;
|
||||
const BACKEND_ORIGIN = `http://localhost:${BACKEND_PORT}`;
|
||||
const PYTHON_PORT = Number(process.env.MESHTOOLS_PORT) || 8200;
|
||||
|
||||
// app.getAppPath() is the project root in dev and resources/app in a packaged
|
||||
// build (we ship unpacked — asar:false — so relative requires + dist/ resolve
|
||||
// normally and the backend can serve static files without asar path shims).
|
||||
const APP_ROOT = app.getAppPath();
|
||||
const SERVER_JS = path.join(APP_ROOT, 'server.js');
|
||||
const PYTHON_DIR = path.join(APP_ROOT, 'python-server');
|
||||
|
||||
// The backend keys its data/ folder off process.cwd() (see storage.js), so we
|
||||
// point it at a per-user writable location. The installed app directory is
|
||||
// read-only on macOS/Linux, so we must not write there.
|
||||
const DATA_ROOT = process.env.GENSTUDIO_DATA_ROOT || app.getPath('userData');
|
||||
const LOG_DIR = path.join(DATA_ROOT, 'logs');
|
||||
|
||||
let backendProc = null;
|
||||
let pythonHandle = null;
|
||||
let mainWindow = null;
|
||||
let shuttingDown = false;
|
||||
|
||||
function log(line) {
|
||||
const stamped = `[main] ${line}`;
|
||||
console.log(stamped);
|
||||
try {
|
||||
fs.mkdirSync(LOG_DIR, { recursive: true });
|
||||
fs.appendFileSync(path.join(LOG_DIR, 'desktop.log'), stamped + '\n');
|
||||
} catch {
|
||||
/* logging must never crash startup */
|
||||
}
|
||||
}
|
||||
|
||||
function openLogStream(name) {
|
||||
fs.mkdirSync(LOG_DIR, { recursive: true });
|
||||
return fs.createWriteStream(path.join(LOG_DIR, name), { flags: 'a' });
|
||||
}
|
||||
|
||||
function startBackend() {
|
||||
log(`Starting backend: ${SERVER_JS} (port ${BACKEND_PORT}, cwd ${DATA_ROOT})`);
|
||||
fs.mkdirSync(DATA_ROOT, { recursive: true });
|
||||
|
||||
const out = openLogStream('backend.log');
|
||||
const proc = spawn(process.execPath, [SERVER_JS], {
|
||||
cwd: DATA_ROOT,
|
||||
env: {
|
||||
...process.env,
|
||||
ELECTRON_RUN_AS_NODE: '1', // run server.js as plain Node, not an Electron window
|
||||
PORT: String(BACKEND_PORT),
|
||||
NODE_ENV: 'production',
|
||||
},
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
proc.stdout.pipe(out);
|
||||
proc.stderr.pipe(out);
|
||||
proc.on('exit', (code, signal) => {
|
||||
log(`Backend exited (code=${code} signal=${signal})`);
|
||||
if (!shuttingDown) {
|
||||
dialog.showErrorBox(
|
||||
'3D Gen Studio — backend stopped',
|
||||
`The backend process exited unexpectedly (code ${code}).\n\nSee ${path.join(LOG_DIR, 'backend.log')}`
|
||||
);
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
return proc;
|
||||
}
|
||||
|
||||
// Poll the backend until it answers or we time out.
|
||||
function waitForBackend(timeoutMs = 60000, intervalMs = 400) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
return new Promise((resolve, reject) => {
|
||||
const tick = () => {
|
||||
const req = http.get(`${BACKEND_ORIGIN}/`, (res) => {
|
||||
res.resume();
|
||||
resolve();
|
||||
});
|
||||
req.on('error', () => {
|
||||
if (Date.now() > deadline) reject(new Error('Backend did not start in time'));
|
||||
else setTimeout(tick, intervalMs);
|
||||
});
|
||||
req.setTimeout(2000, () => req.destroy());
|
||||
};
|
||||
tick();
|
||||
});
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1600,
|
||||
height: 1000,
|
||||
minWidth: 1024,
|
||||
minHeight: 700,
|
||||
backgroundColor: '#111318',
|
||||
show: false,
|
||||
title: '3D Gen Studio',
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.once('ready-to-show', () => mainWindow.show());
|
||||
mainWindow.loadURL(BACKEND_ORIGIN);
|
||||
|
||||
// Open external links (docs, Discord, cloud API dashboards) in the OS browser.
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
if (!url.startsWith(BACKEND_ORIGIN)) {
|
||||
shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
return { action: 'allow' };
|
||||
});
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
}
|
||||
|
||||
function loadingWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 520,
|
||||
height: 320,
|
||||
frame: false,
|
||||
resizable: false,
|
||||
transparent: true,
|
||||
backgroundColor: '#00000000',
|
||||
show: true,
|
||||
center: true,
|
||||
title: '3D Gen Studio',
|
||||
// Edit electron/splash.html to change the splash design.
|
||||
});
|
||||
win.loadFile(path.join(__dirname, 'splash.html'));
|
||||
return win;
|
||||
}
|
||||
|
||||
async function boot() {
|
||||
const splash = loadingWindow();
|
||||
|
||||
backendProc = startBackend();
|
||||
|
||||
// Python is optional — Auto UV/Retopo only. Never block or fail the app on it.
|
||||
try {
|
||||
pythonHandle = startPythonService({
|
||||
pythonDir: PYTHON_DIR,
|
||||
dataRoot: DATA_ROOT,
|
||||
port: PYTHON_PORT,
|
||||
logStream: openLogStream('python.log'),
|
||||
log,
|
||||
});
|
||||
} catch (err) {
|
||||
log(`Python service failed to start (non-fatal): ${err.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await waitForBackend();
|
||||
log('Backend is up.');
|
||||
} catch (err) {
|
||||
log(`Backend startup failed: ${err.message}`);
|
||||
dialog.showErrorBox(
|
||||
'3D Gen Studio — failed to start',
|
||||
`The backend did not start.\n\nSee ${path.join(LOG_DIR, 'backend.log')}`
|
||||
);
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
createWindow();
|
||||
if (!splash.isDestroyed()) splash.close();
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
shuttingDown = true;
|
||||
if (pythonHandle && typeof pythonHandle.stop === 'function') {
|
||||
try { pythonHandle.stop(); } catch { /* ignore */ }
|
||||
}
|
||||
if (backendProc && !backendProc.killed) {
|
||||
try { backendProc.kill(); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
// Single-instance: focus the existing window instead of launching a 2nd copy
|
||||
// (which would fight over ports 3001/8200).
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
|
||||
app.whenReady().then(boot);
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
||||
|
||||
app.on('before-quit', shutdown);
|
||||
process.on('exit', shutdown);
|
||||
}
|
||||
11
electron/preload.cjs
Normal file
11
electron/preload.cjs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Minimal preload. The UI is a normal same-origin web app served by the
|
||||
// backend, so it needs no privileged bridge today. We expose only a tiny,
|
||||
// read-only marker so the frontend can detect it's running inside the desktop
|
||||
// shell (e.g. to hide "open in browser" hints) without granting Node access.
|
||||
const { contextBridge } = require('electron');
|
||||
|
||||
contextBridge.exposeInMainWorld('genStudioDesktop', {
|
||||
isDesktop: true,
|
||||
platform: process.platform,
|
||||
version: process.env.npm_package_version || null,
|
||||
});
|
||||
168
electron/python.cjs
Normal file
168
electron/python.cjs
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
// Cross-platform launcher for the Python mesh-tools service (Auto UV / Auto
|
||||
// Retopo). This is the Node/Electron equivalent of python-server/run.bat, made
|
||||
// to work on Windows, macOS and Linux.
|
||||
//
|
||||
// Model: "require Python on the machine" (fastest to ship). On first launch we
|
||||
// 1. locate a system Python interpreter,
|
||||
// 2. create a virtualenv in a WRITABLE location (the per-user data dir — the
|
||||
// installed app folder is read-only on macOS/Linux),
|
||||
// 3. install requirements.txt (CPU-only base install),
|
||||
// then run main.py against that venv. Subsequent launches reuse the venv.
|
||||
//
|
||||
// IMPORTANT: every step here is ASYNCHRONOUS. venv creation + pip install take
|
||||
// minutes on first run; doing them synchronously (spawnSync) would block
|
||||
// Electron's main-process event loop and starve the backend health-poll,
|
||||
// causing a bogus "backend did not start" error on first launch.
|
||||
//
|
||||
// GPU acceleration (CuPy/Warp) is intentionally NOT installed here to keep the
|
||||
// first-run install portable and fast; it can be layered in later per the
|
||||
// python-server README (requirements-nvidia.txt + detect_cuda.py).
|
||||
|
||||
const path = require('node:path');
|
||||
const fs = require('node:fs');
|
||||
const { spawn, spawnSync } = require('node:child_process');
|
||||
|
||||
const IS_WIN = process.platform === 'win32';
|
||||
|
||||
function venvPython(venvDir) {
|
||||
return IS_WIN
|
||||
? path.join(venvDir, 'Scripts', 'python.exe')
|
||||
: path.join(venvDir, 'bin', 'python');
|
||||
}
|
||||
|
||||
// Written only after requirements install fully succeeds. Gating on this (not
|
||||
// just python.exe's existence) means a venv left half-built by a crashed or
|
||||
// interrupted first run is detected and completed on the next launch, instead
|
||||
// of launching a broken service that fails on missing imports.
|
||||
function depsMarker(venvDir) {
|
||||
return path.join(venvDir, '.deps-installed');
|
||||
}
|
||||
|
||||
// Find a usable system Python (3.x). A one-shot `--version` probe is instant,
|
||||
// so spawnSync is fine here (it does not block for any meaningful time).
|
||||
function findSystemPython() {
|
||||
const candidates = IS_WIN ? ['python', 'python3', 'py'] : ['python3', 'python'];
|
||||
for (const c of candidates) {
|
||||
try {
|
||||
const r = spawnSync(c, ['--version'], { encoding: 'utf8' });
|
||||
if (r.status === 0 && /Python 3\./.test((r.stdout || '') + (r.stderr || ''))) {
|
||||
return c;
|
||||
}
|
||||
} catch {
|
||||
/* try next */
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Public entry point. Fully non-blocking: kicks off setup + launch and returns
|
||||
// immediately with a handle exposing stop().
|
||||
function startPythonService({ pythonDir, dataRoot, port, logStream, log }) {
|
||||
const venvDir = path.join(dataRoot, 'python-venv');
|
||||
let proc = null;
|
||||
let stopped = false;
|
||||
|
||||
const write = (s) => { try { logStream.write(s); } catch { /* ignore */ } };
|
||||
|
||||
// Run a command asynchronously, streaming output to the log. Resolves to the
|
||||
// exit code (0 = success). Never rejects.
|
||||
const run = (cmd, args) =>
|
||||
new Promise((resolve) => {
|
||||
write(`\n$ ${cmd} ${args.join(' ')}\n`);
|
||||
let p;
|
||||
try {
|
||||
p = spawn(cmd, args, { cwd: pythonDir });
|
||||
} catch (err) {
|
||||
write(`spawn error: ${err.message}\n`);
|
||||
return resolve(-1);
|
||||
}
|
||||
// {end:false} so a finished child doesn't close the shared log stream.
|
||||
p.stdout.on('data', (d) => write(d.toString()));
|
||||
p.stderr.on('data', (d) => write(d.toString()));
|
||||
p.on('error', (err) => { write(`error: ${err.message}\n`); resolve(-1); });
|
||||
p.on('exit', (code) => resolve(code));
|
||||
});
|
||||
|
||||
async function ensureVenv() {
|
||||
// Fully set up already (venv + deps marker) → nothing to do.
|
||||
if (fs.existsSync(venvPython(venvDir)) && fs.existsSync(depsMarker(venvDir))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const py = venvPython(venvDir);
|
||||
|
||||
// Create the venv only if it isn't there yet. If a previous run created it
|
||||
// but crashed before finishing pip install, reuse it and just (re)install.
|
||||
if (!fs.existsSync(py)) {
|
||||
const sysPython = findSystemPython();
|
||||
if (!sysPython) {
|
||||
log(
|
||||
'Python 3 not found on PATH — the mesh-tools service (Auto UV/Retopo) ' +
|
||||
'will be unavailable. Install Python 3.10+ and restart to enable it.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
log(`First run: creating Python venv with "${sysPython}" (this can take a few minutes)…`);
|
||||
fs.mkdirSync(path.dirname(venvDir), { recursive: true });
|
||||
if ((await run(sysPython, ['-m', 'venv', venvDir])) !== 0) {
|
||||
log('Failed to create Python venv — see python.log.');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log('Completing Python setup (installing dependencies)…');
|
||||
}
|
||||
|
||||
await run(py, ['-m', 'pip', 'install', '--upgrade', 'pip']);
|
||||
|
||||
const reqs = path.join(pythonDir, 'requirements.txt');
|
||||
if ((await run(py, ['-m', 'pip', 'install', '-r', reqs])) !== 0) {
|
||||
log('Failed to install Python requirements — see python.log.');
|
||||
return false;
|
||||
}
|
||||
|
||||
try { fs.writeFileSync(depsMarker(venvDir), new Date().toISOString()); } catch { /* ignore */ }
|
||||
log('Python environment ready.');
|
||||
return true;
|
||||
}
|
||||
|
||||
async function launch() {
|
||||
try {
|
||||
if (stopped) return;
|
||||
const ok = await ensureVenv();
|
||||
if (stopped || !ok) return;
|
||||
|
||||
const py = venvPython(venvDir);
|
||||
log(`Starting Python mesh-tools service on port ${port}…`);
|
||||
proc = spawn(py, ['main.py'], {
|
||||
cwd: pythonDir,
|
||||
env: {
|
||||
...process.env,
|
||||
MESHTOOLS_HOST: '127.0.0.1',
|
||||
MESHTOOLS_PORT: String(port),
|
||||
},
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
proc.stdout.on('data', (d) => write(d.toString()));
|
||||
proc.stderr.on('data', (d) => write(d.toString()));
|
||||
proc.on('exit', (code, signal) => {
|
||||
log(`Python service exited (code=${code} signal=${signal})`);
|
||||
});
|
||||
} catch (err) {
|
||||
log(`Python service failed: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Fire and forget — runs on the microtask queue, never blocks the caller.
|
||||
launch();
|
||||
|
||||
return {
|
||||
stop() {
|
||||
stopped = true;
|
||||
if (proc && !proc.killed) {
|
||||
try { proc.kill(); } catch { /* ignore */ }
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { startPythonService };
|
||||
77
electron/splash.html
Normal file
77
electron/splash.html
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0d0f14;
|
||||
--card: #141821;
|
||||
--text: #e8eaf0;
|
||||
--muted: #8b91a3;
|
||||
--accent1: #7c5cff;
|
||||
--accent2: #22d3ee;
|
||||
}
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body { width: 100%; height: 100%; background: transparent; overflow: hidden; }
|
||||
body {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-family: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
|
||||
-webkit-user-select: none; user-select: none;
|
||||
}
|
||||
.card {
|
||||
position: relative;
|
||||
width: 500px; height: 300px;
|
||||
background: radial-gradient(120% 140% at 50% 0%, #1a1f2b 0%, var(--card) 45%, var(--bg) 100%);
|
||||
border: 1px solid rgba(255,255,255,0.06);
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 24px 70px rgba(0,0,0,0.55);
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
/* Soft animated glow behind the mark */
|
||||
.glow {
|
||||
position: absolute; top: -40px; width: 260px; height: 260px; border-radius: 50%;
|
||||
background: radial-gradient(circle, rgba(124,92,255,0.35), transparent 65%);
|
||||
filter: blur(14px);
|
||||
animation: pulse 3.4s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse { 0%,100%{opacity:.55;transform:scale(1)} 50%{opacity:1;transform:scale(1.12)} }
|
||||
|
||||
.mark { position: relative; width: 72px; height: 72px; margin-bottom: 18px; }
|
||||
.ring {
|
||||
position: absolute; inset: 0; border-radius: 50%;
|
||||
border: 3px solid rgba(255,255,255,0.08);
|
||||
border-top-color: var(--accent1);
|
||||
border-right-color: var(--accent2);
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
.orb {
|
||||
position: absolute; inset: 16px; border-radius: 50%;
|
||||
background: linear-gradient(135deg, var(--accent1), var(--accent2));
|
||||
box-shadow: 0 0 22px rgba(124,92,255,0.55);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 22px;
|
||||
}
|
||||
.title {
|
||||
font-size: 26px; font-weight: 700; letter-spacing: .3px;
|
||||
background: linear-gradient(90deg, #ffffff, #c9c2ff 60%, #9be9ff);
|
||||
-webkit-background-clip: text; background-clip: text; color: transparent;
|
||||
}
|
||||
.status { margin-top: 10px; font-size: 13px; color: var(--muted); }
|
||||
.dots::after { content: ""; animation: dots 1.6s steps(4,end) infinite; }
|
||||
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="glow"></div>
|
||||
<div class="mark">
|
||||
<div class="ring"></div>
|
||||
<div class="orb">🌌</div>
|
||||
</div>
|
||||
<div class="title">3D Gen Studio</div>
|
||||
<div class="status">Starting local services<span class="dots"></span></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
4187
package-lock.json
generated
4187
package-lock.json
generated
File diff suppressed because it is too large
Load diff
15
package.json
15
package.json
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
"name": "app",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"version": "1.3.2",
|
||||
"type": "module",
|
||||
"main": "electron/main.cjs",
|
||||
"scripts": {
|
||||
"dev": "concurrently \"npm run dev:server\" \"npm run dev:client\"",
|
||||
"dev:server": "node server.js",
|
||||
|
|
@ -11,7 +12,13 @@
|
|||
"start": "node server.js",
|
||||
"serve": "vite build && node server.js",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
"preview": "vite preview",
|
||||
"electron:dev": "npm run build && electron .",
|
||||
"dist": "npm run build && electron-builder",
|
||||
"dist:win": "npm run build && electron-builder --win",
|
||||
"dist:mac": "npm run build && electron-builder --mac",
|
||||
"dist:linux": "npm run build && electron-builder --linux",
|
||||
"dist:dir": "npm run build && electron-builder --dir"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-three/drei": "^10.7.7",
|
||||
|
|
@ -48,6 +55,8 @@
|
|||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.4.0",
|
||||
"vite": "^8.0.4"
|
||||
"vite": "^8.0.4",
|
||||
"electron": "^33.2.0",
|
||||
"electron-builder": "^25.1.8"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue