Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tauri-plugin-aptabase"
version = "0.5.1"
license = "MIT"
description = "Tauri Plugin for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps"
authors = [ "Guilherme Oenning" ]
authors = ["Guilherme Oenning"]
edition = "2021"
rust-version = "1.70"
readme = "README.md"
Expand All @@ -12,19 +12,16 @@ exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"]
links = "tauri-plugin-aptabase"

[dependencies]
tauri = { version = "2.0.0-beta.2" }
tauri = "2.1"
tokio = "1"
futures = "0"
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
reqwest = { version = "0.11", features = ["json"] }
time = { version = "0.3", features = ["formatting"]}
serde = "1"
serde_json = "1"
reqwest = { version = "0.12", features = ["json"] }
time = { version = "0.3", features = ["formatting"] }
os_info = "3"
uuid = "1"
rand = "0.8"
log = "0.4"
sys-locale = "0.3.1"
sys-locale = "0.3"

[build-dependencies]
tauri-plugin = { version = "2.0.0-beta.1", features = ["build"] }
tauri-plugin = { version = "2.0", features = ["build"] }
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const COMMANDS: &[&str] = &["track_event"];

fn main() {
tauri_plugin::Builder::new(COMMANDS).build();
tauri_plugin::Builder::new(COMMANDS).build();
}
6 changes: 3 additions & 3 deletions examples/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2.0.0-alpha.11",
"@tauri-apps/api": "^2.1.1",
"@aptabase/tauri": "file:../../"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"internal-ip": "^7.0.0",
"svelte": "^3.49.0",
"vite": "^3.0.2",
"@tauri-apps/cli": "^2.0.0-alpha.17"
"@tauri-apps/cli": "^2.1.0"
}
}
}
6 changes: 3 additions & 3 deletions examples/helloworld/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ crate-type = ["staticlib", "cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "2.0.0-beta.1", default-features = false , features = [] }
tauri-build = { version = "2.0", default-features = false, features = [] }

[dependencies]
tauri = { version = "2.0.0-beta.2", features = [] }
tauri = { version = "2.1", features = [] }
tauri-plugin-aptabase = { path = "../../../" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

[features]
# this feature is used for production builds or when `devUrl` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = [ "tauri/custom-protocol" ]
custom-protocol = ["tauri/custom-protocol"]
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"package.json"
],
"devDependencies": {
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "11.1.6",
"@rollup/plugin-terser": "0.4.4",
"rollup": "4.9.6",
"typescript": "5.3.3"
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-typescript": "^12.1.1",
"@rollup/plugin-terser": "^0.4.4",
"rollup": "^4.27.4",
"typescript": "^5.7.2"
},
"dependencies": {
"@tauri-apps/api": "^2.0.0-alpha.11",
"tslib": "^2.6.2"
"@tauri-apps/api": "^2.1.1",
"tslib": "^2.8.1"
}
}
32 changes: 29 additions & 3 deletions permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
# Permissions

## allow-track-event
## Permission Table

<table>
<tr>
<th>Identifier</th>
<th>Description</th>
</tr>


<tr>
<td>

`aptabase:allow-track-event`

</td>
<td>

Enables the track_event command without any pre-configured scope.

## deny-track-event
</td>
</tr>

<tr>
<td>

`aptabase:deny-track-event`

</td>
<td>

Denies the track_event command without any pre-configured scope.

</td>
</tr>
</table>
68 changes: 56 additions & 12 deletions permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"set": {
"description": "A list of permissions sets defined",
"default": [],
"type": "array",
"items": {
"$ref": "#/definitions/PermissionSet"
Expand Down Expand Up @@ -50,7 +49,7 @@
"minimum": 1.0
},
"description": {
"description": "Human-readable description of what the permission does.",
"description": "Human-readable description of what the permission does. Tauri convention is to use <h4> headings in markdown content for Tauri documentation generation purposes.",
"type": [
"string",
"null"
Expand Down Expand Up @@ -112,7 +111,7 @@
"type": "string"
},
"description": {
"description": "Human-readable description of what the permission does.",
"description": "Human-readable description of what the permission does. Tauri internal convention is to use <h4> headings in markdown content for Tauri documentation generation purposes.",
"type": [
"string",
"null"
Expand All @@ -132,12 +131,21 @@
},
"scope": {
"description": "Allowed or denied scoped when using this permission.",
"default": {},
"allOf": [
{
"$ref": "#/definitions/Scopes"
}
]
},
"platforms": {
"description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Target"
}
}
}
},
Expand All @@ -164,7 +172,7 @@
}
},
"Scopes": {
"description": "A restriction of the command/endpoint functionality.\n\nIt can be of any serde serializable type and is used for allowing or preventing certain actions inside a Tauri command.\n\nThe scope is passed to the command and handled/enforced by the command itself.",
"description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
"type": "object",
"properties": {
"allow": {
Expand All @@ -178,7 +186,7 @@
}
},
"deny": {
"description": "Data that defines what is denied by the scope.",
"description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
"type": [
"array",
"null"
Expand Down Expand Up @@ -243,24 +251,60 @@
}
]
},
"PermissionKind": {
"type": "string",
"Target": {
"description": "Platform target.",
"oneOf": [
{
"description": "allow-track-event -> Enables the track_event command without any pre-configured scope.",
"description": "MacOS.",
"type": "string",
"enum": [
"macOS"
]
},
{
"description": "Windows.",
"type": "string",
"enum": [
"windows"
]
},
{
"description": "Linux.",
"type": "string",
"enum": [
"linux"
]
},
{
"description": "Android.",
"type": "string",
"enum": [
"allow-track-event"
"android"
]
},
{
"description": "deny-track-event -> Denies the track_event command without any pre-configured scope.",
"description": "iOS.",
"type": "string",
"enum": [
"deny-track-event"
"iOS"
]
}
]
},
"PermissionKind": {
"type": "string",
"oneOf": [
{
"description": "Enables the track_event command without any pre-configured scope.",
"type": "string",
"const": "allow-track-event"
},
{
"description": "Denies the track_event command without any pre-configured scope.",
"type": "string",
"const": "deny-track-event"
}
]
}
}
}
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
newline_style = "Unix"
22 changes: 13 additions & 9 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::time::{SystemTime, UNIX_EPOCH};
use rand::Rng;
use serde_json::{json, Value};
use std::{sync::{Arc, Mutex as SyncMutex}, time::Duration};
use std::time::{SystemTime, UNIX_EPOCH};
use std::{
sync::{Arc, Mutex as SyncMutex},
time::Duration,
};
use time::{format_description::well_known::Rfc3339, OffsetDateTime};

use crate::{
config::Config,
sys::{self, SystemProperties}, dispatcher::EventDispatcher,
dispatcher::EventDispatcher,
sys::{self, SystemProperties},
};

static SESSION_TIMEOUT: Duration = Duration::from_secs(4 * 60 * 60);
Expand All @@ -22,7 +26,7 @@ fn new_session_id() -> String {

let id = epoch_in_seconds * 100_000_000 + random;

return id.to_string();
id.to_string()
}

/// A tracking session.
Expand All @@ -34,7 +38,7 @@ pub struct TrackingSession {

impl TrackingSession {
fn new() -> Self {
TrackingSession {
Self {
id: new_session_id(),
last_touch_ts: OffsetDateTime::now_utc(),
}
Expand All @@ -51,23 +55,22 @@ pub struct AptabaseClient {
}

impl AptabaseClient {

/// Creates a new Aptabase client.
pub fn new(config: &Config, app_version: String) -> Self {
let sys_info = sys::get_info();

let is_enabled = !config.app_key.is_empty();
let dispatcher = Arc::new(EventDispatcher::new(config, &sys_info));

AptabaseClient {
Self {
is_enabled,
dispatcher,
session: SyncMutex::new(TrackingSession::new()),
app_version,
sys_info,
}
}

/// Starts the event dispatcher loop.
pub(crate) fn start_polling(&self, interval: Duration) {
let dispatcher = self.dispatcher.clone();
Expand All @@ -90,7 +93,8 @@ impl AptabaseClient {
} else {
session.last_touch_ts = now;
}
return session.id.clone();

session.id.clone()
}

/// Enqueues an event to be sent to the server.
Expand Down
12 changes: 4 additions & 8 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use std::sync::Arc;
use serde_json::Value;
use std::sync::Arc;
use tauri::{command, State};

use crate::client::AptabaseClient;

#[command]
pub fn track_event(
client: State<'_, Arc<AptabaseClient>>,
name: &str,
props: Option<Value>,
) {
client.track_event(name, props);
}
pub fn track_event(client: State<'_, Arc<AptabaseClient>>, name: &str, props: Option<Value>) {
client.track_event(name, props);
}
Loading