3.3 KiB
3.3 KiB
| name | description |
|---|---|
| macos-selfcontained-webapp | Build or refactor a project so a web app runs as a self-contained macOS app: embedded local backend binary + SwiftUI/WKWebView shell + packaging scripts. Use when a user has web logic and wants no external browser, no separate web-code install, local execution from inside .app, and repeatable DMG packaging. |
macOS Self-Contained Web App
Outcome
Deliver one installable macOS app that:
- launches an embedded backend executable from app resources
- opens the web UI only inside
WKWebView - persists settings locally and supports native-to-web sync
- can be packaged as a DMG
Layout Standard
Use this layout for new projects:
web/for web backend source (app.py, modules, requirements)mac/<AppName>Mac/for Xcode project and SwiftUI shellscripts/for build and packaging automationdocs/for architecture and onboarding docs
For existing repos, avoid destructive renames unless explicitly requested. Add compatibility paths or migration commits in small steps.
Detailed naming guidance: references/layout-and-naming.md
Workflow
- Inventory existing architecture.
- Identify backend entrypoint, runtime dependencies, and static/resource files.
- Confirm current launch mode and where browser auto-open is happening.
- Create embedded backend launcher.
- Add a thin launcher (
backend_embedded_launcher.pyor equivalent) that starts the web server on127.0.0.1and reads port from env (for exampleMANESH_TRADER_PORT). - Ensure browser auto-open is disabled.
- Build backend into a single executable.
- Add
scripts/build_embedded_backend.shthat compiles backend into a one-file executable and copies it into the mac target resource folder. - Include all required web files/modules in build inputs.
- Implement SwiftUI host shell.
- Use
@Observablehost state (noObservableObject/Combine). - Start/stop backend process, detect available local port, and handle retries.
- Render URL in
WKWebViewonly. - Keep app responsive when backend fails and surface actionable status.
- Define settings sync contract.
- Use shared settings file (for example
~/.<app>/settings.json) as source of truth. - Normalize settings both in web app and native app.
- Pass effective settings via URL query params on launch/reload/restart.
- Keep onboarding limited to starter fields; preserve advanced fields.
- Automate packaging.
- Add
scripts/build_selfcontained_mac_app.shto build embedded backend then Xcode app. - Add
scripts/create_installer_dmg.shfor distributable DMG.
- Validate.
- Python syntax:
python -m py_compileon web entrypoint. - Xcode build:
xcodebuild ... build. - Runtime check: no external browser opens, webview loads locally, settings persist across relaunch.
Required Deliverables
- Embedded backend build script
- macOS app host that launches backend + WKWebView
- Shared settings sync path
- README section for local build + DMG workflow
- Verified build commands and final artifact locations
References
- Layout and migration rules:
references/layout-and-naming.md - Implementation blueprint and command templates:
references/implementation-blueprint.md
Bundled Script
Use scripts/scaffold_web_mac_layout.sh to create a new standardized folder skeleton for fresh projects.