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

foreground-handoff.ts

22 lines698 Bytes

1/**
2 * Tracks app-initiated OS-surface handoffs (image picker, auth tab, share
3 * sheet). Android reports the app as backgrounded while one of these covers
4 * the activity, so background-triggered work — like a deferred app update
5 * restart — has to wait them out instead of tearing down the mid-flow runtime.
6 */
7let activeHandoffs = 0;
8​
9/** Returns an idempotent end function; call it when the handoff resolves. */
10export function beginForegroundHandoff(): () => void {
11 activeHandoffs += 1;
12 let ended = false;
13 return () => {
14 if (ended) return;
15 ended = true;
16 activeHandoffs -= 1;
17 };
19​
20export function isForegroundHandoffActive(): boolean {
21 return activeHandoffs > 0;