Some checks failed
build-apk / build (push) Has been cancelled
Starting a session posts an ongoing notification showing the expiry time + time
remaining, so you can glance at how long you have left without opening the app.
- Default ON; toggle in Account -> Notifications ("Active-session countdown").
- Kept fresh on app open / foreground (re-posts nearest-expiring active session,
clears when none remain). Quiet channel, no banner/sound on refresh.
- Purely local (expo-notifications); no server/push.
Note: expo-notifications can't render a live per-second ticking countdown in the
background, so it shows the exact expiry time (always accurate) + remaining, and
refreshes on foreground. A true ticking chronometer would need notifee (native).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
/**
|
|
* How many minutes before a session's expiry to fire the local reminder.
|
|
* Configurable in Notifications preferences, in 5-minute increments.
|
|
*/
|
|
const KEY = 'ps_reminder_lead_minutes';
|
|
export const DEFAULT_LEAD_MINUTES = 15;
|
|
export const MIN_LEAD_MINUTES = 5;
|
|
export const MAX_LEAD_MINUTES = 60;
|
|
export const LEAD_STEP = 5;
|
|
|
|
/** When true, expiry reminders are enabled at all. */
|
|
const ENABLED_KEY = 'ps_reminder_enabled';
|
|
|
|
export async function getReminderLeadMinutes(): Promise<number> {
|
|
const raw = await AsyncStorage.getItem(KEY);
|
|
const n = raw != null ? parseInt(raw, 10) : NaN;
|
|
return Number.isFinite(n) ? n : DEFAULT_LEAD_MINUTES;
|
|
}
|
|
|
|
export async function setReminderLeadMinutes(minutes: number): Promise<void> {
|
|
const clamped = Math.min(
|
|
MAX_LEAD_MINUTES,
|
|
Math.max(MIN_LEAD_MINUTES, Math.round(minutes / LEAD_STEP) * LEAD_STEP),
|
|
);
|
|
await AsyncStorage.setItem(KEY, String(clamped));
|
|
}
|
|
|
|
export async function getRemindersEnabled(): Promise<boolean> {
|
|
const raw = await AsyncStorage.getItem(ENABLED_KEY);
|
|
return raw == null ? true : raw === 'true';
|
|
}
|
|
|
|
export async function setRemindersEnabled(on: boolean): Promise<void> {
|
|
await AsyncStorage.setItem(ENABLED_KEY, String(on));
|
|
}
|
|
|
|
/**
|
|
* When true, an ongoing "time left" status notification is shown while a
|
|
* parking session is active, so you can glance at remaining time without
|
|
* opening the app. Default ON.
|
|
*/
|
|
const COUNTDOWN_KEY = 'ps_session_countdown_enabled';
|
|
|
|
export async function getCountdownEnabled(): Promise<boolean> {
|
|
const raw = await AsyncStorage.getItem(COUNTDOWN_KEY);
|
|
return raw == null ? true : raw === 'true';
|
|
}
|
|
|
|
export async function setCountdownEnabled(on: boolean): Promise<void> {
|
|
await AsyncStorage.setItem(COUNTDOWN_KEY, String(on));
|
|
}
|