Skip to content
Source
Sign inSign up
Open History to see the last commit

app-state-wakeups.ts

18 lines573 Bytes

1import type { Wakeups } from "@t3tools/client-runtime/connection";
2​
3const MOBILE_LONG_BACKGROUND_AFTER_MS = 10_000;
4​
5export type MobileApplicationActiveWakeup = Extract<
6 Wakeups.ConnectionWakeup,
7 "application-active-probe" | "application-active-long"
8>;
9​
10export function mobileApplicationActiveWakeup(
11 backgroundedAtMs: number | null,
12 activeAtMs: number,
13): MobileApplicationActiveWakeup {
14 return backgroundedAtMs !== null &&
15 activeAtMs - backgroundedAtMs >= MOBILE_LONG_BACKGROUND_AFTER_MS
16 ? "application-active-long"
17 : "application-active-probe";