BigBrainParking/app/modules/bbp-notify/index.ts
Hank d0f31d5278
Some checks failed
build-apk / build (push) Has been cancelled
v0.2.3: true ticking countdown via a tiny native module (no deps)
Replaces the static status notification with a native Android chronometer that
counts DOWN to the session end — the system ticks it every second with zero app
CPU/battery, visible without opening the app.

- modules/bbp-notify: a ~50-line local Expo module using only NotificationCompat
  (setWhen + setUsesChronometer + setChronometerCountDown + ongoing). Zero
  third-party dependencies, no Firebase — fits the de-Googled ethos. Verified:
  autolinks + Kotlin compiles.
- sessionStatus.ts uses it when present, else falls back to the expo-notifications
  static expiry-time notification.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-13 21:03:53 -07:00

31 lines
1 KiB
TypeScript

import { Platform } from 'react-native';
import { requireOptionalNativeModule } from 'expo-modules-core';
interface BbpNotifyNative {
/** Post/replace an ongoing notification with a native chronometer counting down to endTimeMillis. */
showCountdown(title: string, body: string, endTimeMillis: number): Promise<void>;
/** Remove the countdown notification. */
clear(): Promise<void>;
}
// Android-only, and only present in a build that includes the native module
// (returns null in Expo Go / other platforms — callers degrade gracefully).
const native =
Platform.OS === 'android'
? (requireOptionalNativeModule('BbpNotify') as BbpNotifyNative | null)
: null;
/** True when the native ticking-countdown module is available. */
export const hasNativeCountdown = native != null;
export async function showCountdown(
title: string,
body: string,
endTimeMillis: number,
): Promise<void> {
await native?.showCountdown(title, body, endTimeMillis);
}
export async function clearCountdown(): Promise<void> {
await native?.clear();
}