# WireGuard React Native VPN App - Project Progress

This document tracks the implementation progress for the React Native Android WireGuard VPN app in this repository.

## 1. Project Planning & Research
- Investigated `react-native-wireguard-vpn-connect` and `rn-wireguard-tunnel` as suitable bridge libraries to interface between JavaScript and the Android `VpnService`. 
- Selected `react-native-wireguard-vpn-connect` as the cornerstone for the integration since it supports React Native >= 0.72 and provides a robust native bridging interface.
- Developed a comprehensive **Implementation Plan** and **Task Checklist**, covering:
  - Tunnel connectivity and configuration parsing.
  - A dark-mode UI with an active tunnel status switch and detailed connection logs.
- Expanded the requirements seamlessly to include **Split Tunneling**, allowing users to individually include or exclude specific apps from routing through the VPN.

## 2. Project Scaffolding
- Succeeded in setting up a clean React Native (TypeScript) workspace using `@react-native-community/cli` resulting in `WgReact` directory initialization.
- Installed structural and routing npm libraries:
  - React Navigation (`@react-navigation/native`, `@react-navigation/native-stack`, `react-native-screens`, `react-native-safe-area-context`) to support the multi-screen topology (Home vs. Settings Screen).
  - Storage tools (`@react-native-async-storage/async-storage`) to locally persist the user's split tunnel configurations.

## 3. Native Android Development (Kotlin Modules)
Implemented and completed the native bridge wiring for VPN control and split-tunnel app discovery:

### `SplitTunnelModule.kt` & `SplitTunnelPackage.kt`
- Implemented `getInstalledApps` returning all user-installed device applications via the Android `PackageManager` (filtering out internal, un-updated system ones). 
- It efficiently serializes `appName`, `packageName`, and the app `icon` (into a `Base64` payload) to the TypeScript boundary.

### `WireGuardModule.kt` & `WireGuardPackage.kt`
- Upgraded from stubs to an Activity-aware module with full permission flow:
  - `initialize()` registers status receiver and emits init event.
  - `connect(config, splitApps, splitMode)` requests `VpnService` permission when needed and starts the VPN service after permission is granted.
  - `disconnect()` signals the VPN service to stop cleanly.
  - `getStatus()` returns current connection state and endpoint host.
  - `requestIgnoreBatteryOptimizations()` opens Android battery exemption prompt.
- Added event emission to JS:
  - `WireGuardEvent` for logs.
  - `VPN_STATUS_CHANGE` for tunnel status updates.
- Registered both custom packages in `MainApplication.kt`:
  - `add(WireGuardPackage())`
  - `add(SplitTunnelPackage())`

### `WireGuardVpnService.kt` (New)
- Added a foreground `VpnService` that:
  - Accepts config and split-tunnel extras from `WireGuardModule` intents.
  - Configures `Builder` addresses/routes/DNS from parsed `.conf` data.
  - Applies split tunneling via `addDisallowedApplication(...)` (exclude mode) or `addAllowedApplication(...)` (include mode).
  - Publishes status broadcasts consumed by `WireGuardModule`.
  - Maintains a foreground notification while active.

## 4. React Native App Implementation (TypeScript)
- Replaced template `App.tsx` with app navigation entrypoint.
- Added complete app structure under `src/`:
  - `src/navigation/AppNavigator.tsx`: Home + Settings stack navigation.
  - `src/screens/HomeScreen.tsx`: tunnel state, connect/disconnect switch, sync button, battery optimization button, live logs.
  - `src/screens/SettingsScreen.tsx`: split-tunnel mode selection (include/exclude), installed app list, search, and persistence.
  - `src/services/wireguardConfig.ts`: HTTPS fetch from `https://wgcf.ordak.dpdns.org` and `.conf` parser to bridge-compatible object.
  - `src/services/splitTunnelStorage.ts`: AsyncStorage-backed split tunnel settings.
  - `src/native/wireguardNative.ts`: typed JS wrapper over native modules/events.
  - `src/types/wireguard.ts`: shared app/native data types.

## 5. Android Manifest & Permissions
- Updated `AndroidManifest.xml` with required permissions and service declaration:
  - `INTERNET`
  - `FOREGROUND_SERVICE`
  - `FOREGROUND_SERVICE_SPECIAL_USE`
  - `REQUEST_IGNORE_BATTERY_OPTIMIZATIONS`
- Added `WireGuardVpnService` entry with:
  - `android:permission="android.permission.BIND_VPN_SERVICE"`
  - `android:foregroundServiceType="specialUse"`
  - `android.net.VpnService` intent-filter.

## 6. Validation & Test Updates
- Lint: `npm run lint` passed.
- Type check: `npx tsc --noEmit` passed.
- Tests: updated `__tests__/App.test.tsx` to validate parser logic; `npm test -- --watch=false --runInBand` passed.
- Jest config updated to transform React Navigation packages used by RN runtime.

## Current Status
- The app now has end-to-end UI + native wiring for Android VPN session lifecycle, config syncing/parsing, logging, and split-tunneling settings.
- Remaining advanced step: integrate a full WireGuard backend implementation (userspace/kernel handshake and crypto) if production-grade tunnel transport behavior is required beyond current `VpnService.Builder` routing/session scaffolding.
