Skip to content

Commit

Permalink
release of 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jul 23, 2023
1 parent c77952e commit a84e798
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2

* (macOS) Fixed an issue where sessions could span multiple days if the app was left open overnight

## 0.3.1

* Wait for event to be flushed on panic
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tauri-plugin-aptabase"
version = "0.3.1"
version = "0.3.2"
license = "MIT"
description = "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps"
authors = [ "Guilherme Oenning" ]
Expand Down
14 changes: 7 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use log::debug;
use reqwest::header::{HeaderMap, HeaderValue};
use serde_json::{json, Value};
use std::{sync::Mutex, time::Duration, time::Instant};
use std::{sync::Mutex, time::Duration};
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use uuid::Uuid;

Expand All @@ -16,14 +16,14 @@ static HTTP_REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
#[derive(Debug, Clone)]
pub struct TrackingSession {
pub id: String,
pub last_touch_ts: Instant,
pub last_touch_ts: OffsetDateTime,
}

impl TrackingSession {
fn new() -> Self {
TrackingSession {
id: Uuid::new_v4().to_string(),
last_touch_ts: Instant::now(),
last_touch_ts: OffsetDateTime::now_utc(),
}
}
}
Expand Down Expand Up @@ -66,11 +66,11 @@ impl AptabaseClient {
pub(crate) fn eval_session_id(&self) -> String {
let mut session = self.session.lock().expect("could not lock session");

// session timeout since last touched, start a new one!
if session.last_touch_ts.elapsed() > SESSION_TIMEOUT {
*session = TrackingSession::new()
let now = OffsetDateTime::now_utc();
if (now - session.last_touch_ts) > SESSION_TIMEOUT {
*session = TrackingSession::new();
} else {
session.last_touch_ts = Instant::now()
session.last_touch_ts = now;
}
return session.id.clone();
}
Expand Down

0 comments on commit a84e798

Please sign in to comment.