1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! App lifecycle: foreground or background, as the single fact the gate reads.
//!
//! The platform reports real visibility transitions (Android
//! `resumed`/`suspended`, a desktop window hidden or occluded, the web's
//! `visibilitychange`), and a game that is not on screen must stop playing and
//! go quiet. Every game in the portal family carries the same pair of
//! functions for this, plus the same static flag behind them; this is that
//! pair, once.
//!
//! [`watch`] is idempotent, and it reads the state the app is already in before
//! it subscribes, because the platform only reports *changes*: a game that
//! boots straight into the background (an Android reopen, a hidden tab) would
//! otherwise read as foreground until the player came back and left again.
use Once;
use ;
use AppLifecycle;
/// Foreground until the platform says otherwise, and on every platform that
/// never reports a lifecycle at all.
static FOREGROUND: AtomicBool = new;
static WATCH: Once = new;
/// Subscribe to the app's lifecycle. Idempotent: calling it twice installs one
/// listener, so a game may call it at boot and anything else may call it again.
/// Whether the app is in the foreground.
///
/// `true` before [`watch`] runs and wherever no platform lifecycle exists, so a
/// game that never watches runs as it always did.
/// Whether the app is in the background: the value the gate takes for
/// [`PortalView::backgrounded`](super::PortalView::backgrounded).