TD-0013: Web, desktop and Android shells¶
Status: Accepted, in progress · React 18 · 16 November 2026
Related: TD-0011 Time service.
Loryth runs as three shells around one React application: the browser, an installed Electron desktop app, and an installed Capacitor Android app. The shells share the UI and almost all logic. Each shell overrides what differs between platforms (secret storage, microphone permission, notifications, clipboard, system integration) behind one typed interface.
Decisions¶
- React DOM in all three shells. The web app is about 54k lines on Radix, vanilla-extract and other DOM libraries. A React Native Android app would mean writing every screen twice.
- One UI build.
apps/webbuilds the UI. The desktop package and the APK carry a copy and load it from disk, so they start without the network. At start-up the UI detects the shell and loads that shell's platform code. - A typed
Platformobject (@loryth-ui/platform) is the only way app code reaches storage, secrets, the microphone, the clipboard, notifications, external links, the server address, UI updates and desktop-only features. - App source lives in
packages/app(@loryth-ui/app), grouped intoshell/,modules/<name>/andshared/.apps/webis a thin Vite project. - The server address is a runtime value.
@loryth-ui/apiexposesconfigureApiBase()andapiUrl(). Paths given tocustomFetchstay relative; any URL handed to the browser itself (fetch,<img src>) goes throughapiUrl(). The browser shell keeps the empty base, so it calls its own origin. - CORS at the gateway for two fixed origins:
https://localhost(Android) andloryth-app://local(desktop). Sign-in uses bearer tokens only, so no credentials mode is needed. - Installed apps update their UI from the server they are connected to. The web image publishes
/shell/manifest.jsonand/shell/bundle.zip. The UI and the API therefore come from the same commit. An APK or RPM release is needed only when native code changes. - Desktop: Electron, RPM package, sandboxed renderer, typed IPC. The app sets up the Time desktop recorder with its own signed-in session.
- Android: Capacitor replaces the Expo WebView shell under the same package id and signing key, so it installs as an upgrade.
- No
lorythCLI for now. The desktop app covers recorder set-up, and the Time uploader stays a small separate program that a systemd timer runs.
What "native" means in each shell¶
| Shell | What draws the UI | What is native |
|---|---|---|
| Web | The browser | Nothing |
| Desktop | Chromium inside Electron, loading the UI from loryth-app://local/ | The main process: tray with the running timer, start at login, keyring-encrypted tokens, system notifications, installing the GNOME extension and uploader, recorder status |
| Android | The Android System WebView inside Capacitor, loading the UI from https://localhost/ | Plugins: Keystore token storage, notifications, clipboard, back button, deep links, system bars, microphone permission |
Screens are HTML and CSS in every shell. Scrolling, text selection and keyboard behaviour follow the web view. Widgets or background work would need native code written later behind the same interface.
Layers¶
apps/web apps/desktop apps/android
(Vite build) (Electron main+preload) (Capacitor project)
\ | /
+--------- @loryth-ui/app (routes, shell, modules) ---------+
|
@loryth-ui/platform (contract + browser / desktop / android)
|
@loryth-ui/api @loryth-ui/web @loryth-ui/theme @loryth-ui/tokens @loryth-ui/domain
@loryth-ui/appnever toucheslocalStorage,navigator.clipboard,navigator.mediaDevices,Notificationorwindow.opendirectly; it callsusePlatform(). ESLint enforces this.@loryth-ui/platformis the only package that imports@capacitor/*or reads the desktop bridge.apps/desktop/src/mainis the only code that runs with Node privileges.
Platform contract¶
ui/packages/platform/src/contract.ts defines Platform with these parts: info (shell kind, shell version, bridge level), storage (non-secret key-value), secrets (tokens), server (current origin, choose another), microphone, clipboard, notifications, appearance, updates, navigation (external links, paths opened by the shell) and desktop (tray, autostart, Time recorder; null outside the desktop app).
bridge-version.json holds one integer per installed shell. Within a level the bridge only grows; new abilities are feature-checked. The level is raised only when the UI cannot work without a method older shells lack, and that shell is released in the same change.
Server address and sign-in¶
The desktop and Android apps open on a Server screen the first time. The person enters the address (HTTPS only); the app checks GET {origin}/api/v1/iam/health, then shows the normal sign-in page against that server. Tokens are stored per server origin: the browser keeps localStorage, the desktop app uses Electron safeStorage (GNOME keyring), Android uses the Keystore. Sessions appear in Profile › Devices as "Loryth desktop app" or "Loryth Android app" and can be revoked there.
UI updates and compatibility¶
After vite build, a script writes dist/shell/manifest.json (entry script, the bridge level each shell needs, bundle URL, SHA-256, size) and dist/shell/bundle.zip. Every shell polls the manifest every 10 minutes and when it becomes visible:
- same entry script: nothing to do;
- the server needs a newer bridge than this shell has: a banner asks to install the app update, and the current UI keeps running;
- otherwise the shell downloads and verifies the bundle and offers Reload.
A downloaded desktop build that does not confirm it started within two starts is dropped in favour of the previous one, or the built-in UI. Android uses the updater plugin's confirmation timeout (10 seconds by default), then rolls back to the last confirmed bundle. Desktop 0.4.0 remembers failed SHA-256 values and refuses them on later downloads. It keeps two complete bundles: active and previous, or active and pending before Reload. Bundles carry their server origin; changing servers clears downloaded UI and reloads the built-in build. Zip downloads are limited to 50 MiB, unpacked files to 200 MiB, and redirects are refused. React confirms a build after mounting. The bridge takes data, never commands or file paths, because a server can replace the UI code that calls it.
Desktop app¶
- Electron with
contextIsolation,sandboxand no Node integration in the renderer. The preload exposes a fixed list of IPC channels, and each main process handler checks the sender URL and parses its arguments. - The
loryth-app://scheme serves the active UI folder with a strict CSP; navigation away from the app origin is cancelled and links open in the system browser. - Tray with the running Time timer and a Stop item, close to tray, start at login (
$XDG_CONFIG_HOME/autostart/loryth.desktop, falling back to~/.config), system notifications. If creating the tray fails, a hidden launch shows the window so the app remains reachable. - Record this computer in Time › Settings creates a device with the session, installs the GNOME extension, the uploader (
.pyz, run by the systempython3) and its systemd user timer, and enables the extension, so only a log-out is left. The uploader keeps its device key in its own 0600 config, so the timer never needs the keyring. - Desktop 0.3.0 includes the extension, systemd units and standalone zipapp in the RPM, which requires
python3. Support checks read the extension's supported Shell majors and require Python 3.13 or later and the systemd user manager. Schemas compile in a staging directory before replacement. - If
gnome-extensions enablefails before Shell loads the extension, the app appends its UUID toorg.gnome.shell enabled-extensions. Other entries stay intact; an existing UUID is not added twice. A logout loads it. - Turn on can omit the key only for the same installed device and server. Reconnect creates a new device/key. Try again rechecks status; the timer retries uploads every minute. Stop removes the local recorder, then revokes the device. At startup a higher packaged extension version refreshes the extension, uploader and units without changing the key.
- Packaged as an RPM for Fedora and published on the download page.
Android app¶
Capacitor project under ui/apps/android, package com.loryth.mobile, signed with the existing key. It adds the microphone permission the WebView shell lacked, follows the system light or dark mode, maps the back button to history, opens external links in the browser and handles loryth://open/<path>. Android 0.5.0 / versionCode 10 uses Capacitor 8.6.2 and updater 8.54.2 in manual mode. The updater accepts the zip's lowercase hex SHA-256 and verifies it before extraction. No cloud update or statistics endpoints are configured. System bars follow the resolved UI scheme; shared insets use Capacitor's CSS variables with browser safe-area fallbacks. The Expo source and React Native component package have been removed. The old installed WebView app's change-server bridge remains until every phone has upgraded (MR 12).
Releases¶
Most changes need no app release, because installed apps fetch the UI from the server. A change to native code (ui/apps/desktop, clients/gnome, ui/apps/android, platform code that needs a new plugin or permission, or a raised bridge level) bumps that shell's version in the same merge request. The android and desktop actions on the main branch skip versions that are already published.
Rollout¶
The work ships as a series of merge requests, each deployable on its own:
- Configurable server address in
@loryth-ui/api(this document). - Move the app source into
packages/app. - Group the app into
shell,modulesandshared. - Platform package; browser APIs go through it; Server screen.
- Gateway CORS and the UI build manifest.
- Desktop app: window, protocol, secrets, packaging and release.
- Desktop tray timer, start at login and notifications.
- Record this computer (desktop 0.3.0).
- Desktop UI updates from the server (desktop 0.4.0, bridge level 1).
- Capacitor Android app.
- Remove the Expo app and React Native leftovers.
- Drop support for the old WebView app once every phone runs the new one.