storebound/docs/desktop.md

129 lines
9.9 KiB
Markdown

# storebound desktop (apps/desktop)
A Tauri 2 window around the storebound CLI: every app in a workspace, on iOS and Android, in one place. It is in
development; this page is for contributors.
## Shape
- **One source of logic.** The app never calls a store itself. It runs the storebound CLI as a sidecar
(`storebound serve --stdio`, compiled with `bun tools/build-sidecars.ts`) and asks it for everything.
- **App-centric.** One app = one product with up to two platforms (iOS bundle id / App Store Connect app id, Android
package name), one `storebound.config.ts` per app folder, many apps per workspace. Navigation: Portfolio -> App
(Releases, Catalog, Listings, Health, Reviews, TestFlight) plus the workspace screens (App folders, Accounts,
Dependencies, Settings).
- **Release trains.** A version (for example 2.3.0) spans both stores: iOS build and Android versionCode, per-store
state (TestFlight, review, live, phased release, rollout fraction). `portfolio.status` returns per app the current
train (highest version live on a store) and the next one (highest version above it anywhere).
- **Catalog parity.** Products (and subscriptions, once the config has them) are defined once; `portfolio.status`
compares the config with both stores (ids missing on a store, ids on one store only).
Types of the protocol: `cli/lib/desktop-protocol.ts`; pure portfolio logic: `cli/lib/portfolio.ts`.
## Safety model
- The sidecar's first request is `session.hello` with a 32-byte secret the Rust host makes per start and writes to
the sidecar's stdin. Write methods are dry runs unless the call carries a confirm token: HMAC-SHA256 over the
method, the canonical `{ project, args }` and a 60 s expiry, single use. The host mints one only after the owner
pressed Apply in a native dialog that shows the summary and the dry run (`write_with_confirm`).
- No method submits for review, releases, publishes, resumes or completes a rollout. Under `serve`, the CLI's own
terminal confirmations always answer no.
- The webview gets no plugin API. It may call the app commands (each re-checks the window label and the page origin
in Rust) and listen to two events. Strict CSP, no remote content. `src-tauri/tests/security.rs` pins all of it.
- Store keys (Play service account JSON, App Store Connect key id, issuer id and .p8) are picked in native dialogs,
stored in the OS keychain (`keyring`), never shown again and passed to the sidecar per call in memory only.
## Screens and data (D2)
- **Portfolio**: KPIs (apps, live versions, rolling out, in review, needs attention), one row per app with the version
reaching users on each store and its place on the track (build, testing, review, live, rollout %), the next
version, the last saved crash rate as a sparkline, catalog parity and the config check; then a "needs attention"
list (problems first, then warnings, store read errors, rejected or halted releases, catalog drift, health near a
threshold).
- **App**: Releases (release timeline, both stores on one track per version; iOS phased release day and share from
`apple status --json`), Catalog (parity matrix from `catalog.diff`: matches, differs, missing, not sold there, not
compared; price gaps per region), Listings (`project.listings`: per language and store, fields against the limits,
rendered screenshots), Health (`health`: daily user-perceived crash and ANR rate against the Play thresholds,
worst devices, top issues, App Store metrics and signatures), Reviews (`reviews.list` + `reviews.drafts`: star
distribution, filters, the local draft with its send checks, Approve via `reviews.approve`), TestFlight
(`apple.testflight_status`), Checks (offline `check` + `validate` with fix hints).
- **First-run guide**: what the app does, add or start an app folder (`project.init` = `storebound init --profile`,
confirmed in a native dialog), store keys into the keychain and which app uses which, local tools, first read.
- **Command palette** (Cmd/Ctrl+K): apps, tabs, screens and actions. Cmd/Ctrl+1 Portfolio, +2-5 workspace screens,
Cmd/Ctrl+Shift+[ ] app tabs, arrow keys in the tab list. Toasts show background jobs with progress and Cancel.
- **Unknown, never false.** Store reads run on demand (they use the account's API quota) and are saved in app data
(`cache.sqlite`, results only, never keys); a screen opens with the saved read and its time ("Last read 3 h ago,
saved copy"), a failed read keeps the previous one and says so, and nothing that was not read is shown as fine.
Settings clears the saved reads.
- **Jobs.** The window tags a call with a job id; the host maps sidecar request ids to it, so progress lines reach the
right toast, and `job_cancel` sends `$/cancelRequest` (or stops a download). Live portfolio reads run up to four
apps at a time with their own accounts and report n / total.
- **i18n**: English and Turkish (`src/i18n`), Settings picks the language (default: the system's); `tools/i18n-check.ts`
(CI) checks keys, empty messages and placeholders. **Theme**: text tokens keep 7:1 contrast in both themes
(`tests/theme.test.ts`), motion at most 200 ms and off with reduced motion.
## Dependencies screen
storebound needs no local tool for store work. Screenshots, app previews, icons and captures use:
| tool | used for | how the app gets it |
|---|---|---|
| ffmpeg, ffprobe | icons, renders, app previews, frame crops | download into the app data folder (planned, see below) |
| Chrome / Chrome for Testing | screenshot renders, captions, web captures | system Chrome, or Chrome for Testing downloaded into the app data folder (planned) |
| Xcode command line tools, simctl | iOS builds, Simulator captures | link to Apple only |
| adb | Android emulator / device captures | link to the Android platform tools only |
| git | release notes, analytics compare | link only |
`system.tools` reports each with its path, version and source (`app` or `system`). The host passes app-managed
copies to the sidecar: `STOREBOUND_TOOL_PATH` (app data `tools/bin`, put in front of PATH for every command) and
`STOREBOUND_CHROME` (app data `tools/chrome/...`, used as Playwright's `executablePath`). Nothing is installed
system-wide and nothing is bundled in the installer.
`storebound doctor` prints the same detection (plus playwright) with the install commands for the OS.
Download sources (one click on the Dependencies screen or in the first-run guide; `src-tauri/src/downloads.rs`):
- **ffmpeg, macOS (arm64, x64):** release builds from ffmpeg.martin-riedl.de (static, notarized zip per tool).
- **ffmpeg, Linux (x64, arm64) and Windows (x64):** `ffmpeg-n<major>-latest-<os>-gpl` release builds from
github.com/BtbN/FFmpeg-Builds.
- **Verification:** the app ships a manifest (`src-tauri/tools-manifest.json`, written by `bun tools/tools-manifest.ts`
before each desktop release, `--check` tests the URLs) with the exact URL, size and SHA-256 of each archive; a
download whose hash differs is deleted. Every pinned hash has two independent sources: macOS archives are
downloaded and hashed by the tool and must equal the publisher's `.sha256`; BtbN archives (pinned autobuild tag)
use the digest GitHub computes for the release asset, which must equal the publisher's `checksums.sha256`.
Downloads and their redirects may only use HTTPS and the hosts in `downloads::DOWNLOAD_HOSTS`. Everything is
unpacked and checked in a staging folder; only a verified result replaces the installed copy, and the sidecar
restarts so it sees the new tool.
- **License:** these ffmpeg builds are GPL (v3 for the BtbN `gpl` variants). The app downloads them only on the
owner's click, from the original publisher, shows the license and the source link next to the button, and never
redistributes them, so the app itself stays MIT.
- **Chrome for Testing:** Google's official JSON endpoints
(googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json, Stable channel), archives
from storage.googleapis.com over HTTPS. Those endpoints publish no hashes, so the app checks the code signature after
unpacking (macOS `codesign --verify` with Google's team, Windows Authenticode); on Linux it checks the version banner.
Chrome for Testing is under Google's terms for Chrome / Chromium (BSD-style Chromium license plus third-party notices).
- **Progress and cancel** go through the same progress events as sidecar jobs; a cancelled download removes its
temporary file.
## Develop
```sh
bun install
bun tools/build-sidecars.ts --host # apps/desktop/src-tauri/binaries/storebound-<target triple>
cd apps/desktop && bunx tauri dev # Vite on 127.0.0.1:1420 + the Rust host
cd apps/desktop/src-tauri && cargo test && cargo clippy --all-targets -- -D warnings
```
Dev-only switches (ignored in release builds): `VITE_START=accounts|app:catalog|app:health:2|welcome:3|palette|...`
opens a screen first, `VITE_THEME=light|dark` and `VITE_LANG=en|tr` force theme and language, `VITE_AUTORUN=gallery`
starts the confirm flow on the first app (the same names work as `?start=...&theme=...` query parameters on the Vite
server). `STOREBOUND_DEV_PROJECTS=<dir>:<dir>` (debug builds) seeds the app folder list.
Fixture mode (dev builds only): `VITE_FIXTURES=1` answers every app command from `src/dev/fixtures.ts` (made-up
store data around the two demo apps; `=empty` for a first run, `=cold` for nothing read yet). The window shows a
"DEV FIXTURES" badge; release bundles do not contain it (`tests/webview.test.ts` checks `dist/`). Screenshots of
every screen in both themes: `VITE_FIXTURES=1 bunx vite --port 1431 &` then
`bun scripts/screens.ts --base http://127.0.0.1:1431 --out <dir>` (playwright with the installed Chrome).
Gotchas kept from earlier Tauri apps: Cmd+Q quits and the Window menu keeps an entry for the hidden window; platform
configs (`tauri.<os>.conf.json`) must not set `app.windows` (Tauri replaces the whole array); Linux sets
`WEBKIT_DISABLE_DMABUF_RENDERER=1` unless the user set it; a `bun build --compile` binary needs an ad-hoc re-sign on
macOS or the kernel kills it on start.