-
-
Save michlimlim/e0397ccd3993306b65dcdda431ffa267 to your computer and use it in GitHub Desktop.
Track time spent in app: network-efficient case tracking last active timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy_static! { | |
static ref LAST_USER_ACTION_UNIX_TIMESTAMP: AtomicI64 = AtomicI64::new(0); | |
} | |
pub fn last_active_timestamp() -> i64 { | |
LAST_USER_ACTION_UNIX_TIMESTAMP.load(Ordering::SeqCst) | |
} | |
// Call this on app start and on every user app active action, e.g. every keystroke | |
pub fn record_last_active_timestamp() { | |
LAST_USER_ACTION_UNIX_TIMESTAMP.fetch_max(Utc::now().timestamp(), Ordering::SeqCst); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment