# BillPe Desktop (Windows + macOS)

BillPe ships as a native desktop app via **Electron** while reusing the same Lovable React frontend and Supabase backend. The desktop shell loads the published web app (`https://billpe.co`) inside a hardened native window — no rebuild of business logic needed.

## What's included

- `electron/main.cjs` — main process (window, splash, tray, IPC, hardened security, single-instance lock, offline fallback page)
- `electron/preload.cjs` — `contextIsolation` preload exposing `window.billpe` (notifications, thermal-print placeholder, version)
- `electron/splash.html` — branded splash with BillPe logo
- `electron/offline.html` — "You're offline" reconnect screen
- `electron/assets/icon.png` — app icon (BillPe logo) used for window, tray, dock, installer, shortcut
- `electron/package.json` — electron-builder config for **Windows NSIS installer + portable .exe**, **macOS DMG (Intel x64 + Apple Silicon arm64)**
- `src/lib/desktop.ts` — typed bridge used by the web app (`isDesktopApp()`, `notifyUser()`, `thermalPrint()`, `onConnectionChange()`)

## Building installers

These commands require a local machine (electron-builder downloads platform toolchains and cannot run inside the Lovable sandbox):

```bash
cd electron
npm install
npm run dist:win   # Windows .exe (NSIS one-click installer + portable)
npm run dist:mac   # macOS .dmg for Intel + Apple Silicon
```

Output is written to `electron/release/`.

- Windows installer: `release/BillPe Setup <version>.exe` (creates Desktop + Start Menu shortcuts, one-click install)
- Windows portable: `release/BillPe <version>.exe`
- macOS Intel: `release/BillPe-<version>.dmg`
- macOS Apple Silicon: `release/BillPe-<version>-arm64.dmg`

## Architecture

- **Frontend**: existing Lovable React/Vite app — untouched
- **Backend**: existing Supabase project — untouched
- **Auth**: Supabase session is persisted in the dedicated `persist:billpe` Electron partition (survives restarts, scoped to the desktop app)
- **Security**: `contextIsolation: true`, `nodeIntegration: false`, `sandbox: true`, external links open in the system browser, navigation locked to billpe.co / lovable.app / supabase.co, permissions denied except notifications
- **Offline**: `did-fail-load` falls back to `offline.html`; the web app can also subscribe via `onConnectionChange()`
- **Notifications**: `notifyUser(title, body)` uses native OS notifications inside the desktop app and falls back to Web Notifications in the browser
- **Auto-update ready**: electron-builder NSIS + DMG targets are compatible with `electron-updater` — drop in a feed URL when you're ready
- **Future-ready**: `thermalPrint()` IPC stub is wired end-to-end; plug in `escpos` / `node-thermal-printer` / `serialport` later without touching the renderer

## Pointing the desktop app at a different URL

Set `BILLPE_URL` before launching (defaults to `https://billpe.co`):

```bash
BILLPE_URL=https://gst-easy-bill.lovable.app electron .
```