[ui] PlanetGarden: Bring main (four versions through Tauri) into the branch; the app check passes the gardener and opens the ring
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* The content-security policy, one string for all four versions (CLAUDE.md §2, *Four versions*).
|
||||
* The PWA carries it in a <meta> tag, because GitHub Pages cannot send headers (CLAUDE.md §8).
|
||||
* The Tauri shell delivers it from `apps/rosea-tauri/src-tauri/tauri.conf.json`
|
||||
* (`app.security.csp`), and the shell's test holds that string equal to this one
|
||||
* (tauri-platforms.md D4).
|
||||
*
|
||||
* `'self'` everywhere and nothing else: no CDN, no font host, no analytics (CLAUDE.md §4).
|
||||
* `frame-ancestors` is ignored in a meta tag and is omitted rather than pretended.
|
||||
*/
|
||||
export const CSP = [
|
||||
"default-src 'self'",
|
||||
"script-src 'self'",
|
||||
"style-src 'self'",
|
||||
"img-src 'self' data:",
|
||||
"font-src 'self'",
|
||||
"connect-src 'self'",
|
||||
"manifest-src 'self'",
|
||||
"worker-src 'self'",
|
||||
"object-src 'none'",
|
||||
"base-uri 'self'",
|
||||
"form-action 'none'"
|
||||
].join('; ');
|
||||
@@ -7,6 +7,8 @@
|
||||
"scripts": {
|
||||
"dev": "vite --host 127.0.0.1 --port 5173 --strictPort",
|
||||
"build": "tsx ../../scripts/validate-library.ts && vite build",
|
||||
"build:shell": "tsx ../../scripts/validate-library.ts && vite build --mode tauri",
|
||||
"dev:shell": "vite --mode tauri --host 127.0.0.1 --port 5173 --strictPort",
|
||||
"typecheck": "svelte-check --threshold error --output human"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -59,8 +59,14 @@
|
||||
persisted: async () => (browserStorage?.persisted ? browserStorage.persisted() : null),
|
||||
persist: async () => (browserStorage?.persist ? browserStorage.persist() : null)
|
||||
};
|
||||
// The Android, iOS and desktop apps are installed by being apps (tauri-platforms.md D9):
|
||||
// they ask to keep the garden after the first care, as an installed PWA does, and never
|
||||
// show the hint to add the page to the home screen.
|
||||
const inApp = __ROSEA_SHELL__ === 'tauri';
|
||||
const installed = (): boolean =>
|
||||
matchMedia('(display-mode: standalone)').matches || (navigator as Navigator & { standalone?: boolean }).standalone === true;
|
||||
inApp ||
|
||||
matchMedia('(display-mode: standalone)').matches ||
|
||||
(navigator as Navigator & { standalone?: boolean }).standalone === true;
|
||||
// An installed app is asked once, after the first care of a visit: by then there is
|
||||
// something to lose, and installed apps are not met with a permission prompt (K5).
|
||||
let askedToKeep = false;
|
||||
@@ -82,7 +88,8 @@
|
||||
|
||||
// --- A new version waiting (calm-refresh.md) ----------------------------
|
||||
// The worker is registered here so the page hears when a new version has installed
|
||||
// and waits. It is offered, never swapped in by itself (U2).
|
||||
// and waits. It is offered, never swapped in by itself (U2). In the apps there is no
|
||||
// worker: this registerSW does nothing, and a new version comes as a new app.
|
||||
let updateReady = $state(false);
|
||||
const updateSW = registerSW({
|
||||
onNeedRefresh: () => (updateReady = true),
|
||||
|
||||
Vendored
+6
@@ -2,6 +2,12 @@
|
||||
/// <reference types="vite/client" />
|
||||
/// <reference types="vite-plugin-pwa/client" />
|
||||
|
||||
/**
|
||||
* Which shell the game was built for (vite.config.ts): `'web'` for the PWA, `'tauri'` for the
|
||||
* Android, iOS and desktop apps. Read in App.svelte only, for wiring (CLAUDE.md §2).
|
||||
*/
|
||||
declare const __ROSEA_SHELL__: 'web' | 'tauri';
|
||||
|
||||
declare module 'virtual:rosea-library' {
|
||||
import type { HopeSentence } from '@rosea/schema';
|
||||
/** The verified hope library, bundled at build time after validate:library passed (day-sentence.md P5). */
|
||||
|
||||
+89
-82
@@ -9,6 +9,18 @@ import { VitePWA } from 'vite-plugin-pwa';
|
||||
// load a workspace package's .ts source, so `vite build` and `svelte-check` both
|
||||
// failed to load this file. The constants module is pure and dependency-free.
|
||||
import { PRODUCT_NAME, PRODUCT_SHORT_NAME } from '../../packages/schema/src/constants.js';
|
||||
import { CSP } from './csp.js';
|
||||
|
||||
/**
|
||||
* Two builds of one game (CLAUDE.md §2, *Four versions*; tauri-platforms.md D2).
|
||||
* - the PWA (default mode): base `/Rosea/`, a service worker, the web manifest, the CSP
|
||||
* in a <meta> tag, into `dist/`;
|
||||
* - the Tauri shell's copy (`--mode tauri`): base `/`, because Tauri serves the game at the
|
||||
* root of its own origin; no worker and no manifest, because the files are already on
|
||||
* the device; no <meta> CSP, because Tauri delivers the same policy and a page that
|
||||
* carries both obeys both; into `dist-tauri/`, so the two can never be mixed up.
|
||||
*/
|
||||
type Shell = 'web' | 'tauri';
|
||||
|
||||
/**
|
||||
* GitHub Pages serves a project site at `/<repo>/`, not `/` (CLAUDE.md §8). Vite
|
||||
@@ -16,45 +28,30 @@ import { PRODUCT_NAME, PRODUCT_SHORT_NAME } from '../../packages/schema/src/cons
|
||||
* derive from this one value, so they cannot disagree. The e2e and offline
|
||||
* suites serve the build under the same prefix.
|
||||
*/
|
||||
const BASE = process.env['ROSEA_BASE'] ?? '/Rosea/';
|
||||
if (!BASE.startsWith('/') || !BASE.endsWith('/')) {
|
||||
throw new Error(`ROSEA_BASE must start and end with '/', got '${BASE}'`);
|
||||
function baseFor(shell: Shell): string {
|
||||
const base = process.env['ROSEA_BASE'] ?? (shell === 'tauri' ? '/' : '/Rosea/');
|
||||
if (!base.startsWith('/') || !base.endsWith('/')) {
|
||||
throw new Error(`ROSEA_BASE must start and end with '/', got '${base}'`);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content-security policy. GitHub Pages cannot send headers, so it lives in
|
||||
* a <meta> tag (CLAUDE.md §8). It is injected into the BUILT page only, because
|
||||
* the dev server injects inline <style> for hot reload and `style-src 'self'`
|
||||
* The content-security policy (`csp.ts`). GitHub Pages cannot send headers, so the PWA
|
||||
* carries it in a <meta> tag (CLAUDE.md §8). It is injected into the BUILT page only,
|
||||
* because the dev server injects inline <style> for hot reload and `style-src 'self'`
|
||||
* would blank it. E2E runs against the build, where the policy is real.
|
||||
*
|
||||
* `'self'` everywhere and nothing else: no CDN, no font host, no analytics
|
||||
* (CLAUDE.md §4). `frame-ancestors` is ignored in a meta tag and is omitted
|
||||
* rather than pretended.
|
||||
*/
|
||||
const CSP = [
|
||||
"default-src 'self'",
|
||||
"script-src 'self'",
|
||||
"style-src 'self'",
|
||||
"img-src 'self' data:",
|
||||
"font-src 'self'",
|
||||
"connect-src 'self'",
|
||||
"manifest-src 'self'",
|
||||
"worker-src 'self'",
|
||||
"object-src 'none'",
|
||||
"base-uri 'self'",
|
||||
"form-action 'none'"
|
||||
].join('; ');
|
||||
|
||||
function contentSecurityPolicy(): Plugin {
|
||||
return {
|
||||
name: 'rosea-csp',
|
||||
apply: 'build',
|
||||
transformIndexHtml: {
|
||||
order: 'post',
|
||||
handler: () => [
|
||||
{ tag: 'meta', attrs: { 'http-equiv': 'Content-Security-Policy', content: CSP }, injectTo: 'head-prepend' }
|
||||
]
|
||||
}
|
||||
name: 'rosea-csp',
|
||||
apply: 'build',
|
||||
transformIndexHtml: {
|
||||
order: 'post',
|
||||
handler: () => [
|
||||
{ tag: 'meta', attrs: { 'http-equiv': 'Content-Security-Policy', content: CSP }, injectTo: 'head-prepend' }
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,54 +86,64 @@ function hopeLibrary(): Plugin {
|
||||
}
|
||||
|
||||
// Nothing binds to anything but 127.0.0.1 (CLAUDE.md §5.7).
|
||||
export default defineConfig({
|
||||
base: BASE,
|
||||
plugins: [
|
||||
svelte(),
|
||||
contentSecurityPolicy(),
|
||||
hopeLibrary(),
|
||||
VitePWA({
|
||||
strategies: 'generateSW',
|
||||
// Never swap a running app silently. A new worker waits until the player
|
||||
// is offered a calm refresh control (CLAUDE.md §8, GAP_ANALYSIS G0.10).
|
||||
registerType: 'prompt',
|
||||
// The app registers the worker itself through virtual:pwa-register, so it hears
|
||||
// when a new version is waiting (calm-refresh.md U1). Bundled, not inline: the
|
||||
// CSP has no 'unsafe-inline' for scripts.
|
||||
injectRegister: false,
|
||||
manifest: {
|
||||
// The web manifest: one of the three places the name lives, built from
|
||||
// the constants in @rosea/schema so the strings exist only there.
|
||||
name: PRODUCT_NAME,
|
||||
short_name: PRODUCT_SHORT_NAME,
|
||||
description: 'A rose to tend, a fox to befriend, and the time we give to people.',
|
||||
id: BASE,
|
||||
start_url: BASE,
|
||||
scope: BASE,
|
||||
display: 'standalone',
|
||||
orientation: 'portrait',
|
||||
background_color: '#fbf6f1',
|
||||
theme_color: '#b4485e',
|
||||
icons: [{ src: 'icon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any' }]
|
||||
},
|
||||
workbox: {
|
||||
// The cache name never contains the build hash; Workbox invalidates
|
||||
// per entry from the precache manifest's revisions.
|
||||
cacheId: 'rosea',
|
||||
globPatterns: ['**/*.{js,css,html,svg,webmanifest}'],
|
||||
navigateFallback: 'index.html',
|
||||
// No runtime caching: the app makes no request it was not asked to make.
|
||||
runtimeCaching: [],
|
||||
cleanupOutdatedCaches: true,
|
||||
// The first worker controls the page that registered it, so a player who
|
||||
// opens the link once and loses signal still has the app.
|
||||
clientsClaim: true,
|
||||
skipWaiting: false
|
||||
},
|
||||
devOptions: { enabled: false }
|
||||
})
|
||||
],
|
||||
server: { host: '127.0.0.1', strictPort: true },
|
||||
preview: { host: '127.0.0.1', strictPort: true },
|
||||
build: { target: 'es2022', sourcemap: true }
|
||||
export default defineConfig(({ mode }) => {
|
||||
const shell: Shell = mode === 'tauri' ? 'tauri' : 'web';
|
||||
const BASE = baseFor(shell);
|
||||
return {
|
||||
base: BASE,
|
||||
// The one way the game knows which shell it is in, read in App.svelte only (CLAUDE.md §2).
|
||||
define: { __ROSEA_SHELL__: JSON.stringify(shell) },
|
||||
plugins: [
|
||||
svelte(),
|
||||
...(shell === 'web' ? [contentSecurityPolicy()] : []),
|
||||
hopeLibrary(),
|
||||
VitePWA({
|
||||
// Off in the shell: `virtual:pwa-register` then gives a registerSW that does nothing,
|
||||
// and no worker, manifest or register script is emitted (tauri-platforms.md D2).
|
||||
disable: shell === 'tauri',
|
||||
strategies: 'generateSW',
|
||||
// Never swap a running app silently. A new worker waits until the player
|
||||
// is offered a calm refresh control (CLAUDE.md §8, GAP_ANALYSIS G0.10).
|
||||
registerType: 'prompt',
|
||||
// The app registers the worker itself through virtual:pwa-register, so it hears
|
||||
// when a new version is waiting (calm-refresh.md U1). Bundled, not inline: the
|
||||
// CSP has no 'unsafe-inline' for scripts.
|
||||
injectRegister: false,
|
||||
manifest: {
|
||||
// The web manifest: one of the three places the name lives, built from
|
||||
// the constants in @rosea/schema so the strings exist only there.
|
||||
name: PRODUCT_NAME,
|
||||
short_name: PRODUCT_SHORT_NAME,
|
||||
description: 'A rose to tend, a fox to befriend, and the time we give to people.',
|
||||
id: BASE,
|
||||
start_url: BASE,
|
||||
scope: BASE,
|
||||
display: 'standalone',
|
||||
orientation: 'portrait',
|
||||
background_color: '#fbf6f1',
|
||||
theme_color: '#b4485e',
|
||||
icons: [{ src: 'icon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any' }]
|
||||
},
|
||||
workbox: {
|
||||
// The cache name never contains the build hash; Workbox invalidates
|
||||
// per entry from the precache manifest's revisions.
|
||||
cacheId: 'rosea',
|
||||
globPatterns: ['**/*.{js,css,html,svg,webmanifest}'],
|
||||
navigateFallback: 'index.html',
|
||||
// No runtime caching: the app makes no request it was not asked to make.
|
||||
runtimeCaching: [],
|
||||
cleanupOutdatedCaches: true,
|
||||
// The first worker controls the page that registered it, so a player who
|
||||
// opens the link once and loses signal still has the app.
|
||||
clientsClaim: true,
|
||||
skipWaiting: false
|
||||
},
|
||||
devOptions: { enabled: false }
|
||||
})
|
||||
],
|
||||
server: { host: '127.0.0.1', strictPort: true },
|
||||
preview: { host: '127.0.0.1', strictPort: true },
|
||||
// The shell's copy has no source maps: they would ship inside every installer and APK.
|
||||
build: { target: 'es2022', sourcemap: shell === 'web', outDir: shell === 'tauri' ? 'dist-tauri' : 'dist' }
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user