Add Windows support via a Tauri (WebView2) shell

zero-native has no Windows target yet, so add a parallel Tauri shell
for Windows that reuses the same frontend:

- src-tauri/: Rust commands (yt_search, yt_streams, store_load,
  store_save) mirroring the Zig bridge; spawns bundled yt-dlp.exe with
  CREATE_NO_WINDOW; data stored in app_data_dir
- frontend bridge now auto-detects window.__TAURI__ vs window.zero and
  routes accordingly; CSP updated for Tauri IPC
- tauri.conf.json bundles yt-dlp.exe as a resource and builds nsis/msi
- scripts/make-icon.js generates appicon.png for 'tauri icon'
- README: native Windows build steps + WSLg fallback note
This commit is contained in:
Jonathan Sykes
2026-06-14 10:04:27 +08:00
parent a171cae417
commit bac6665b3d
12 changed files with 527 additions and 18 deletions

View File

@@ -24,21 +24,32 @@ or Node runtime.
## Architecture
The **same frontend** drives two native shells:
- **Linux / macOS** → zero-native (Zig + system WebView)
- **Windows** → Tauri (Rust + WebView2) — see [Run on Windows](#run-on-windows-tauri)
```
frontend/ Static web UI (no framework, no build step)
frontend/ Static web UI (no framework, no build step) — shared
index.html
styles.css
app.js Player engine + UI; calls window.zero.invoke(...)
src/
app.js Player engine + UI; auto-detects Tauri vs zero-native
src/ zero-native (Linux/macOS) shell
main.zig App definition + bridge handler registration
bridge.zig Native handlers: spawn yt-dlp, slim its JSON, local store
src-tauri/ Tauri (Windows) shell
src/main.rs Same handlers as Rust commands
tauri.conf.json Window, CSP, bundle (icons, yt-dlp resource)
Cargo.toml
scripts/
setup-ytdlp.js Downloads the standalone yt-dlp binary into ./bin
make-icon.js Generates appicon.png for `tauri icon`
bin/ yt-dlp lands here (gitignored)
app.zon App manifest (window, engine, permissions, frontend dir)
app.zon zero-native manifest
```
The web UI talks to the Zig side over the zero-native bridge:
The web UI talks to the native side over whichever bridge is present
(`window.__TAURI__.core.invoke` on Windows, `window.zero.invoke` elsewhere):
| `window.zero.invoke(...)` | Native handler | Returns |
|---|---|---|
@@ -58,8 +69,44 @@ and return only the compact fields the UI needs.
- No system `yt-dlp` needed — the setup script bundles it. (On Linux/macOS the
bundled build is self-contained; Python is not required.)
## Run on Windows (Tauri)
zero-native does **not** target Windows yet, so the Windows build uses a Tauri
shell (Rust + the WebView2 runtime that ships with Windows 10/11). The result is
a small standalone `.exe`/installer — no bundled Chromium or Node.
**Build natively on the Windows machine** (cross-compiling a WebView2 app from
WSL/Linux is unreliable, so do this on Windows):
```powershell
# Prerequisites (one time):
# • Rust https://rustup.rs (MSVC toolchain)
# • Microsoft C++ Build Tools (Desktop development with C++)
# • WebView2 runtime — preinstalled on Win11; on Win10 grab the Evergreen runtime
# • Node.js (to run the helper scripts + Tauri CLI)
npm install # installs the Tauri CLI (@tauri-apps/cli)
npm run setup # downloads yt-dlp.exe into .\bin
npm run make-icon # writes appicon.png
npm run tauri icon .\appicon.png # expands it into src-tauri\icons\*
npm run tauri:dev # hot dev window
npm run tauri:build # produces the installer (see below)
```
The installer lands in
`src-tauri\target\release\bundle\` (`nsis\*-setup.exe` and `msi\*.msi`).
`yt-dlp.exe` is bundled as an app resource, so the installed app is self-contained.
> Already in WSL and just want it running fast? Your WSL is WSLg-enabled, so you
> can instead build the **Linux** (zero-native) target and its window appears on
> your Windows desktop — see [Setup & run](#setup--run). That needs WSL running
> each time; the Tauri build above is a true standalone Windows app.
## Setup & run
> Linux / macOS (zero-native). For Windows see [Run on Windows](#run-on-windows-tauri).
```bash
# 1. Download the yt-dlp binary into ./bin
npm run setup # or: node scripts/setup-ytdlp.js