| 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 | */ |
| 7 | let activeHandoffs = 0; |
| 8 | |
| 9 | /** Returns an idempotent end function; call it when the handoff resolves. */ |
| 10 | export function beginForegroundHandoff(): () => void { |
| 11 | activeHandoffs += 1; |
| 12 | let ended = false; |
| 13 | return () => { |
| 14 | if (ended) return; |
| 15 | ended = true; |
| 16 | activeHandoffs -= 1; |
| 17 | }; |
| 18 | } |
| 19 | |
| 20 | export function isForegroundHandoffActive(): boolean { |
| 21 | return activeHandoffs > 0; |
| 22 | } |