Add Tauri v2 desktop app alongside Electron
- New tauri/ project: frameless 1280x800 window, loads the Vite dev server in dev and tauri/frontend_build in release builds. - Starts the backend on launch (node server.js in dev, pkg backend.exe sidecar in release) and stops it on exit through a Windows job object; reuses a backend already listening on port 4000. - Custom title bar works in Tauri (minimize, maximize, close, drag region) with the matching window capabilities. - react_frontend: dev:tauri / build:tauri scripts, shared platform flags so Electron and Tauri builds both use the local API and hash router. Web and Electron builds are unchanged. - tauri/README.md: prerequisites, dev, build, and gaps vs Electron.
This commit is contained in:
1 parent
06bf902ad3
commit
3144bd96c9
30 files changed
+5121
-14
No files matched your search
+128
@@ -0,0 +1,128 @@
|
||||
# Showy — Tauri desktop app
|
||||
|
||||
A Tauri v2 shell for Showy, built side by side with the Electron app in `../electron`
|
||||
(which stays untouched). It loads the React frontend from `../react_frontend` and
|
||||
starts the Node backend from `../backend` alongside the window.
|
||||
|
||||
```
|
||||
tauri/
|
||||
├─ package.json # Tauri CLI + scripts
|
||||
├─ scripts/prepare-sidecar.mjs # copies dist/backend/backend.exe into src-tauri/binaries
|
||||
├─ frontend_build/ # output of `pnpm build:tauri` (git-ignored)
|
||||
└─ src-tauri/
|
||||
├─ tauri.conf.json # window, dev URL, frontend dist, bundle
|
||||
├─ tauri.bundle.conf.json # adds the backend sidecar; merged in only for `pnpm build`
|
||||
├─ capabilities/default.json # window permissions for the custom title bar
|
||||
├─ icons/ # generated from electron/assets/icon.ico
|
||||
└─ src/
|
||||
├─ lib.rs # app setup, stops the backend on exit
|
||||
└─ backend.rs # starts/stops the backend process
|
||||
```
|
||||
|
||||
## Prerequisites (Windows)
|
||||
|
||||
- **Rust** (stable, MSVC toolchain): install with [rustup](https://rustup.rs/), target
|
||||
`x86_64-pc-windows-msvc`.
|
||||
- **Microsoft C++ Build Tools**: "Desktop development with C++" workload from Visual Studio
|
||||
Build Tools (needed by the MSVC Rust toolchain).
|
||||
- **WebView2 runtime**: preinstalled on Windows 11. On Windows 10 install the Evergreen
|
||||
runtime from Microsoft.
|
||||
- **Node.js** (22.x is used here) and **pnpm**.
|
||||
- **Tauri CLI**: installed per project as `@tauri-apps/cli` (`pnpm install` in this folder).
|
||||
`cargo install tauri-cli --version "^2"` also works if you prefer `cargo tauri ...`.
|
||||
- For the backend: a running **MySQL** and `backend/settings.json` (see
|
||||
`backend/settings.json.example`), with dependencies installed in `backend/`.
|
||||
|
||||
## Run in dev
|
||||
|
||||
```bash
|
||||
cd react_frontend && pnpm install
|
||||
cd ../backend && pnpm install
|
||||
cd ../tauri && pnpm install
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
`pnpm dev` (= `tauri dev`) does the following:
|
||||
|
||||
1. Runs `pnpm --dir ../react_frontend dev:tauri`: Vite on `http://localhost:4200` with
|
||||
`VITE_TAURI=true` (API base `http://localhost:4000/api/v1`, hash router, custom title bar).
|
||||
2. Builds and starts the Rust app, which opens the window on the dev server (with hot reload)
|
||||
and opens DevTools, like Electron's dev mode (set `SHOWY_NO_DEVTOOLS=1` to skip).
|
||||
3. Starts the backend with `node server.js` in `../backend`. Its output shows in the same
|
||||
terminal. When the window closes the backend is stopped, and so is anything it spawned (a
|
||||
Windows job object kills the process tree, even if the app crashes).
|
||||
|
||||
If something already listens on port 4000 (e.g. you run `pnpm dev` in `backend/` yourself), the
|
||||
app does **not** start a second backend and uses the one that is running.
|
||||
|
||||
Environment overrides:
|
||||
|
||||
| Variable | Effect |
|
||||
| --- | --- |
|
||||
| `SHOWY_SKIP_BACKEND=1` | never start a backend |
|
||||
| `SHOWY_BACKEND_DIR=<path>` | backend folder for dev builds (default `../backend`) |
|
||||
| `SHOWY_BACKEND_EXE=<path>` | run this executable as the backend (dev or release) |
|
||||
| `SHOWY_NO_DEVTOOLS=1` | don't open DevTools in dev builds |
|
||||
|
||||
The first `tauri dev` compiles all Rust dependencies, which takes several minutes. Later runs
|
||||
take seconds.
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
cd backend && npm run package # pkg -> dist/backend/backend.exe
|
||||
cd ../tauri && pnpm build-backend # copies it to src-tauri/binaries/backend-x86_64-pc-windows-msvc.exe
|
||||
pnpm build # tauri build (runs `pnpm build:tauri` in react_frontend first)
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
- `src-tauri/target/release/showy.exe`: the app (the sidecar must sit next to it as `backend.exe`).
|
||||
- `src-tauri/target/release/bundle/nsis/Showy_2.0.0_x64-setup.exe`: an installer that puts
|
||||
`showy.exe` and `backend.exe` side by side.
|
||||
|
||||
In release builds the backend runs without a console, and its output goes to
|
||||
`%LOCALAPPDATA%\x4lo.showy\logs\backend.log`.
|
||||
|
||||
The frontend build for Tauri goes to `tauri/frontend_build`. The web build (`pnpm build`) and
|
||||
the Electron build (`pnpm build:electron`) are unchanged.
|
||||
|
||||
## Frontend changes
|
||||
|
||||
- `react_frontend/src/lib/platform.ts`: `isTauri`, `isElectron`, `isDesktop`, `isDesktopBuild`.
|
||||
- `api.ts` and `router.tsx` use `isDesktopBuild` (Electron **or** Tauri build), so both desktop
|
||||
builds talk to `localhost:4000` and use the hash router.
|
||||
- `TitleBar.tsx`: on Tauri the buttons call `@tauri-apps/api/window` (`minimize`,
|
||||
`toggleMaximize`, `close`), which is loaded lazily. Dragging uses `data-tauri-drag-region`.
|
||||
Electron keeps using `window.electron.windowControls` and `-webkit-app-region`.
|
||||
- `vite.config.ts`: `base: './'`, `strictPort` and no screen clearing when `VITE_TAURI=true`.
|
||||
- New scripts: `dev:tauri`, `build:tauri`.
|
||||
|
||||
## Status / missing compared with Electron
|
||||
|
||||
Tested on Windows 11 in dev mode: the window opens on the Vite dev server, the backend starts
|
||||
and answers the webview on port 4000, the title-bar window commands (minimize, maximize/restore,
|
||||
close) work, and closing the window stops the backend.
|
||||
|
||||
Not done yet / differences:
|
||||
|
||||
- **The release build has not been tested yet.** It needs `dist/backend/backend.exe`, and there
|
||||
is a known problem with the pkg backend: `configService.getUserDataPath()` uses `__dirname`,
|
||||
which points inside pkg's read-only snapshot. So the packaged backend cannot find or create
|
||||
`settings.json`. The backend needs to read its settings next to the executable
|
||||
(`path.dirname(process.execPath)` when `process.pkg` is set) or from a folder the shell passes
|
||||
in, e.g. via `PARENT_PROCESS.tauri_path` (the app data dir, already sent). `sharp` and
|
||||
`ffmpeg-static` native files also need checking in the pkg build.
|
||||
- **Backend model**: Electron `require`s `server.js` in its own process. Tauri runs it as a
|
||||
separate process (`node` in dev, the pkg `backend.exe` in release).
|
||||
- **`PARENT_PROCESS`**: Electron sends `{ electron_path: userData }`. Tauri sends
|
||||
`{ tauri_path: <app data dir> }`. The backend doesn't read either today.
|
||||
- **Generic IPC**: Electron's preload also exposes `window.electron.ipcRenderer`. The frontend
|
||||
doesn't use it, so Tauri has no equivalent (only window controls).
|
||||
- **Title bar on the login page**: the window has no native frame, and the login page renders
|
||||
outside `AppLayout`, so there is no title bar to drag or close the window until you log in.
|
||||
Electron behaves the same way.
|
||||
- **Dev API target**: Electron's `npm run dev` loads the plain `vite` dev server, which proxies
|
||||
`/api` to the remote backend. Tauri dev uses the local backend on port 4000.
|
||||
- No auto-update, tray icon, single-instance lock or code signing (Electron has none of these
|
||||
either). The bundle target is NSIS. Electron produces an unpacked `dir` build instead.
|
||||
Reference in new issue
Block a user