- 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.
6.6 KiB
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, 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 installin this folder).cargo install tauri-cli --version "^2"also works if you prefercargo tauri .... - For the backend: a running MySQL and
backend/settings.json(seebackend/settings.json.example), with dependencies installed inbackend/.
Run in dev
cd react_frontend && pnpm install
cd ../backend && pnpm install
cd ../tauri && pnpm install
pnpm dev
pnpm dev (= tauri dev) does the following:
- Runs
pnpm --dir ../react_frontend dev:tauri: Vite onhttp://localhost:4200withVITE_TAURI=true(API basehttp://localhost:4000/api/v1, hash router, custom title bar). - 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=1to skip). - Starts the backend with
node server.jsin../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
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 asbackend.exe).src-tauri/target/release/bundle/nsis/Showy_2.0.0_x64-setup.exe: an installer that putsshowy.exeandbackend.exeside 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.tsandrouter.tsxuseisDesktopBuild(Electron or Tauri build), so both desktop builds talk tolocalhost:4000and use the hash router.TitleBar.tsx: on Tauri the buttons call@tauri-apps/api/window(minimize,toggleMaximize,close), which is loaded lazily. Dragging usesdata-tauri-drag-region. Electron keeps usingwindow.electron.windowControlsand-webkit-app-region.vite.config.ts:base: './',strictPortand no screen clearing whenVITE_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 createsettings.json. The backend needs to read its settings next to the executable (path.dirname(process.execPath)whenprocess.pkgis set) or from a folder the shell passes in, e.g. viaPARENT_PROCESS.tauri_path(the app data dir, already sent).sharpandffmpeg-staticnative files also need checking in the pkg build. - Backend model: Electron
requiresserver.jsin its own process. Tauri runs it as a separate process (nodein dev, the pkgbackend.exein 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 devloads the plainvitedev server, which proxies/apito 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
dirbuild instead.