Clean up DB refactor access (#192)

This commit is contained in:
Gregory Schier
2025-03-26 07:54:58 -07:00
committed by GitHub
parent 006284b99c
commit b7f62b78b1
39 changed files with 470 additions and 705 deletions

View File

@@ -1,6 +1,6 @@
use tauri::{AppHandle, Runtime};
use yaak_models::manager::QueryManagerExt;
use yaak_models::queries_legacy::UpdateSource;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
const NAMESPACE: &str = "analytics";
const NUM_LAUNCHES_KEY: &str = "num_launches";
@@ -22,7 +22,6 @@ pub async fn store_launch_history<R: Runtime>(app_handle: &AppHandle<R>) -> Laun
info.current_version = app_handle.package_info().version.to_string();
app_handle
.queries()
.with_tx(|tx| {
info.previous_version =
tx.get_key_value_string(NAMESPACE, last_tracked_version_key, "");
@@ -39,7 +38,6 @@ pub async fn store_launch_history<R: Runtime>(app_handle: &AppHandle<R>) -> Laun
tx.set_key_value_int(NAMESPACE, NUM_LAUNCHES_KEY, info.num_launches, source);
Ok(())
})
.await
.unwrap();
info
@@ -58,5 +56,5 @@ pub fn get_os() -> &'static str {
}
pub async fn get_num_launches<R: Runtime>(app_handle: &AppHandle<R>) -> i32 {
app_handle.queries().connect().await.unwrap().get_key_value_int(NAMESPACE, NUM_LAUNCHES_KEY, 0)
app_handle.db().get_key_value_int(NAMESPACE, NUM_LAUNCHES_KEY, 0)
}

View File

@@ -24,12 +24,12 @@ use tokio::fs::{create_dir_all, File};
use tokio::io::AsyncWriteExt;
use tokio::sync::watch::Receiver;
use tokio::sync::{oneshot, Mutex};
use yaak_models::manager::QueryManagerExt;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::models::{
Cookie, CookieJar, Environment, HttpRequest, HttpResponse, HttpResponseHeader,
HttpResponseState, ProxySetting, ProxySettingAuth,
};
use yaak_models::queries_legacy::UpdateSource;
use yaak_models::util::UpdateSource;
use yaak_plugins::events::{
CallHttpAuthenticationRequest, HttpHeader, RenderPurpose, WindowContext,
};
@@ -48,16 +48,13 @@ pub async fn send_http_request<R: Runtime>(
let plugin_manager = app_handle.state::<PluginManager>();
let update_source = &UpdateSource::from_window(&window);
let (settings, workspace) = {
let db = window.queries().connect().await?;
let settings = db.get_or_create_settings(update_source)?;
let db = window.db();
let settings = db.get_or_create_settings(update_source);
let workspace = db.get_workspace(&unrendered_request.workspace_id)?;
(settings, workspace)
};
let base_environment = app_handle
.queries()
.connect()
.await?
.get_base_environment(&unrendered_request.workspace_id)?;
let base_environment =
app_handle.db().get_base_environment(&unrendered_request.workspace_id)?;
let response_id = og_response.id.clone();
let response = Arc::new(Mutex::new(og_response.clone()));
@@ -84,8 +81,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e.to_string(),
&update_source,
)
.await)
))
}
};
@@ -200,8 +196,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
format!("Failed to parse URL \"{}\": {}", url_string, e.to_string()),
&update_source,
)
.await);
));
}
};
// Yes, we're parsing both URI and URL because they could return different errors
@@ -213,8 +208,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
format!("Failed to parse URL \"{}\": {}", url_string, e.to_string()),
&update_source,
)
.await);
));
}
};
@@ -321,8 +315,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e,
&update_source,
)
.await);
));
}
}
} else if body_type == "multipart/form-data" && request_body.contains_key("form") {
@@ -353,8 +346,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e.to_string(),
&update_source,
)
.await);
));
}
}
};
@@ -371,8 +363,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
format!("Invalid mime for multi-part entry {e:?}"),
&update_source,
)
.await);
));
}
};
} else if !file_path.is_empty() {
@@ -388,8 +379,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
format!("Invalid mime for multi-part entry {e:?}"),
&update_source,
)
.await);
));
}
};
}
@@ -431,8 +421,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e.to_string(),
&update_source,
)
.await);
));
}
};
@@ -463,8 +452,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e.to_string(),
&update_source,
)
.await);
));
}
};
@@ -490,7 +478,7 @@ pub async fn send_http_request<R: Runtime>(
Ok(r) = resp_rx => r,
_ = cancelled_rx.changed() => {
debug!("Request cancelled");
return Ok(response_err(&app_handle, &*response.lock().await, "Request was cancelled".to_string(), &update_source).await);
return Ok(response_err(&app_handle, &*response.lock().await, "Request was cancelled".to_string(), &update_source));
}
};
@@ -541,10 +529,7 @@ pub async fn send_http_request<R: Runtime>(
r.state = HttpResponseState::Connected;
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.update_http_response_if_id(&r, &update_source)
.expect("Failed to update response after connected");
}
@@ -574,10 +559,7 @@ pub async fn send_http_request<R: Runtime>(
written_bytes += bytes.len();
r.content_length = Some(written_bytes as i32);
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.update_http_response_if_id(&r, &update_source)
.expect("Failed to update response");
}
@@ -590,8 +572,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
e.to_string(),
&update_source,
)
.await;
);
break;
}
}
@@ -606,10 +587,7 @@ pub async fn send_http_request<R: Runtime>(
};
r.state = HttpResponseState::Closed;
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.update_http_response_if_id(&r, &UpdateSource::from_window(&window))
.expect("Failed to update response");
};
@@ -636,10 +614,7 @@ pub async fn send_http_request<R: Runtime>(
.collect::<Vec<_>>();
cookie_jar.cookies = json_cookies;
if let Err(e) = app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_cookie_jar(&cookie_jar, &UpdateSource::from_window(&window))
{
error!("Failed to update cookie jar: {}", e);
@@ -653,8 +628,7 @@ pub async fn send_http_request<R: Runtime>(
&*response.lock().await,
format!("{e}{e:?}"),
&update_source,
)
.await;
);
}
};
@@ -667,19 +641,14 @@ pub async fn send_http_request<R: Runtime>(
Ok(tokio::select! {
Ok(r) = done_rx => r,
_ = cancelled_rx.changed() => {
match app_handle.queries().with_conn(|c| c.get_http_response(&response_id)).await {
match app_handle.with_db(|c| c.get_http_response(&response_id)) {
Ok(mut r) => {
r.state = HttpResponseState::Closed;
app_handle
.queries()
.connect()
.await
.unwrap()
.update_http_response_if_id(&r, &UpdateSource::from_window(window))
app_handle.db().update_http_response_if_id(&r, &UpdateSource::from_window(window))
.expect("Failed to update response")
},
_ => {
response_err(&app_handle, &*response.lock().await, "Ephemeral request was cancelled".to_string(), &update_source).await
response_err(&app_handle, &*response.lock().await, "Ephemeral request was cancelled".to_string(), &update_source)
}.clone(),
}
}

View File

@@ -30,13 +30,13 @@ use tokio::sync::Mutex;
use tokio::task::block_in_place;
use yaak_grpc::manager::{DynamicMessage, GrpcHandle};
use yaak_grpc::{deserialize_message, serialize_message, Code, ServiceDefinition};
use yaak_models::manager::QueryManagerExt;
use yaak_models::models::{
CookieJar, Environment, EnvironmentVariable, Folder, GrpcConnection, GrpcConnectionState,
GrpcEvent, GrpcEventType, GrpcRequest, HttpRequest, HttpResponse, HttpResponseState, KeyValue,
ModelType, Plugin, Settings, WebsocketRequest, Workspace, WorkspaceMeta,
};
use yaak_models::queries_legacy::{
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::{
generate_model_id, get_workspace_export_resources, BatchUpsertResult, UpdateSource,
};
use yaak_plugins::events::{
@@ -108,11 +108,10 @@ async fn cmd_render_template<R: Runtime>(
environment_id: Option<&str>,
) -> YaakResult<String> {
let environment = match environment_id {
Some(id) => app_handle.queries().connect().await?.get_environment(id).ok(),
Some(id) => app_handle.db().get_environment(id).ok(),
None => None,
};
let base_environment =
app_handle.queries().connect().await?.get_base_environment(&workspace_id)?;
let base_environment = app_handle.db().get_base_environment(&workspace_id)?;
let result = render_template(
template,
&base_environment,
@@ -143,12 +142,7 @@ async fn cmd_grpc_reflect<R: Runtime>(
app_handle: AppHandle<R>,
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> YaakResult<Vec<ServiceDefinition>> {
let req = app_handle
.queries()
.connect()
.await?
.get_grpc_request(request_id)?
.ok_or(GenericError("Failed to find GRPC request".to_string()))?;
let req = app_handle.db().get_grpc_request(request_id)?;
let uri = safe_uri(&req.url);
@@ -175,20 +169,12 @@ async fn cmd_grpc_go<R: Runtime>(
grpc_handle: State<'_, Mutex<GrpcHandle>>,
) -> YaakResult<String> {
let environment = match environment_id {
Some(id) => app_handle.queries().connect().await?.get_environment(id).ok(),
Some(id) => app_handle.db().get_environment(id).ok(),
None => None,
};
let unrendered_request = app_handle
.queries()
.connect()
.await?
.get_grpc_request(request_id)?
.ok_or(GenericError("Failed to get GRPC request".to_string()))?;
let base_environment = app_handle
.queries()
.connect()
.await?
.get_base_environment(&unrendered_request.workspace_id)?;
let unrendered_request = app_handle.db().get_grpc_request(request_id)?;
let base_environment =
app_handle.db().get_base_environment(&unrendered_request.workspace_id)?;
let request = render_grpc_request(
&unrendered_request,
&base_environment,
@@ -237,7 +223,7 @@ async fn cmd_grpc_go<R: Runtime>(
}
}
let conn = app_handle.queries().connect().await?.upsert_grpc_connection(
let conn = app_handle.db().upsert_grpc_connection(
&GrpcConnection {
workspace_id: request.workspace_id.clone(),
request_id: request.id.clone(),
@@ -289,7 +275,7 @@ async fn cmd_grpc_go<R: Runtime>(
let connection = match connection {
Ok(c) => c,
Err(err) => {
app_handle.queries().connect().await?.upsert_grpc_connection(
app_handle.db().upsert_grpc_connection(
&GrpcConnection {
elapsed: start.elapsed().as_millis() as i32,
error: Some(err.clone()),
@@ -364,10 +350,7 @@ async fn cmd_grpc_go<R: Runtime>(
Err(e) => {
tauri::async_runtime::spawn(async move {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
event_type: GrpcEventType::Error,
@@ -384,10 +367,7 @@ async fn cmd_grpc_go<R: Runtime>(
in_msg_tx.try_send(d_msg).unwrap();
tauri::async_runtime::spawn(async move {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: msg,
@@ -431,7 +411,7 @@ async fn cmd_grpc_go<R: Runtime>(
)
.await?;
app_handle.queries().connect().await?.upsert_grpc_event(
app_handle.db().upsert_grpc_event(
&GrpcEvent {
content: format!("Connecting to {}", req.url),
event_type: GrpcEventType::ConnectionStart,
@@ -469,10 +449,7 @@ async fn cmd_grpc_go<R: Runtime>(
if !method_desc.is_client_streaming() {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
event_type: GrpcEventType::ClientMessage,
@@ -487,10 +464,7 @@ async fn cmd_grpc_go<R: Runtime>(
match maybe_msg {
Some(Ok(msg)) => {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
metadata: metadata_to_map(msg.metadata().clone()),
@@ -507,10 +481,7 @@ async fn cmd_grpc_go<R: Runtime>(
)
.unwrap();
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: serialize_message(&msg.into_inner()).unwrap(),
@@ -521,10 +492,7 @@ async fn cmd_grpc_go<R: Runtime>(
)
.unwrap();
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: "Connection complete".to_string(),
@@ -538,10 +506,7 @@ async fn cmd_grpc_go<R: Runtime>(
}
Some(Err(e)) => {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&(match e.status {
Some(s) => GrpcEvent {
@@ -572,10 +537,7 @@ async fn cmd_grpc_go<R: Runtime>(
let mut stream = match maybe_stream {
Some(Ok(stream)) => {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
metadata: metadata_to_map(stream.metadata().clone()),
@@ -596,10 +558,7 @@ async fn cmd_grpc_go<R: Runtime>(
Some(Err(e)) => {
warn!("GRPC stream error {e:?}");
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&(match e.status {
Some(s) => GrpcEvent {
@@ -631,10 +590,7 @@ async fn cmd_grpc_go<R: Runtime>(
Ok(Some(msg)) => {
let message = serialize_message(&msg).unwrap();
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: message,
@@ -649,10 +605,7 @@ async fn cmd_grpc_go<R: Runtime>(
let trailers =
stream.trailers().await.unwrap_or_default().unwrap_or_default();
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: "Connection complete".to_string(),
@@ -668,10 +621,7 @@ async fn cmd_grpc_go<R: Runtime>(
}
Err(status) => {
app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_grpc_event(
&GrpcEvent {
content: status.to_string(),
@@ -695,12 +645,12 @@ async fn cmd_grpc_go<R: Runtime>(
let w = app_handle.clone();
tokio::select! {
_ = grpc_listen => {
let events = w.queries().connect().await.unwrap().list_grpc_events(&conn_id).unwrap();
let events = w.db().list_grpc_events(&conn_id).unwrap();
let closed_event = events
.iter()
.find(|e| GrpcEventType::ConnectionEnd == e.event_type);
let closed_status = closed_event.and_then(|e| e.status).unwrap_or(Code::Unavailable as i32);
w.queries().with_conn(|c| {
w.with_tx(|c| {
c.upsert_grpc_connection(
&GrpcConnection{
elapsed: start.elapsed().as_millis() as i32,
@@ -710,10 +660,10 @@ async fn cmd_grpc_go<R: Runtime>(
},
&UpdateSource::from_window(&window),
)
}).await.unwrap();
}).unwrap();
},
_ = cancelled_rx.changed() => {
w.queries().connect().await.unwrap().upsert_grpc_event(
w.db().upsert_grpc_event(
&GrpcEvent {
content: "Cancelled".to_string(),
event_type: GrpcEventType::ConnectionEnd,
@@ -722,7 +672,7 @@ async fn cmd_grpc_go<R: Runtime>(
},
&UpdateSource::from_window(&window),
).unwrap();
w.queries().with_conn(|c| {
w.with_tx(|c| {
c.upsert_grpc_connection(
&GrpcConnection{
elapsed: start.elapsed().as_millis() as i32,
@@ -732,7 +682,7 @@ async fn cmd_grpc_go<R: Runtime>(
},
&UpdateSource::from_window(&window),
)
}).await.unwrap();
}).unwrap();
},
}
w.unlisten(event_handler);
@@ -753,11 +703,11 @@ async fn cmd_send_ephemeral_request<R: Runtime>(
let response = HttpResponse::default();
request.id = "".to_string();
let environment = match environment_id {
Some(id) => Some(app_handle.queries().connect().await?.get_environment(id)?),
Some(id) => Some(app_handle.db().get_environment(id)?),
None => None,
};
let cookie_jar = match cookie_jar_id {
Some(id) => Some(app_handle.queries().connect().await?.get_cookie_jar(id)?),
Some(id) => Some(app_handle.db().get_cookie_jar(id)?),
None => None,
};
@@ -784,7 +734,7 @@ async fn cmd_filter_response<R: Runtime>(
plugin_manager: State<'_, PluginManager>,
filter: &str,
) -> YaakResult<FilterResponse> {
let response = app_handle.queries().connect().await?.get_http_response(response_id)?;
let response = app_handle.db().get_http_response(response_id)?;
if let None = response.body_path {
return Err(GenericError("Response body path not set".to_string()));
@@ -940,20 +890,17 @@ async fn cmd_import_data<R: Runtime>(
})
.collect();
let upserted = app_handle
.queries()
.with_tx(|tx| {
tx.batch_upsert(
workspaces,
environments,
folders,
http_requests,
grpc_requests,
websocket_requests,
&UpdateSource::Import,
)
})
.await?;
let upserted = app_handle.with_tx(|tx| {
tx.batch_upsert(
workspaces,
environments,
folders,
http_requests,
grpc_requests,
websocket_requests,
&UpdateSource::Import,
)
})?;
Ok(upserted)
}
@@ -1077,7 +1024,7 @@ async fn cmd_save_response<R: Runtime>(
response_id: &str,
filepath: &str,
) -> YaakResult<()> {
let response = app_handle.queries().connect().await?.get_http_response(response_id)?;
let response = app_handle.db().get_http_response(response_id)?;
let body_path =
response.body_path.ok_or(GenericError("Response does not have a body".to_string()))?;
@@ -1097,7 +1044,7 @@ async fn cmd_send_http_request<R: Runtime>(
// that has not yet been saved in the DB.
request: HttpRequest,
) -> YaakResult<HttpResponse> {
let response = app_handle.queries().connect().await?.upsert_http_response(
let response = app_handle.db().upsert_http_response(
&HttpResponse {
request_id: request.id.clone(),
workspace_id: request.workspace_id.clone(),
@@ -1114,7 +1061,7 @@ async fn cmd_send_http_request<R: Runtime>(
});
let environment = match environment_id {
Some(id) => match app_handle.queries().connect().await?.get_environment(id) {
Some(id) => match app_handle.db().get_environment(id) {
Ok(env) => Some(env),
Err(e) => {
warn!("Failed to find environment by id {id} {}", e);
@@ -1125,14 +1072,14 @@ async fn cmd_send_http_request<R: Runtime>(
};
let cookie_jar = match cookie_jar_id {
Some(id) => Some(app_handle.queries().connect().await?.get_cookie_jar(id)?),
Some(id) => Some(app_handle.db().get_cookie_jar(id)?),
None => None,
};
send_http_request(&window, &request, &response, environment, cookie_jar, &mut cancel_rx).await
}
async fn response_err<R: Runtime>(
fn response_err<R: Runtime>(
app_handle: &AppHandle<R>,
response: &HttpResponse,
error: String,
@@ -1143,10 +1090,7 @@ async fn response_err<R: Runtime>(
response.state = HttpResponseState::Closed;
response.error = Some(error.clone());
response = app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.update_http_response_if_id(&response, update_source)
.expect("Failed to update response");
response
@@ -1158,7 +1102,7 @@ async fn cmd_set_update_mode<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<KeyValue> {
let (key_value, _created) = app_handle.queries().connect().await?.set_key_value_raw(
let (key_value, _created) = app_handle.db().set_key_value_raw(
"app",
"update_mode",
update_mode,
@@ -1173,7 +1117,7 @@ async fn cmd_get_key_value<R: Runtime>(
key: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Option<KeyValue>> {
Ok(app_handle.queries().connect().await?.get_key_value_raw(namespace, key))
Ok(app_handle.db().get_key_value_raw(namespace, key))
}
#[tauri::command]
@@ -1184,7 +1128,7 @@ async fn cmd_set_key_value<R: Runtime>(
key: &str,
value: &str,
) -> YaakResult<KeyValue> {
let (key_value, _created) = app_handle.queries().connect().await?.set_key_value_raw(
let (key_value, _created) = app_handle.db().set_key_value_raw(
namespace,
key,
value,
@@ -1205,7 +1149,7 @@ async fn cmd_install_plugin<R: Runtime>(
.add_plugin_by_dir(&WindowContext::from_window(&window), &directory, true)
.await?;
Ok(app_handle.queries().connect().await?.upsert_plugin(
Ok(app_handle.db().upsert_plugin(
&Plugin {
directory: directory.into(),
url,
@@ -1222,11 +1166,8 @@ async fn cmd_uninstall_plugin<R: Runtime>(
window: WebviewWindow<R>,
app_handle: AppHandle<R>,
) -> YaakResult<Plugin> {
let plugin = app_handle
.queries()
.connect()
.await?
.delete_plugin_by_id(plugin_id, &UpdateSource::from_window(&window))?;
let plugin =
app_handle.db().delete_plugin_by_id(plugin_id, &UpdateSource::from_window(&window))?;
plugin_manager
.uninstall(&WindowContext::from_window(&window), plugin.directory.as_str())
@@ -1241,11 +1182,7 @@ async fn cmd_update_cookie_jar<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<CookieJar> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_cookie_jar(&cookie_jar, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_cookie_jar(&cookie_jar, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1255,9 +1192,7 @@ async fn cmd_delete_cookie_jar<R: Runtime>(
cookie_jar_id: &str,
) -> YaakResult<CookieJar> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_cookie_jar_by_id(cookie_jar_id, &UpdateSource::from_window(&window))?)
}
@@ -1268,7 +1203,7 @@ async fn cmd_create_cookie_jar<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<CookieJar> {
Ok(app_handle.queries().connect().await?.upsert_cookie_jar(
Ok(app_handle.db().upsert_cookie_jar(
&CookieJar {
name: name.to_string(),
workspace_id: workspace_id.to_string(),
@@ -1287,7 +1222,7 @@ async fn cmd_create_environment<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Environment> {
Ok(app_handle.queries().connect().await?.upsert_environment(
Ok(app_handle.db().upsert_environment(
&Environment {
workspace_id: workspace_id.to_string(),
environment_id: environment_id.map(|s| s.to_string()),
@@ -1308,7 +1243,7 @@ async fn cmd_create_grpc_request<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<GrpcRequest> {
Ok(app_handle.queries().connect().await?.upsert_grpc_request(
Ok(app_handle.db().upsert_grpc_request(
&GrpcRequest {
workspace_id: workspace_id.to_string(),
name: name.to_string(),
@@ -1326,8 +1261,8 @@ async fn cmd_duplicate_grpc_request<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<GrpcRequest> {
let db = app_handle.queries().connect().await?;
let request = db.get_grpc_request(id)?.unwrap();
let db = app_handle.db();
let request = db.get_grpc_request(id)?;
Ok(db.duplicate_grpc_request(&request, &UpdateSource::from_window(&window))?)
}
@@ -1337,7 +1272,7 @@ async fn cmd_duplicate_folder<R: Runtime>(
window: WebviewWindow<R>,
id: &str,
) -> YaakResult<Folder> {
let db = app_handle.queries().connect().await?;
let db = app_handle.db();
let folder = db.get_folder(id)?;
Ok(db.duplicate_folder(&folder, &UpdateSource::from_window(&window))?)
}
@@ -1348,8 +1283,8 @@ async fn cmd_duplicate_http_request<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<HttpRequest> {
let db = app_handle.queries().connect().await?;
let request = db.get_http_request(id)?.unwrap();
let db = app_handle.db();
let request = db.get_http_request(id)?;
Ok(db.duplicate_http_request(&request, &UpdateSource::from_window(&window))?)
}
@@ -1359,11 +1294,7 @@ async fn cmd_update_workspace<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Workspace> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_workspace(&workspace, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_workspace(&workspace, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1373,9 +1304,7 @@ async fn cmd_update_workspace_meta<R: Runtime>(
window: WebviewWindow<R>,
) -> YaakResult<WorkspaceMeta> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.upsert_workspace_meta(&workspace_meta, &UpdateSource::from_window(&window))?)
}
@@ -1385,11 +1314,7 @@ async fn cmd_update_environment<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Environment> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_environment(&environment, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_environment(&environment, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1398,11 +1323,7 @@ async fn cmd_update_grpc_request<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<GrpcRequest> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_grpc_request(&request, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_grpc_request(&request, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1411,11 +1332,7 @@ async fn cmd_upsert_http_request<R: Runtime>(
window: WebviewWindow<R>,
app_handle: AppHandle<R>,
) -> YaakResult<HttpRequest> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert(&request, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert(&request, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1425,9 +1342,7 @@ async fn cmd_delete_grpc_request<R: Runtime>(
window: WebviewWindow<R>,
) -> YaakResult<GrpcRequest> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_grpc_request_by_id(request_id, &UpdateSource::from_window(&window))?)
}
@@ -1438,9 +1353,7 @@ async fn cmd_delete_http_request<R: Runtime>(
window: WebviewWindow<R>,
) -> YaakResult<HttpRequest> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_http_request_by_id(request_id, &UpdateSource::from_window(&window))?)
}
@@ -1449,7 +1362,7 @@ async fn cmd_list_folders<R: Runtime>(
workspace_id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<Folder>> {
Ok(app_handle.queries().connect().await?.list_folders(workspace_id)?)
Ok(app_handle.db().list_folders(workspace_id)?)
}
#[tauri::command]
@@ -1458,11 +1371,7 @@ async fn cmd_update_folder<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Folder> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_folder(&folder, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_folder(&folder, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1471,11 +1380,7 @@ async fn cmd_delete_folder<R: Runtime>(
window: WebviewWindow<R>,
folder_id: &str,
) -> YaakResult<Folder> {
Ok(app_handle
.queries()
.connect()
.await?
.delete_folder_by_id(folder_id, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().delete_folder_by_id(folder_id, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1485,9 +1390,7 @@ async fn cmd_delete_environment<R: Runtime>(
environment_id: &str,
) -> YaakResult<Environment> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_environment_by_id(environment_id, &UpdateSource::from_window(&window))?)
}
@@ -1496,11 +1399,7 @@ async fn cmd_list_grpc_connections<R: Runtime>(
workspace_id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<GrpcConnection>> {
Ok(app_handle
.queries()
.connect()
.await?
.list_grpc_connections_for_workspace(workspace_id, None)?)
Ok(app_handle.db().list_grpc_connections_for_workspace(workspace_id, None)?)
}
#[tauri::command]
@@ -1508,7 +1407,7 @@ async fn cmd_list_grpc_events<R: Runtime>(
connection_id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<GrpcEvent>> {
Ok(app_handle.queries().connect().await?.list_grpc_events(connection_id)?)
Ok(app_handle.db().list_grpc_events(connection_id)?)
}
#[tauri::command]
@@ -1516,7 +1415,7 @@ async fn cmd_list_grpc_requests<R: Runtime>(
workspace_id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<GrpcRequest>> {
Ok(app_handle.queries().connect().await?.list_grpc_requests(workspace_id)?)
Ok(app_handle.db().list_grpc_requests(workspace_id)?)
}
#[tauri::command]
@@ -1524,7 +1423,7 @@ async fn cmd_list_http_requests<R: Runtime>(
workspace_id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<HttpRequest>> {
Ok(app_handle.queries().connect().await?.list_http_requests(workspace_id)?)
Ok(app_handle.db().list_http_requests(workspace_id)?)
}
#[tauri::command]
@@ -1533,14 +1432,14 @@ async fn cmd_list_environments<R: Runtime>(
app_handle: AppHandle<R>,
) -> YaakResult<Vec<Environment>> {
// Not sure of a better place to put this...
let db = app_handle.queries().connect().await?;
let db = app_handle.db();
db.ensure_base_environment(workspace_id)?;
Ok(db.list_environments(workspace_id)?)
}
#[tauri::command]
async fn cmd_list_plugins<R: Runtime>(app_handle: AppHandle<R>) -> YaakResult<Vec<Plugin>> {
Ok(app_handle.queries().connect().await?.list_plugins()?)
Ok(app_handle.db().list_plugins()?)
}
#[tauri::command]
@@ -1562,7 +1461,7 @@ async fn cmd_plugin_info<R: Runtime>(
app_handle: AppHandle<R>,
plugin_manager: State<'_, PluginManager>,
) -> YaakResult<BootResponse> {
let plugin = app_handle.queries().connect().await?.get_plugin(id)?;
let plugin = app_handle.db().get_plugin(id)?;
Ok(plugin_manager
.get_plugin_by_dir(plugin.directory.as_str())
.await
@@ -1573,11 +1472,7 @@ async fn cmd_plugin_info<R: Runtime>(
#[tauri::command]
async fn cmd_get_settings<R: Runtime>(window: WebviewWindow<R>) -> YaakResult<Settings> {
Ok(window
.queries()
.connect()
.await?
.get_or_create_settings(&UpdateSource::from_window(&window))?)
Ok(window.db().get_or_create_settings(&UpdateSource::from_window(&window)))
}
#[tauri::command]
@@ -1586,40 +1481,12 @@ async fn cmd_update_settings<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Settings> {
Ok(app_handle
.queries()
.connect()
.await?
.upsert_settings(&settings, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().upsert_settings(&settings, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
async fn cmd_get_folder<R: Runtime>(id: &str, app_handle: AppHandle<R>) -> YaakResult<Folder> {
Ok(app_handle.queries().connect().await?.get_folder(id)?)
}
#[tauri::command]
async fn cmd_get_grpc_request<R: Runtime>(
id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Option<GrpcRequest>> {
Ok(app_handle.queries().connect().await?.get_grpc_request(id)?)
}
#[tauri::command]
async fn cmd_get_http_request<R: Runtime>(
id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Option<HttpRequest>> {
Ok(app_handle.queries().connect().await?.get_http_request(id)?)
}
#[tauri::command]
async fn cmd_get_cookie_jar<R: Runtime>(
id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<CookieJar> {
Ok(app_handle.queries().connect().await?.get_cookie_jar(id)?)
Ok(app_handle.db().get_folder(id)?)
}
#[tauri::command]
@@ -1628,7 +1495,7 @@ async fn cmd_list_cookie_jars<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Vec<CookieJar>> {
let db = app_handle.queries().connect().await?;
let db = app_handle.db();
let cookie_jars = db.list_cookie_jars(workspace_id)?;
if cookie_jars.is_empty() {
@@ -1648,7 +1515,7 @@ async fn cmd_list_cookie_jars<R: Runtime>(
#[tauri::command]
async fn cmd_list_key_values<R: Runtime>(app_handle: AppHandle<R>) -> YaakResult<Vec<KeyValue>> {
Ok(app_handle.queries().connect().await?.list_key_values_raw()?)
Ok(app_handle.db().list_key_values_raw()?)
}
#[tauri::command]
@@ -1656,7 +1523,7 @@ async fn cmd_get_environment<R: Runtime>(
id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Environment> {
Ok(app_handle.queries().connect().await?.get_environment(id)?)
Ok(app_handle.db().get_environment(id)?)
}
#[tauri::command]
@@ -1664,7 +1531,7 @@ async fn cmd_get_workspace<R: Runtime>(
id: &str,
app_handle: AppHandle<R>,
) -> YaakResult<Workspace> {
Ok(app_handle.queries().connect().await?.get_workspace(id)?)
Ok(app_handle.db().get_workspace(id)?)
}
#[tauri::command]
@@ -1673,11 +1540,7 @@ async fn cmd_list_http_responses<R: Runtime>(
limit: Option<i64>,
app_handle: AppHandle<R>,
) -> YaakResult<Vec<HttpResponse>> {
Ok(app_handle
.queries()
.connect()
.await?
.list_http_responses_for_workspace(workspace_id, limit.map(|l| l as u64))?)
Ok(app_handle.db().list_http_responses_for_workspace(workspace_id, limit.map(|l| l as u64))?)
}
#[tauri::command]
@@ -1686,7 +1549,7 @@ async fn cmd_delete_http_response<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<HttpResponse> {
let db = app_handle.queries().connect().await?;
let db = app_handle.db();
let http_response = db.get_http_response(id)?;
Ok(db.delete_http_response(&http_response, &UpdateSource::from_window(&window))?)
}
@@ -1697,11 +1560,7 @@ async fn cmd_delete_grpc_connection<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<GrpcConnection> {
Ok(app_handle
.queries()
.connect()
.await?
.delete_grpc_connection_by_id(id, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().delete_grpc_connection_by_id(id, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1711,9 +1570,7 @@ async fn cmd_delete_all_grpc_connections<R: Runtime>(
window: WebviewWindow<R>,
) -> YaakResult<()> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_all_grpc_connections_for_request(request_id, &UpdateSource::from_window(&window))?)
}
@@ -1723,16 +1580,13 @@ async fn cmd_delete_send_history<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<()> {
Ok(app_handle
.queries()
.with_tx(|tx| {
let source = &UpdateSource::from_window(&window);
tx.delete_all_http_responses_for_workspace(workspace_id, source)?;
tx.delete_all_grpc_connections_for_workspace(workspace_id, source)?;
tx.delete_all_websocket_connections_for_workspace(workspace_id, source)?;
Ok(())
})
.await?)
Ok(app_handle.with_tx(|tx| {
let source = &UpdateSource::from_window(&window);
tx.delete_all_http_responses_for_workspace(workspace_id, source)?;
tx.delete_all_grpc_connections_for_workspace(workspace_id, source)?;
tx.delete_all_websocket_connections_for_workspace(workspace_id, source)?;
Ok(())
})?)
}
#[tauri::command]
@@ -1742,9 +1596,7 @@ async fn cmd_delete_all_http_responses<R: Runtime>(
window: WebviewWindow<R>,
) -> YaakResult<()> {
Ok(app_handle
.queries()
.connect()
.await?
.db()
.delete_all_http_responses_for_request(request_id, &UpdateSource::from_window(&window))?)
}
@@ -1753,7 +1605,7 @@ async fn cmd_list_workspaces<R: Runtime>(
app_handle: AppHandle<R>,
window: WebviewWindow<R>,
) -> YaakResult<Vec<Workspace>> {
let queries = app_handle.queries().connect().await?;
let queries = app_handle.db();
let workspaces = queries.find_all::<Workspace>()?;
if workspaces.is_empty() {
let workspace = queries.upsert_workspace(
@@ -1777,7 +1629,7 @@ async fn cmd_get_workspace_meta<R: Runtime>(
window: WebviewWindow<R>,
workspace_id: &str,
) -> YaakResult<WorkspaceMeta> {
let db = app_handle.queries().connect().await?;
let db = app_handle.db();
let workspace = db.get_workspace(workspace_id)?;
Ok(db.get_or_create_workspace_meta(&workspace, &UpdateSource::from_window(&window))?)
}
@@ -1806,11 +1658,7 @@ async fn cmd_delete_workspace<R: Runtime>(
window: WebviewWindow<R>,
workspace_id: &str,
) -> YaakResult<Workspace> {
Ok(app_handle
.queries()
.connect()
.await?
.delete_workspace_by_id(workspace_id, &UpdateSource::from_window(&window))?)
Ok(app_handle.db().delete_workspace_by_id(workspace_id, &UpdateSource::from_window(&window))?)
}
#[tauri::command]
@@ -1928,13 +1776,10 @@ pub fn run() {
cmd_export_data,
cmd_filter_response,
cmd_format_json,
cmd_get_cookie_jar,
cmd_get_environment,
cmd_get_folder,
cmd_get_grpc_request,
cmd_get_http_authentication_summaries,
cmd_get_http_authentication_config,
cmd_get_http_request,
cmd_get_key_value,
cmd_get_settings,
cmd_get_sse_events,
@@ -1996,7 +1841,7 @@ pub fn run() {
// Cancel pending requests
let h = app_handle.clone();
tauri::async_runtime::block_on(async move {
let db = h.queries().connect().await.unwrap();
let db = h.db();
let _ = db.cancel_pending_http_responses();
let _ = db.cancel_pending_grpc_connections();
let _ = db.cancel_pending_websocket_connections();
@@ -2046,11 +1891,7 @@ pub fn run() {
}
async fn get_update_mode<R: Runtime>(window: &WebviewWindow<R>) -> YaakResult<UpdateMode> {
let settings = window
.queries()
.connect()
.await?
.get_or_create_settings(&UpdateSource::from_window(window))?;
let settings = window.db().get_or_create_settings(&UpdateSource::from_window(window));
Ok(UpdateMode::new(settings.update_channel.as_str()))
}
@@ -2152,7 +1993,7 @@ fn workspace_id_from_window<R: Runtime>(window: &WebviewWindow<R>) -> Option<Str
async fn workspace_from_window<R: Runtime>(window: &WebviewWindow<R>) -> YaakResult<Workspace> {
match workspace_id_from_window(&window) {
None => Err(GenericError("Failed to get workspace ID from window".to_string())),
Some(id) => Ok(window.queries().connect().await?.get_workspace(id.as_str())?),
Some(id) => Ok(window.db().get_workspace(id.as_str())?),
}
}
@@ -2165,7 +2006,7 @@ fn environment_id_from_window<R: Runtime>(window: &WebviewWindow<R>) -> Option<S
async fn environment_from_window<R: Runtime>(window: &WebviewWindow<R>) -> Option<Environment> {
match environment_id_from_window(&window) {
None => None,
Some(id) => window.queries().connect().await.unwrap().get_environment(&id).ok(),
Some(id) => window.db().get_environment(&id).ok(),
}
}
@@ -2178,6 +2019,6 @@ fn cookie_jar_id_from_window<R: Runtime>(window: &WebviewWindow<R>) -> Option<St
async fn cookie_jar_from_window<R: Runtime>(window: &WebviewWindow<R>) -> Option<CookieJar> {
match cookie_jar_id_from_window(&window) {
None => None,
Some(id) => window.queries().connect().await.unwrap().get_cookie_jar(&id).ok(),
Some(id) => window.db().get_cookie_jar(&id).ok(),
}
}

View File

@@ -7,8 +7,8 @@ use reqwest::Method;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tauri::{AppHandle, Emitter, Manager, Runtime, WebviewWindow};
use yaak_models::manager::QueryManagerExt;
use yaak_models::queries_legacy::UpdateSource;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
// Check for updates every hour
const MAX_UPDATE_CHECK_SECONDS: u64 = 60 * 60;
@@ -54,7 +54,7 @@ impl YaakNotifier {
seen.push(id.to_string());
debug!("Marked notification as seen {}", id);
let seen_json = serde_json::to_string(&seen).map_err(|e| e.to_string())?;
window.queries().connect().await.map_err(|e| e.to_string())?.set_key_value_raw(
window.db().set_key_value_raw(
KV_NAMESPACE,
KV_KEY,
seen_json.as_str(),
@@ -118,13 +118,7 @@ impl YaakNotifier {
}
async fn get_kv<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Vec<String>, String> {
match app_handle
.queries()
.connect()
.await
.map_err(|e| e.to_string())?
.get_key_value_raw("notifications", "seen")
{
match app_handle.db().get_key_value_raw("notifications", "seen") {
None => Ok(Vec::new()),
Some(v) => serde_json::from_str(&v.value).map_err(|e| e.to_string()),
}

View File

@@ -9,9 +9,9 @@ use chrono::Utc;
use log::warn;
use tauri::{AppHandle, Emitter, Manager, Runtime, State};
use tauri_plugin_clipboard_manager::ClipboardExt;
use yaak_models::manager::QueryManagerExt;
use yaak_models::models::{HttpResponse, Plugin};
use yaak_models::queries_legacy::UpdateSource;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
use yaak_plugins::events::{
Color, DeleteKeyValueResponse, EmptyPayload, FindHttpResponsesResponse,
GetHttpRequestByIdResponse, GetKeyValueResponse, Icon, InternalEvent, InternalEventPayload,
@@ -53,10 +53,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
}
InternalEventPayload::FindHttpResponsesRequest(req) => {
let http_responses = app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.list_http_responses_for_request(
req.request_id.as_str(),
req.limit.map(|l| l as u64),
@@ -67,13 +64,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
}))
}
InternalEventPayload::GetHttpRequestByIdRequest(req) => {
let http_request = app_handle
.queries()
.connect()
.await
.unwrap()
.get_http_request(req.id.as_str())
.unwrap();
let http_request = app_handle.db().get_http_request(req.id.as_str()).ok();
Some(InternalEventPayload::GetHttpRequestByIdResponse(GetHttpRequestByIdResponse {
http_request,
}))
@@ -87,10 +78,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
.expect("Failed to get workspace_id from window URL");
let environment = environment_from_window(&window).await;
let base_environment = app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.get_base_environment(&workspace.id)
.expect("Failed to get base environment");
let cb = PluginTemplateCallback::new(app_handle, &window_context, req.purpose);
@@ -115,10 +103,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
.expect("Failed to get workspace_id from window URL");
let environment = environment_from_window(&window).await;
let base_environment = app_handle
.queries()
.connect()
.await
.unwrap()
.db()
.get_base_environment(&workspace.id)
.expect("Failed to get base environment");
let cb = PluginTemplateCallback::new(app_handle, &window_context, req.purpose);
@@ -149,7 +134,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
InternalEventPayload::ReloadResponse(_) => {
let window = get_window_from_window_context(app_handle, &window_context)
.expect("Failed to find window for plugin reload");
let plugins = app_handle.queries().connect().await.unwrap().list_plugins().unwrap();
let plugins = app_handle.db().list_plugins().unwrap();
for plugin in plugins {
if plugin.directory != plugin_handle.dir {
continue;
@@ -159,13 +144,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
updated_at: Utc::now().naive_utc(), // TODO: Add reloaded_at field to use instead
..plugin
};
app_handle
.queries()
.connect()
.await
.unwrap()
.upsert_plugin(&new_plugin, &UpdateSource::Plugin)
.unwrap();
app_handle.db().upsert_plugin(&new_plugin, &UpdateSource::Plugin).unwrap();
}
let toast_event = plugin_handle.build_event_to_send(
&WindowContext::from_window(&window),
@@ -197,10 +176,7 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
HttpResponse::default()
} else {
window
.queries()
.connect()
.await
.unwrap()
.db()
.upsert_http_response(
&HttpResponse {
request_id: http_request.id.clone(),
@@ -292,34 +268,17 @@ pub(crate) async fn handle_plugin_event<R: Runtime>(
}
InternalEventPayload::SetKeyValueRequest(req) => {
let name = plugin_handle.name().await;
app_handle
.queries()
.connect()
.await
.unwrap()
.set_plugin_key_value(&name, &req.key, &req.value);
app_handle.db().set_plugin_key_value(&name, &req.key, &req.value);
Some(InternalEventPayload::SetKeyValueResponse(SetKeyValueResponse {}))
}
InternalEventPayload::GetKeyValueRequest(req) => {
let name = plugin_handle.name().await;
let value = app_handle
.queries()
.connect()
.await
.unwrap()
.get_plugin_key_value(&name, &req.key)
.map(|v| v.value);
let value = app_handle.db().get_plugin_key_value(&name, &req.key).map(|v| v.value);
Some(InternalEventPayload::GetKeyValueResponse(GetKeyValueResponse { value }))
}
InternalEventPayload::DeleteKeyValueRequest(req) => {
let name = plugin_handle.name().await;
let deleted = app_handle
.queries()
.connect()
.await
.unwrap()
.delete_plugin_key_value(&name, &req.key)
.unwrap();
let deleted = app_handle.db().delete_plugin_key_value(&name, &req.key).unwrap();
Some(InternalEventPayload::DeleteKeyValueResponse(DeleteKeyValueResponse { deleted }))
}
_ => None,

View File

@@ -7,8 +7,8 @@ use tauri::{Manager, Runtime, WebviewWindow};
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons};
use tauri_plugin_updater::UpdaterExt;
use tokio::task::block_in_place;
use yaak_models::manager::QueryManagerExt;
use yaak_models::queries_legacy::UpdateSource;
use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::UpdateSource;
use yaak_plugins::manager::PluginManager;
use crate::is_dev;
@@ -67,11 +67,7 @@ impl YaakUpdater {
mode: UpdateMode,
update_trigger: UpdateTrigger,
) -> Result<bool> {
let settings = window
.queries()
.connect()
.await?
.get_or_create_settings(&UpdateSource::from_window(window))?;
let settings = window.db().get_or_create_settings(&UpdateSource::from_window(window));
let update_key = format!("{:x}", md5::compute(settings.id));
self.last_update_check = SystemTime::now();