@softr/sdk
pwa
>-
Installing the app
The builder turns installing on in Studio, under Settings → Mobile app, and sets the name, colour and icon there. The app already answers with its manifest and icon once they do. What the app adds is two things: the links that point the browser at them, and a button that tells visitors how to install.
CRITICAL: Never write a web app manifest, icon files, a service worker, or manifest / apple-touch-icon / apple-touch-startup-image links or an apple-mobile-web-app-title meta of your own, in public/ or in head(). The app already serves them from Studio's settings, and a file or tag of your own shadows those settings.
CRITICAL: Render an install button only while usePwaInstall() returns available: true. Never show it unconditionally, never cache the answer, never replace the check with your own. Softr can switch installing off for an app, and this check is the only way that reaches the button.
Setup
import { SoftrPwaHead, usePwaInstall } from '@softr/sdk'
import type { PwaInstall, PwaPlatform } from '@softr/sdk'type PwaPlatform = 'ios' | 'android' | 'desktop'
type PwaInstall =
| { available: false }
| {
available: true
platform: PwaPlatform // which steps install the app on this device
name: string // what the home screen will show
iconUrl: string // the icon the home screen will show
}Is the app installable?
The builder switches installing on in Studio, and usePwaInstall() reads that switch at runtime. To check it before writing any code, ask the running app for /_softr/pwa.json: 200 means installable, 404 means installing is off or there is no icon yet. Do not build an install button against a 404: installing has to be turned on first. A change in Studio can take up to two minutes to reach the app.
Core Patterns
The links: <SoftrPwaHead />
Render it once, in <head> next to <HeadContent />, in RootDocument in src/routes/__root.tsx. While the app is installable it also renders the name iOS puts under the home screen icon and the iOS launch screens, so an installed app opens on its own splash screen instead of white.
function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<HeadContent />
<SoftrPwaHead />
</head>
<body>
{children}
<Scripts />
</body>
</html>
)
}Whether to show a button: usePwaInstall()
It fetches after mount, so the first render, the server render included, always says available: false. It stays unavailable when the app is not installable, when the request fails, and when the app already runs installed from the home screen. Inside the Studio preview it says available, so the builder can see the button; installing itself only works on the published app.
There is no install() to call. No browser opens its install dialog for this app on request, so the button opens steps for platform instead: Share, then Add to Home Screen on iOS; the browser menu's Install app on Android and desktop. name and iconUrl tell the visitor what they are adding.
References
- SKILL.md: the entrypoints and which one each export lives on