# Grestapp — Mobile (React Native)

Android-first WebView shell over [grest.in](https://grest.in) that adds:

- Stable device ID + brand / model / OS / app version captured at first launch
- Coarse location (Android runtime permission)
- FCM push notifications (foreground, background, killed-state)
- A `window.GrestApp` JS bridge the storefront site can call to bind a
  Shopify customer ID / email to this device for targeted notifications

It talks to the backend at `https://grstapi.winds-os.com`.

## Build (Android)

```bash
# 1. Initialize the React Native CLI scaffold (one-time)
#    This creates android/ + ios/ folders and bundles the gradle wrapper.
npx @react-native-community/cli init GrestApp --version 0.74.0 --skip-install
mv GrestApp/android ./android
mv GrestApp/ios ./ios
mv GrestApp/.bundle ./.bundle 2>/dev/null || true
rm -rf GrestApp

# 2. Install deps from this folder
npm install --legacy-peer-deps

# 3. Drop the Firebase config
#    Place google-services.json into android/app/google-services.json
#    (Get it from Firebase Console → Project settings → Your Android app)

# 4. Edit src/config.ts — set API_MOBILE_KEY to the value of API_MOBILE_KEY from
#    the server's .env file.

# 5. Run on device / emulator
npm run android

# 6. Release APK
npm run build:android
# → android/app/build/outputs/apk/release/app-release.apk
```

## Required Android permissions

`android/app/src/main/AndroidManifest.xml` must declare:

```xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
```

And `android/app/build.gradle` needs the Firebase plugin:

```gradle
apply plugin: 'com.google.gms.google-services'
```

with `classpath 'com.google.gms:google-services:4.4.2'` in `android/build.gradle`.

## Bridge usage from grest.in

```js
// Read context (deviceId, location, fcmToken, etc.)
const ctx = window.GrestApp?.getContext?.();

// After login on the storefront, bind the customer:
window.GrestApp?.setCustomerId?.(customerId);
window.GrestApp?.setEmail?.(email);
```
