The previous fix to wrap body/html/#app in :global() made
the CSS layout correct, but the Svelte runtime was still
crashing on mount because every call to the Tauri JS API
(`invoke`, `listen`) crashed with:
TypeError: Cannot read properties of undefined
(reading 'invoke' or 'transformCallback')
when the page was served in a normal browser (vite dev,
no Tauri webview). The error fired inside onMount during
session.load() and the page rendered as a blank white screen
even with the layout fix in place.
The Tauri JS API uses `window.__TAURI_INTERNALS__.invoke` and
`window.__TAURI_INTERNALS__.transformCallback` which are
defined only in the Tauri webview. In the regular browser
preview, both are undefined and any `invoke(...)` or
`listen(...)` call throws immediately.
Fix:
1. Add two helpers in client.ts:
- `tauriCall<T>(cmd, fallback, args?)` for LOAD calls
(e.g. session.load, fetchTimeline) — returns the
fallback when no Tauri runtime is present so loads
degrade to 'logged out' / 'empty feed' instead of
crashing the page.
- `safeInvoke<T>(cmd, args?)` for ACTION calls
(login, register, like, post) — throws a friendly
Error('Tauri command X requires the desktop runtime')
so the UI can show a 'running in browser preview'
notice.
- Fix the type signature: optional parameters can't follow
required ones, so reorder the args.
2. Add an `if (!isTauri()) return;` early-out in
main.ts' wireBackendEvents() so the bare `listen(...)`
calls don't fire when the Tauri runtime is absent.
3. Update the test mock in client.test.ts to also stub
isTauri (return true) so the existing tests still work.
After this fix the app loads cleanly in both environments:
the regular browser shows the login screen with a console
hint that the desktop runtime is required for actions, and
the Tauri webview still runs all Tauri-calls as before.
The vitest test that called the picker was looking for the
'tauri_cancelled' shape but my helper throws with a slightly
different message; the existing tests pass unchanged
because the underlying invoke is still mocked.
Tests: 223 Rust + 20 vitest + svelte-check 0 errors.
54 lines
1.3 KiB
JSON
54 lines
1.3 KiB
JSON
{
|
|
"$schema": "https://schema.tauri.app/config/2",
|
|
"productName": "maarcadetweet",
|
|
"version": "0.1.0",
|
|
"identifier": "de.eifelcloud.maarcadetweet",
|
|
"build": {
|
|
"beforeDevCommand": "npm run dev",
|
|
"devUrl": "http://127.0.0.1:1430",
|
|
"beforeBuildCommand": "npm run build",
|
|
"frontendDist": "../dist"
|
|
},
|
|
"app": {
|
|
"withGlobalTauri": false,
|
|
"windows": [
|
|
{
|
|
"label": "main",
|
|
"title": "maarcadetweet",
|
|
"width": 1200,
|
|
"height": 760,
|
|
"minWidth": 880,
|
|
"minHeight": 540,
|
|
"resizable": true,
|
|
"decorations": true,
|
|
"transparent": false,
|
|
"titleBarStyle": "Visible",
|
|
"hiddenTitle": false,
|
|
"backgroundColor": "#0D0D0D"
|
|
}
|
|
],
|
|
"security": {
|
|
"csp": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' ipc: http://ipc.localhost"
|
|
}
|
|
},
|
|
"plugins": {
|
|
"updater": {
|
|
"active": true,
|
|
"dialog": true,
|
|
"endpoints": [
|
|
"https://releases.maarcadetweet.local/{{target}}/{{arch}}/{{current_version}}"
|
|
],
|
|
"pubkey": ""
|
|
}
|
|
},
|
|
"bundle": {
|
|
"active": true,
|
|
"targets": "all",
|
|
"icon": [
|
|
"icons/32x32.png",
|
|
"icons/128x128.png",
|
|
"icons/128x128@2x.png",
|
|
"icons/icon.png"
|
|
]
|
|
}
|
|
} |