mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-09 14:25:12 +02:00
Database access refactor (#190)
This commit is contained in:
+20
-28
@@ -1,8 +1,6 @@
|
||||
use tauri::{AppHandle, Runtime};
|
||||
|
||||
use yaak_models::queries::{
|
||||
get_key_value_int, get_key_value_string, set_key_value_int, set_key_value_string, UpdateSource,
|
||||
};
|
||||
use yaak_models::manager::QueryManagerExt;
|
||||
use yaak_models::queries_legacy::UpdateSource;
|
||||
|
||||
const NAMESPACE: &str = "analytics";
|
||||
const NUM_LAUNCHES_KEY: &str = "num_launches";
|
||||
@@ -21,34 +19,28 @@ pub async fn store_launch_history<R: Runtime>(app_handle: &AppHandle<R>) -> Laun
|
||||
let mut info = LaunchEventInfo::default();
|
||||
|
||||
info.num_launches = get_num_launches(app_handle).await + 1;
|
||||
info.previous_version =
|
||||
get_key_value_string(app_handle, NAMESPACE, last_tracked_version_key, "").await;
|
||||
info.current_version = app_handle.package_info().version.to_string();
|
||||
|
||||
if info.previous_version.is_empty() {
|
||||
} else {
|
||||
info.launched_after_update = info.current_version != info.previous_version;
|
||||
};
|
||||
app_handle
|
||||
.queries()
|
||||
.with_tx(|tx| {
|
||||
info.previous_version =
|
||||
tx.get_key_value_string(NAMESPACE, last_tracked_version_key, "");
|
||||
|
||||
// Update key values
|
||||
if !info.previous_version.is_empty() {
|
||||
info.launched_after_update = info.current_version != info.previous_version;
|
||||
};
|
||||
|
||||
set_key_value_string(
|
||||
app_handle,
|
||||
NAMESPACE,
|
||||
last_tracked_version_key,
|
||||
info.current_version.as_str(),
|
||||
&UpdateSource::Background,
|
||||
)
|
||||
.await;
|
||||
// Update key values
|
||||
|
||||
set_key_value_int(
|
||||
app_handle,
|
||||
NAMESPACE,
|
||||
NUM_LAUNCHES_KEY,
|
||||
info.num_launches,
|
||||
&UpdateSource::Background,
|
||||
)
|
||||
.await;
|
||||
let source = &UpdateSource::Background;
|
||||
let version = info.current_version.as_str();
|
||||
tx.set_key_value_string(NAMESPACE, last_tracked_version_key, version, source);
|
||||
tx.set_key_value_int(NAMESPACE, NUM_LAUNCHES_KEY, info.num_launches, source);
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
info
|
||||
}
|
||||
@@ -66,5 +58,5 @@ pub fn get_os() -> &'static str {
|
||||
}
|
||||
|
||||
pub async fn get_num_launches<R: Runtime>(app_handle: &AppHandle<R>) -> i32 {
|
||||
get_key_value_int(app_handle, NAMESPACE, NUM_LAUNCHES_KEY, 0).await
|
||||
app_handle.queries().connect().await.unwrap().get_key_value_int(NAMESPACE, NUM_LAUNCHES_KEY, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user