Skip to content

Commit a36218a

Browse files
committed
Use new session id format
1 parent 02540b8 commit a36218a

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.2
2+
3+
* Use new session id format
4+
15
## 0.4.1
26

37
* Automatic flush of events on app exit

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tauri-plugin-aptabase"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
license = "MIT"
55
description = "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps"
66
authors = [ "Guilherme Oenning" ]
@@ -21,4 +21,5 @@ reqwest = { version = "0.11", features = ["json"] }
2121
time = { version = "0.3", features = ["formatting"]}
2222
os_info = "3"
2323
uuid = "1"
24+
rand = "0.8"
2425
log = "0.4"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aptabase/tauri",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"private": false,
55
"description": "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
66
"author": "Guilherme Oenning",

src/client.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
use rand::Rng;
13
use serde_json::{json, Value};
24
use std::{sync::{Arc, Mutex as SyncMutex}, time::Duration};
35
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
4-
use uuid::Uuid;
56

67
use crate::{
78
config::Config,
@@ -10,6 +11,20 @@ use crate::{
1011

1112
static SESSION_TIMEOUT: Duration = Duration::from_secs(4 * 60 * 60);
1213

14+
fn new_session_id() -> String {
15+
let epoch_in_seconds = SystemTime::now()
16+
.duration_since(UNIX_EPOCH)
17+
.expect("time went backwards")
18+
.as_secs();
19+
20+
let mut rng = rand::thread_rng();
21+
let random: u64 = rng.gen_range(0..=99999999);
22+
23+
let id = epoch_in_seconds * 100_000_000 + random;
24+
25+
return id.to_string();
26+
}
27+
1328
/// A tracking session.
1429
#[derive(Debug, Clone)]
1530
pub struct TrackingSession {
@@ -20,7 +35,7 @@ pub struct TrackingSession {
2035
impl TrackingSession {
2136
fn new() -> Self {
2237
TrackingSession {
23-
id: Uuid::new_v4().to_string(),
38+
id: new_session_id(),
2439
last_touch_ts: OffsetDateTime::now_utc(),
2540
}
2641
}
@@ -52,7 +67,7 @@ impl AptabaseClient {
5267
sys_info,
5368
}
5469
}
55-
70+
5671
/// Starts the event dispatcher loop.
5772
pub(crate) fn start_polling(&self, interval: Duration) {
5873
let dispatcher = self.dispatcher.clone();

0 commit comments

Comments
 (0)