# Matokeo Desktop (Electron)

This project now includes an Electron desktop wrapper so schools can use the same app interface as the web version.

## 1) App URL Configuration

By default, Electron loads the hosted app URL:

`https://school.netfastatz.co.tz`

If you are developing locally, make sure your local server is running (for example Apache/XAMPP with this project in `htdocs/results`) and override the default URL as explained below.

## 2) Launch desktop app

```bash
npm run electron
```

## Optional: use a different app URL

PowerShell:

```powershell
$env:ELECTRON_APP_URL = "http://127.0.0.1:8000"
npm run electron
```

CMD:

```cmd
set ELECTRON_APP_URL=http://127.0.0.1:8000
npm run electron
```

## Build installable `.exe` (Windows)

Create unpacked app (quick test):

```bash
npm run electron:pack
```

Create stable Windows installer (`.exe`):

```bash
npm run electron:dist
```

Create beta channel installer:

```bash
npm run electron:dist:beta
```

Create alpha channel installer:

```bash
npm run electron:dist:alpha
```

Output files are generated in:

`dist-electron/`

Installer file naming is channel-aware:

`Matokeo Results-Setup-<version>-<channel>.exe`

## App icon (`.ico`)

Icon generation is automated before packaging:

```bash
npm run electron:icon
```

Generated icon path:

`build/icons/icon.ico`

## Notes

- The desktop app is a secure wrapper (`contextIsolation: true`, `sandbox: true`, `nodeIntegration: false`).
- External links are opened in the system browser.
- Installer target is NSIS (standard Windows installer flow).
- Offline mode in desktop:
  - Form submissions are queued locally when the device is offline.
  - Once connection returns, queued actions are auto-synced to the server.
  - File-upload forms are not queued and must be submitted while online.

## Auto-update groundwork

Auto-update hooks are integrated and activate in packaged builds when an update URL is provided.

Set update URL before launching packaged app:

PowerShell:

```powershell
$env:AUTO_UPDATE_URL = "https://updates.results.co.tz/matokeo/stable"
```

The app uses `electron-updater` and checks for updates from a generic provider URL.
