Skip to content
Merged

V2 #21

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
77b3aef
feat: update for tauri v2
nwesterhausen Oct 16, 2023
21650bd
feat: use `sys_locale` to get locale
nwesterhausen Oct 16, 2023
78a4436
fix: spelling typo
nwesterhausen Oct 16, 2023
89a5970
docs: update install instructions
nwesterhausen Oct 16, 2023
759bbe1
docs: fix formatting of branch value
nwesterhausen Oct 16, 2023
212d6b7
fix: use unwrap_or_default
nwesterhausen Oct 16, 2023
8a6312c
chore: ignore lock file
nwesterhausen Oct 16, 2023
a983ec0
Merge pull request #5 from nwesterhausen/tauri-v2
goenning Oct 18, 2023
fabe1bb
Update README.md
goenning Oct 18, 2023
3e77d35
Update README.md
goenning Oct 18, 2023
69756df
docs: fix dependency name
nwesterhausen Oct 18, 2023
0ad92fa
Merge pull request #6 from nwesterhausen/patch-1
goenning Oct 18, 2023
ed7de87
fix: invoke is in primitives now
nwesterhausen Nov 1, 2023
0e04e3f
Update README.md
goenning Oct 18, 2023
226e218
Use new session id format
goenning Nov 3, 2023
3a46b90
Merge pull request #7 from nwesterhausen/patch-invoke-v2
goenning Nov 3, 2023
03bf4ec
commit webview-dist
goenning Nov 3, 2023
0ce6517
add message to set_hook
goenning Dec 12, 2023
cb2f936
update docs
goenning Dec 13, 2023
10753fd
Fixed an issue where `with_panic_hook` would swallow the panic after …
goenning Feb 5, 2024
4e2422a
update to beta2
goenning Feb 5, 2024
40efe59
feat: update for tauri v2
nwesterhausen Oct 16, 2023
3589f9b
feat: use `sys_locale` to get locale
nwesterhausen Oct 16, 2023
89a18ab
fix: spelling typo
nwesterhausen Oct 16, 2023
8617627
docs: update install instructions
nwesterhausen Oct 16, 2023
1adf8bb
docs: fix formatting of branch value
nwesterhausen Oct 16, 2023
2dbb3bd
fix: use unwrap_or_default
nwesterhausen Oct 16, 2023
bc50a39
chore: ignore lock file
nwesterhausen Oct 16, 2023
7e0e30e
Update README.md
goenning Oct 18, 2023
6dcbef0
Update README.md
goenning Oct 18, 2023
f0d4691
docs: fix dependency name
nwesterhausen Oct 18, 2023
a1c8f09
Use new session id format
goenning Nov 3, 2023
92e8ee1
fix: invoke is in primitives now
nwesterhausen Nov 1, 2023
19c7e45
commit webview-dist
goenning Nov 3, 2023
af62faa
add message to set_hook
goenning Dec 12, 2023
947505c
update docs
goenning Dec 13, 2023
fcaa774
update to beta2
goenning Feb 5, 2024
728f1bb
Merge branch 'v2' into v2
nekename Nov 27, 2024
93aab7e
Merge pull request #12 from ninjadev64/v2
cristipufu Nov 28, 2024
11df29a
Resolve linter violations and format code
nekename Nov 28, 2024
83f2aab
Update dependencies and remove unused dependencies
nekename Nov 28, 2024
2d0f7d8
Merge pull request #13 from ninjadev64/v2
cristipufu Nov 29, 2024
0423821
Verify that the `props` of an event is an object
nekename Dec 15, 2024
f9f199f
Merge pull request #14 from ninjadev64/v2
cristipufu Dec 15, 2024
c4b5ca3
Replace usage of `tauri::async_runtime`
nekename Dec 16, 2024
373abe1
Merge pull request #15 from ninjadev64/v2
cristipufu Dec 16, 2024
0991e31
Add Flatpak as a recognised platform
nekename Jan 6, 2025
22363f3
fix: deprecated rand::thread_rng and rand::Rng::gen_range
0PandaDEV Jan 29, 2025
f7af726
chore: Update project dependencies to latest versions
0PandaDEV Jan 29, 2025
8085ab1
refactor: Update panic hook type from PanicHookInfo to PanicInfo fixe…
0PandaDEV Jan 29, 2025
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package-lock.json
.vscode/settings.json
yarn.lock

/.tauri
/target
Cargo.lock
node_modules/
webview-dist
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
## 0.2.0

* BREAKING CHANGE: replaced the `init` function with a `Builder` struct, see README for example usage
* Ability to set custom hosts for self hosted servers
* Ability to set custom hosts for self hosted servers
33 changes: 18 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ 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.59"
rust-version = "1.70"
readme = "README.md"
repository = "https://github.com/aptabase/tauri-plugin-aptabase"
exclude = ["/examples", "/webview-dist", "/webview-src", "node_modules"]
exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"]
links = "tauri-plugin-aptabase"

[dependencies]
tauri = { version = "1", features = ["os-api"] }
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"]}
os_info = "3"
uuid = "1"
rand = "0.8"
log = "0.4"
tauri = "2.2.5"
tokio = "1.43.0"
futures = "0.3.31"
serde = "1.0.217"
serde_json = "1.0.138"
reqwest = { version = "0.12.12", features = ["json"] }
time = { version = "0.3.37", features = ["formatting"] }
os_info = "3.9.2"
rand = "0.9.0"
log = "0.4.25"
sys-locale = "0.3.2"

[build-dependencies]
tauri-plugin = { version = "2.0.4", features = ["build"] }
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:

```toml
[dependencies]
tauri-plugin-aptabase = "0.4"
tauri-plugin-aptabase = { git = "https://github.com/aptabase/tauri-plugin-aptabase", branch = "v2" }
```

You can install the JavaScript Guest bindings using your preferred JavaScript package manager

```bash
npm add @aptabase/tauri
npm add https://github.com/aptabase/tauri-plugin-aptabase#v2
```

> This plugin is only compatible with Tauri v1. To use it on a Tauri v2 app, [follow the instructions on our v2 branch](https://github.com/aptabase/tauri-plugin-aptabase/blob/v2).

## Usage

First, you need to get your `App Key` from Aptabase, you can find it in the `Instructions` menu on the left side menu.

Then you need to register the core plugin with Tauri:
Then register the plugin with Tauri:

`src-tauri/src/main.rs`

Expand All @@ -40,11 +38,12 @@ fn main() {
}
```

And finally add `aptabase:allow-track-event` to your list Access Control List.

You can then start sending events from Rust by importing the `tauri_plugin_aptabase::EventTracker` trait and calling the `track_event` method on `App`, `AppHandle` or `Window`.

As an example, you can add `app_started` and `app_exited` events like this:


```rust
use tauri_plugin_aptabase::EventTracker;

Expand Down Expand Up @@ -83,3 +82,35 @@ A few important notes:
- Because of this, it's generally recommended to at least track an event at startup
3. You do not need to await for the `trackEvent` function, it'll run in the background.
3. Only strings and numbers values are allowed on custom properties

## Providing the APTABASE_KEY via .env

It's possible to load the APTABASE_KEY from a .env file at compile time using the `dotenvy_macro` crate. The `.env` file needs to be
in the `src-tauri` directory for the `dotevny_macro` crate to find it properly.

Add the `use` declaration to where you are building the tauri app (likely `lib.rs` for Tauri v2), and then call it where you would put the key.

```rust
use tauri_plugin_aptabase::EventTracker;
use dotenvy_macro::dotenv;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
/// This function sets up and runs a Rust application using the Tauri framework, with various plugins
/// and event handlers.
pub fn run() {
tauri::Builder::default()
.build(tauri::generate_context!())
.plugin(tauri_plugin_aptabase::Builder::new(dotenv!("APTABASE_KEY")).build())
.expect("Error when building tauri app")
.run(|handler, event| match event {
tauri::RunEvent::Exit { .. } => {
handler.track_event("app_exited", None);
handler.flush_events_blocking();
}
tauri::RunEvent::Ready { .. } => {
handler.track_event("app_started", None);
}
_ => {}
});
}
```
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const COMMANDS: &[&str] = &["track_event"];

fn main() {
tauri_plugin::Builder::new(COMMANDS).build();
}
7 changes: 0 additions & 7 deletions examples/helloworld/README.md

This file was deleted.

6 changes: 3 additions & 3 deletions examples/helloworld/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + React + TS</title>
<title>Tauri + Svelte</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions examples/helloworld/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"moduleResolution": "Node",
"target": "ESNext",
"module": "ESNext",
/**
* svelte-preprocess cannot figure out whether you have
* a value or a type, so tell TypeScript to enforce using
* `import type` instead of `import` for Types.
*/
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"resolveJsonModule": true,
/**
* To have warnings / errors of the Svelte compiler at the
* correct position, enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types.
*/
"checkJs": true
},
/**
* Use global.d.ts instead of compilerOptions.types
* to avoid limiting type declarations.
*/
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}
16 changes: 6 additions & 10 deletions examples/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@
"tauri": "tauri"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@tauri-apps/api": "^1.2.0",
"@tauri-apps/api": "^2.1.1",
"@aptabase/tauri": "file:../../"
},
"devDependencies": {
"@types/node": "^18.7.10",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^3.0.0",
"typescript": "^4.6.4",
"vite": "^4.0.0",
"@tauri-apps/cli": "^1.2.2"
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"internal-ip": "^7.0.0",
"svelte": "^3.49.0",
"vite": "^3.0.2",
"@tauri-apps/cli": "^2.1.0"
}
}
1 change: 1 addition & 0 deletions examples/helloworld/public/svelte.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 11 additions & 10 deletions examples/helloworld/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
[package]
name = "helloworld"
name = "tauri-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
rust-version = "1.70"

[lib]
name = "tauri_app_lib"
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 = "1.4", features = [] }
tauri-build = { version = "2.0", default-features = false, features = [] }

[dependencies]
tauri = { version = "2.1", features = [] }
tauri-plugin-aptabase = { path = "../../../" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.4", features = ["shell-open"] }
tauri-plugin-aptabase = { path = "../../../" }
tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }

[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
# this feature is used for production builds or when `devUrl` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
8 changes: 8 additions & 0 deletions examples/helloworld/src-tauri/capabilities/desktop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"aptabase:allow-track-event"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","context":"local","windows":["main"],"permissions":["aptabase:allow-track-event"],"platforms":["linux","macOS","windows","android","iOS"]}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{schema_str}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{schema_str}

Large diffs are not rendered by default.

Binary file modified examples/helloworld/src-tauri/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/helloworld/src-tauri/icons/128x128@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/helloworld/src-tauri/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed examples/helloworld/src-tauri/icons/Square30x30Logo.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed examples/helloworld/src-tauri/icons/StoreLogo.png
Binary file not shown.
Binary file modified examples/helloworld/src-tauri/icons/icon.icns
Binary file not shown.
Binary file modified examples/helloworld/src-tauri/icons/icon.ico
Binary file not shown.
Binary file modified examples/helloworld/src-tauri/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions examples/helloworld/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use serde_json::json;

#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

#[tauri::command]
fn this_will_panic() {
panic!("I told you!");
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, this_will_panic])
.plugin(tauri_plugin_aptabase::Builder::new("A-US-0928558097").with_panic_hook(Box::new(|client, info, msg| {
let location = info.location().map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column())).unwrap_or_else(|| "".to_string());

client.track_event("panic", Some(json!({
"info": format!("{} ({})", msg, location),
})));
})).build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
43 changes: 3 additions & 40 deletions examples/helloworld/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use tauri_plugin_log::LogTarget;
use tauri_plugin_aptabase::EventTracker;
use serde_json::json;

#[tauri::command]
fn this_will_panic() {
panic!("I told you!");
}
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![this_will_panic])
.plugin(tauri_plugin_aptabase::Builder::new("A-DEV-0000000000").with_panic_hook(Box::new(|client, info, msg| {
let location = info.location().map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column())).unwrap_or_else(|| "".to_string());

client.track_event("panic", Some(json!({
"info": format!("{} ({})", msg, location),
})));
})).build())
.plugin(tauri_plugin_log::Builder::default().targets([
LogTarget::LogDir,
LogTarget::Stdout,
LogTarget::Webview,
]).build())
.setup(|app| {
app.track_event("app_started", None);
Ok(())
})
.build(tauri::generate_context!())
.expect("error while running tauri application")
.run(|handler, event| match event {
tauri::RunEvent::Exit { .. } => {
handler.track_event("app_exit", None);
handler.flush_events_blocking();
}
_ => {}
})
tauri_app_lib::run();
}
Loading