Skip to content

Instantly share code, notes, and snippets.

@michlimlim
Created March 19, 2023 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michlimlim/e0397ccd3993306b65dcdda431ffa267 to your computer and use it in GitHub Desktop.
Save michlimlim/e0397ccd3993306b65dcdda431ffa267 to your computer and use it in GitHub Desktop.
Track time spent in app: network-efficient case tracking last active timestamp
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