mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:18:32 +02:00
db to app_handle!
This commit is contained in:
@@ -2,7 +2,6 @@ use log::{debug, warn};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::types::JsonValue;
|
use sqlx::types::JsonValue;
|
||||||
use sqlx::{Pool, Sqlite};
|
|
||||||
use tauri::{AppHandle, Manager};
|
use tauri::{AppHandle, Manager};
|
||||||
|
|
||||||
use crate::{is_dev, models};
|
use crate::{is_dev, models};
|
||||||
@@ -128,15 +127,16 @@ pub struct LaunchEventInfo {
|
|||||||
pub num_launches: i32,
|
pub num_launches: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn track_launch_event(app_handle: &AppHandle, db: &Pool<Sqlite>) -> LaunchEventInfo {
|
pub async fn track_launch_event(app_handle: &AppHandle) -> LaunchEventInfo {
|
||||||
let namespace = "analytics";
|
let namespace = "analytics";
|
||||||
let last_tracked_version_key = "last_tracked_version";
|
let last_tracked_version_key = "last_tracked_version";
|
||||||
|
|
||||||
let mut info = LaunchEventInfo::default();
|
let mut info = LaunchEventInfo::default();
|
||||||
|
|
||||||
info.num_launches = models::get_key_value_int(db, namespace, "num_launches", 0).await + 1;
|
info.num_launches =
|
||||||
|
models::get_key_value_int(app_handle, namespace, "num_launches", 0).await + 1;
|
||||||
info.previous_version =
|
info.previous_version =
|
||||||
models::get_key_value_string(db, namespace, last_tracked_version_key, "").await;
|
models::get_key_value_string(app_handle, namespace, last_tracked_version_key, "").await;
|
||||||
info.current_version = app_handle.package_info().version.to_string();
|
info.current_version = app_handle.package_info().version.to_string();
|
||||||
|
|
||||||
if info.previous_version.is_empty() {
|
if info.previous_version.is_empty() {
|
||||||
@@ -172,13 +172,13 @@ pub async fn track_launch_event(app_handle: &AppHandle, db: &Pool<Sqlite>) -> La
|
|||||||
// Update key values
|
// Update key values
|
||||||
|
|
||||||
models::set_key_value_string(
|
models::set_key_value_string(
|
||||||
db,
|
app_handle,
|
||||||
namespace,
|
namespace,
|
||||||
last_tracked_version_key,
|
last_tracked_version_key,
|
||||||
info.current_version.as_str(),
|
info.current_version.as_str(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
models::set_key_value_int(db, namespace, "num_launches", info.num_launches).await;
|
models::set_key_value_int(app_handle, namespace, "num_launches", info.num_launches).await;
|
||||||
|
|
||||||
info
|
info
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,12 @@ use log::{error, info, warn};
|
|||||||
use reqwest::redirect::Policy;
|
use reqwest::redirect::Policy;
|
||||||
use reqwest::{multipart, Url};
|
use reqwest::{multipart, Url};
|
||||||
use sqlx::types::{Json, JsonValue};
|
use sqlx::types::{Json, JsonValue};
|
||||||
use sqlx::{Pool, Sqlite};
|
use tauri::AppHandle;
|
||||||
use tauri::{AppHandle, Wry};
|
|
||||||
|
|
||||||
use crate::{emit_side_effect, models, render, response_err};
|
use crate::{emit_side_effect, models, render, response_err};
|
||||||
|
|
||||||
pub async fn send_http_request(
|
pub async fn send_http_request(
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: &AppHandle,
|
||||||
db: &Pool<Sqlite>,
|
|
||||||
request: models::HttpRequest,
|
request: models::HttpRequest,
|
||||||
response: &models::HttpResponse,
|
response: &models::HttpResponse,
|
||||||
environment: Option<models::Environment>,
|
environment: Option<models::Environment>,
|
||||||
@@ -28,7 +26,7 @@ pub async fn send_http_request(
|
|||||||
download_path: Option<PathBuf>,
|
download_path: Option<PathBuf>,
|
||||||
) -> Result<models::HttpResponse, String> {
|
) -> Result<models::HttpResponse, String> {
|
||||||
let environment_ref = environment.as_ref();
|
let environment_ref = environment.as_ref();
|
||||||
let workspace = models::get_workspace(db, &request.workspace_id)
|
let workspace = models::get_workspace(app_handle, &request.workspace_id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get Workspace");
|
.expect("Failed to get Workspace");
|
||||||
|
|
||||||
@@ -88,7 +86,7 @@ pub async fn send_http_request(
|
|||||||
let url = match Url::from_str(url_string.as_str()) {
|
let url = match Url::from_str(url_string.as_str()) {
|
||||||
Ok(u) => u,
|
Ok(u) => u,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return response_err(response, e.to_string(), app_handle.clone(), db).await;
|
return response_err(response, e.to_string(), app_handle).await;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -293,7 +291,7 @@ pub async fn send_http_request(
|
|||||||
let sendable_req = match request_builder.build() {
|
let sendable_req = match request_builder.build() {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return response_err(response, e.to_string(), app_handle.clone(), db).await;
|
return response_err(response, e.to_string(), app_handle).await;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,11 +360,11 @@ pub async fn send_http_request(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
response = models::update_response_if_id(db, &response)
|
response = models::update_response_if_id(app_handle, &response)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update response");
|
.expect("Failed to update response");
|
||||||
if !request.id.is_empty() {
|
if !request.id.is_empty() {
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", &response);
|
emit_side_effect(app_handle, "upserted_model", &response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy response to download path, if specified
|
// Copy response to download path, if specified
|
||||||
@@ -397,7 +395,7 @@ pub async fn send_http_request(
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
cookie_jar.cookies = json_cookies;
|
cookie_jar.cookies = json_cookies;
|
||||||
match models::upsert_cookie_jar(db, &cookie_jar).await {
|
match models::upsert_cookie_jar(&app_handle, &cookie_jar).await {
|
||||||
Ok(updated_jar) => {
|
Ok(updated_jar) => {
|
||||||
emit_side_effect(app_handle, "upserted_model", &updated_jar);
|
emit_side_effect(app_handle, "upserted_model", &updated_jar);
|
||||||
}
|
}
|
||||||
@@ -409,6 +407,6 @@ pub async fn send_http_request(
|
|||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
Err(e) => response_err(response, e.to_string(), app_handle, db).await,
|
Err(e) => response_err(response, e.to_string(), app_handle).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ pub struct CustomResponse {
|
|||||||
pub status_reason: Option<&'static str>,
|
pub status_reason: Option<&'static str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn migrate_db(app_handle: AppHandle<Wry>, db: &Mutex<Pool<Sqlite>>) -> Result<(), String> {
|
async fn migrate_db(app_handle: AppHandle, db: &Mutex<Pool<Sqlite>>) -> Result<(), String> {
|
||||||
let pool = &*db.lock().await;
|
let pool = &*db.lock().await;
|
||||||
let p = app_handle
|
let p = app_handle
|
||||||
.path_resolver()
|
.path_resolver()
|
||||||
@@ -100,7 +100,7 @@ async fn cmd_grpc_reflect(endpoint: &str) -> Result<Vec<ServiceDefinition>, Stri
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_grpc_call_unary(
|
async fn cmd_grpc_call_unary(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
||||||
) -> Result<GrpcMessage, String> {
|
) -> Result<GrpcMessage, String> {
|
||||||
let req = get_grpc_request(&app_handle, request_id)
|
let req = get_grpc_request(&app_handle, request_id)
|
||||||
@@ -119,7 +119,7 @@ async fn cmd_grpc_call_unary(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", conn.clone());
|
emit_side_effect(&app_handle, "upserted_model", conn.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
let req = req.clone();
|
let req = req.clone();
|
||||||
@@ -176,7 +176,7 @@ async fn cmd_grpc_call_unary(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_grpc_client_streaming(
|
async fn cmd_grpc_client_streaming(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
) -> Result<GrpcConnection, String> {
|
) -> Result<GrpcConnection, String> {
|
||||||
let req = get_grpc_request(&app_handle, request_id)
|
let req = get_grpc_request(&app_handle, request_id)
|
||||||
.await
|
.await
|
||||||
@@ -194,7 +194,7 @@ async fn cmd_grpc_client_streaming(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", conn.clone());
|
emit_side_effect(&app_handle, "upserted_model", conn.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
let conn = conn.clone();
|
let conn = conn.clone();
|
||||||
@@ -369,7 +369,7 @@ async fn cmd_grpc_client_streaming(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_grpc_streaming(
|
async fn cmd_grpc_streaming(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
let req = get_grpc_request(&app_handle, request_id)
|
let req = get_grpc_request(&app_handle, request_id)
|
||||||
@@ -388,7 +388,7 @@ async fn cmd_grpc_streaming(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", conn.clone());
|
emit_side_effect(&app_handle, "upserted_model", conn.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
let conn = conn.clone();
|
let conn = conn.clone();
|
||||||
@@ -565,7 +565,7 @@ async fn cmd_grpc_streaming(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_grpc_server_streaming(
|
async fn cmd_grpc_server_streaming(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
grpc_handle: State<'_, Mutex<GrpcManager>>,
|
||||||
) -> Result<GrpcConnection, String> {
|
) -> Result<GrpcConnection, String> {
|
||||||
let req = get_grpc_request(&app_handle, request_id)
|
let req = get_grpc_request(&app_handle, request_id)
|
||||||
@@ -585,7 +585,7 @@ async fn cmd_grpc_server_streaming(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?
|
.map_err(|e| e.to_string())?
|
||||||
};
|
};
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", conn.clone());
|
emit_side_effect(&app_handle, "upserted_model", conn.clone());
|
||||||
|
|
||||||
{
|
{
|
||||||
let req = req.clone();
|
let req = req.clone();
|
||||||
@@ -734,15 +734,13 @@ async fn cmd_send_ephemeral_request(
|
|||||||
mut request: HttpRequest,
|
mut request: HttpRequest,
|
||||||
environment_id: Option<&str>,
|
environment_id: Option<&str>,
|
||||||
cookie_jar_id: Option<&str>,
|
cookie_jar_id: Option<&str>,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
) -> Result<HttpResponse, String> {
|
) -> Result<HttpResponse, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let response = HttpResponse::new();
|
let response = HttpResponse::new();
|
||||||
request.id = "".to_string();
|
request.id = "".to_string();
|
||||||
let environment = match environment_id {
|
let environment = match environment_id {
|
||||||
Some(id) => Some(
|
Some(id) => Some(
|
||||||
get_environment(db, id)
|
get_environment(&app_handle, id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get environment"),
|
.expect("Failed to get environment"),
|
||||||
),
|
),
|
||||||
@@ -750,7 +748,7 @@ async fn cmd_send_ephemeral_request(
|
|||||||
};
|
};
|
||||||
let cookie_jar = match cookie_jar_id {
|
let cookie_jar = match cookie_jar_id {
|
||||||
Some(id) => Some(
|
Some(id) => Some(
|
||||||
get_cookie_jar(db, id)
|
get_cookie_jar(&app_handle, id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get cookie jar"),
|
.expect("Failed to get cookie jar"),
|
||||||
),
|
),
|
||||||
@@ -759,8 +757,7 @@ async fn cmd_send_ephemeral_request(
|
|||||||
|
|
||||||
// let cookie_jar_id2 = cookie_jar_id.unwrap_or("").to_string();
|
// let cookie_jar_id2 = cookie_jar_id.unwrap_or("").to_string();
|
||||||
send_http_request(
|
send_http_request(
|
||||||
app_handle,
|
&app_handle,
|
||||||
db,
|
|
||||||
request,
|
request,
|
||||||
&response,
|
&response,
|
||||||
environment,
|
environment,
|
||||||
@@ -773,12 +770,11 @@ async fn cmd_send_ephemeral_request(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_filter_response(
|
async fn cmd_filter_response(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
response_id: &str,
|
response_id: &str,
|
||||||
filter: &str,
|
filter: &str,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
let db = &*db_state.lock().await;
|
let response = get_response(&app_handle, response_id)
|
||||||
let response = get_response(db, response_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get response");
|
.expect("Failed to get response");
|
||||||
|
|
||||||
@@ -811,10 +807,9 @@ async fn cmd_filter_response(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_import_data(
|
async fn cmd_import_data(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
file_paths: Vec<&str>,
|
file_paths: Vec<&str>,
|
||||||
) -> Result<ImportResources, String> {
|
) -> Result<ImportResources, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let mut result: Option<ImportResult> = None;
|
let mut result: Option<ImportResult> = None;
|
||||||
let plugins = vec!["importer-yaak", "importer-insomnia", "importer-postman"];
|
let plugins = vec!["importer-yaak", "importer-insomnia", "importer-postman"];
|
||||||
for plugin_name in plugins {
|
for plugin_name in plugins {
|
||||||
@@ -844,7 +839,7 @@ async fn cmd_import_data(
|
|||||||
|
|
||||||
info!("Importing resources");
|
info!("Importing resources");
|
||||||
for w in r.resources.workspaces {
|
for w in r.resources.workspaces {
|
||||||
let x = upsert_workspace(db, w)
|
let x = upsert_workspace(&app_handle, w)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create workspace");
|
.expect("Failed to create workspace");
|
||||||
imported_resources.workspaces.push(x.clone());
|
imported_resources.workspaces.push(x.clone());
|
||||||
@@ -852,7 +847,7 @@ async fn cmd_import_data(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for e in r.resources.environments {
|
for e in r.resources.environments {
|
||||||
let x = upsert_environment(db, e)
|
let x = upsert_environment(&app_handle, e)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create environment");
|
.expect("Failed to create environment");
|
||||||
imported_resources.environments.push(x.clone());
|
imported_resources.environments.push(x.clone());
|
||||||
@@ -860,13 +855,15 @@ async fn cmd_import_data(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for f in r.resources.folders {
|
for f in r.resources.folders {
|
||||||
let x = upsert_folder(db, f).await.expect("Failed to create folder");
|
let x = upsert_folder(&app_handle, f)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create folder");
|
||||||
imported_resources.folders.push(x.clone());
|
imported_resources.folders.push(x.clone());
|
||||||
info!("Imported folder: {}", x.name);
|
info!("Imported folder: {}", x.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for r in r.resources.requests {
|
for r in r.resources.requests {
|
||||||
let x = upsert_http_request(db, r)
|
let x = upsert_http_request(&app_handle, r)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create request");
|
.expect("Failed to create request");
|
||||||
imported_resources.requests.push(x.clone());
|
imported_resources.requests.push(x.clone());
|
||||||
@@ -880,13 +877,11 @@ async fn cmd_import_data(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_export_data(
|
async fn cmd_export_data(
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
export_path: &str,
|
export_path: &str,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let db = &*db_state.lock().await;
|
let export_data = get_workspace_export_resources(&app_handle, workspace_id).await;
|
||||||
let export_data = get_workspace_export_resources(&app_handle, db, workspace_id).await;
|
|
||||||
let f = File::options()
|
let f = File::options()
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
@@ -912,22 +907,19 @@ async fn cmd_export_data(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_send_request(
|
async fn cmd_send_request(
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
environment_id: Option<&str>,
|
environment_id: Option<&str>,
|
||||||
cookie_jar_id: Option<&str>,
|
cookie_jar_id: Option<&str>,
|
||||||
download_dir: Option<&str>,
|
download_dir: Option<&str>,
|
||||||
) -> Result<HttpResponse, String> {
|
) -> Result<HttpResponse, String> {
|
||||||
let db = &*db_state.lock().await;
|
let request = get_http_request(&app_handle, request_id)
|
||||||
|
|
||||||
let request = get_http_request(db, request_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get request");
|
.expect("Failed to get request");
|
||||||
|
|
||||||
let environment = match environment_id {
|
let environment = match environment_id {
|
||||||
Some(id) => Some(
|
Some(id) => Some(
|
||||||
get_environment(db, id)
|
get_environment(&app_handle, id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get environment"),
|
.expect("Failed to get environment"),
|
||||||
),
|
),
|
||||||
@@ -936,7 +928,7 @@ async fn cmd_send_request(
|
|||||||
|
|
||||||
let cookie_jar = match cookie_jar_id {
|
let cookie_jar = match cookie_jar_id {
|
||||||
Some(id) => Some(
|
Some(id) => Some(
|
||||||
get_cookie_jar(db, id)
|
get_cookie_jar(&app_handle, id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get cookie jar"),
|
.expect("Failed to get cookie jar"),
|
||||||
),
|
),
|
||||||
@@ -944,7 +936,7 @@ async fn cmd_send_request(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let response = create_response(
|
let response = create_response(
|
||||||
db,
|
&app_handle,
|
||||||
&request.id,
|
&request.id,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -966,11 +958,10 @@ async fn cmd_send_request(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
emit_side_effect(app_handle.clone(), "upserted_model", response.clone());
|
emit_side_effect(&app_handle, "upserted_model", response.clone());
|
||||||
|
|
||||||
send_http_request(
|
send_http_request(
|
||||||
app_handle,
|
&app_handle,
|
||||||
db,
|
|
||||||
request.clone(),
|
request.clone(),
|
||||||
&response,
|
&response,
|
||||||
environment,
|
environment,
|
||||||
@@ -983,16 +974,15 @@ async fn cmd_send_request(
|
|||||||
async fn response_err(
|
async fn response_err(
|
||||||
response: &HttpResponse,
|
response: &HttpResponse,
|
||||||
error: String,
|
error: String,
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: &AppHandle,
|
||||||
db: &Pool<Sqlite>,
|
|
||||||
) -> Result<HttpResponse, String> {
|
) -> Result<HttpResponse, String> {
|
||||||
let mut response = response.clone();
|
let mut response = response.clone();
|
||||||
response.elapsed = -1;
|
response.elapsed = -1;
|
||||||
response.error = Some(error.clone());
|
response.error = Some(error.clone());
|
||||||
response = update_response_if_id(db, &response)
|
response = update_response_if_id(&app_handle, &response)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update response");
|
.expect("Failed to update response");
|
||||||
emit_side_effect(app_handle, "upserted_model", &response);
|
emit_side_effect(&app_handle, "upserted_model", &response);
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1022,19 +1012,18 @@ async fn cmd_track_event(
|
|||||||
async fn cmd_set_update_mode(
|
async fn cmd_set_update_mode(
|
||||||
update_mode: &str,
|
update_mode: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<KeyValue, String> {
|
) -> Result<KeyValue, String> {
|
||||||
cmd_set_key_value("app", "update_mode", update_mode, window, db_state).await
|
cmd_set_key_value("app", "update_mode", update_mode, window, app_handle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_key_value(
|
async fn cmd_get_key_value(
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Option<KeyValue>, ()> {
|
) -> Result<Option<KeyValue>, ()> {
|
||||||
let db = &*db_state.lock().await;
|
let result = get_key_value_raw(&app_handle, namespace, key).await;
|
||||||
let result = get_key_value_raw(db, namespace, key).await;
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1044,10 +1033,9 @@ async fn cmd_set_key_value(
|
|||||||
key: &str,
|
key: &str,
|
||||||
value: &str,
|
value: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<KeyValue, String> {
|
) -> Result<KeyValue, String> {
|
||||||
let db = &*db_state.lock().await;
|
let (key_value, created) = set_key_value_raw(&app_handle, namespace, key, value).await;
|
||||||
let (key_value, created) = set_key_value_raw(db, namespace, key, value).await;
|
|
||||||
|
|
||||||
if created {
|
if created {
|
||||||
emit_and_return(&window, "upserted_model", key_value)
|
emit_and_return(&window, "upserted_model", key_value)
|
||||||
@@ -1060,10 +1048,9 @@ async fn cmd_set_key_value(
|
|||||||
async fn cmd_create_workspace(
|
async fn cmd_create_workspace(
|
||||||
name: &str,
|
name: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Workspace, String> {
|
) -> Result<Workspace, String> {
|
||||||
let db = &*db_state.lock().await;
|
let created_workspace = upsert_workspace(&app_handle, Workspace::new(name.to_string()))
|
||||||
let created_workspace = upsert_workspace(db, Workspace::new(name.to_string()))
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create Workspace");
|
.expect("Failed to create Workspace");
|
||||||
|
|
||||||
@@ -1074,11 +1061,9 @@ async fn cmd_create_workspace(
|
|||||||
async fn cmd_update_cookie_jar(
|
async fn cmd_update_cookie_jar(
|
||||||
cookie_jar: CookieJar,
|
cookie_jar: CookieJar,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<CookieJar, String> {
|
) -> Result<CookieJar, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated = upsert_cookie_jar(&app_handle, &cookie_jar)
|
||||||
|
|
||||||
let updated = upsert_cookie_jar(db, &cookie_jar)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update cookie jar");
|
.expect("Failed to update cookie jar");
|
||||||
|
|
||||||
@@ -1088,11 +1073,10 @@ async fn cmd_update_cookie_jar(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_cookie_jar(
|
async fn cmd_delete_cookie_jar(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
cookie_jar_id: &str,
|
cookie_jar_id: &str,
|
||||||
) -> Result<CookieJar, String> {
|
) -> Result<CookieJar, String> {
|
||||||
let db = &*db_state.lock().await;
|
let req = delete_cookie_jar(&app_handle, cookie_jar_id)
|
||||||
let req = delete_cookie_jar(db, cookie_jar_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete cookie jar");
|
.expect("Failed to delete cookie jar");
|
||||||
emit_and_return(&window, "deleted_model", req)
|
emit_and_return(&window, "deleted_model", req)
|
||||||
@@ -1103,11 +1087,10 @@ async fn cmd_create_cookie_jar(
|
|||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
name: &str,
|
name: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<CookieJar, String> {
|
) -> Result<CookieJar, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let created_cookie_jar = upsert_cookie_jar(
|
let created_cookie_jar = upsert_cookie_jar(
|
||||||
db,
|
&app_handle,
|
||||||
&CookieJar {
|
&CookieJar {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
@@ -1126,11 +1109,10 @@ async fn cmd_create_environment(
|
|||||||
name: &str,
|
name: &str,
|
||||||
variables: Vec<EnvironmentVariable>,
|
variables: Vec<EnvironmentVariable>,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Environment, String> {
|
) -> Result<Environment, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let created_environment = upsert_environment(
|
let created_environment = upsert_environment(
|
||||||
db,
|
&app_handle,
|
||||||
Environment {
|
Environment {
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
@@ -1188,11 +1170,10 @@ async fn cmd_create_http_request(
|
|||||||
sort_priority: f64,
|
sort_priority: f64,
|
||||||
folder_id: Option<&str>,
|
folder_id: Option<&str>,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<HttpRequest, String> {
|
) -> Result<HttpRequest, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let created_request = upsert_http_request(
|
let created_request = upsert_http_request(
|
||||||
db,
|
&app_handle,
|
||||||
HttpRequest {
|
HttpRequest {
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
@@ -1212,10 +1193,9 @@ async fn cmd_create_http_request(
|
|||||||
async fn cmd_duplicate_http_request(
|
async fn cmd_duplicate_http_request(
|
||||||
id: &str,
|
id: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<HttpRequest, String> {
|
) -> Result<HttpRequest, String> {
|
||||||
let db = &*db_state.lock().await;
|
let request = duplicate_http_request(&app_handle, id)
|
||||||
let request = duplicate_http_request(db, id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to duplicate http request");
|
.expect("Failed to duplicate http request");
|
||||||
emit_and_return(&window, "upserted_model", request)
|
emit_and_return(&window, "upserted_model", request)
|
||||||
@@ -1225,10 +1205,9 @@ async fn cmd_duplicate_http_request(
|
|||||||
async fn cmd_update_workspace(
|
async fn cmd_update_workspace(
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Workspace, String> {
|
) -> Result<Workspace, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated_workspace = upsert_workspace(&app_handle, workspace)
|
||||||
let updated_workspace = upsert_workspace(db, workspace)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update request");
|
.expect("Failed to update request");
|
||||||
|
|
||||||
@@ -1239,10 +1218,9 @@ async fn cmd_update_workspace(
|
|||||||
async fn cmd_update_environment(
|
async fn cmd_update_environment(
|
||||||
environment: Environment,
|
environment: Environment,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Environment, String> {
|
) -> Result<Environment, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated_environment = upsert_environment(&app_handle, environment)
|
||||||
let updated_environment = upsert_environment(db, environment)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update environment");
|
.expect("Failed to update environment");
|
||||||
|
|
||||||
@@ -1265,10 +1243,9 @@ async fn cmd_update_grpc_request(
|
|||||||
async fn cmd_update_http_request(
|
async fn cmd_update_http_request(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<HttpRequest, String> {
|
) -> Result<HttpRequest, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated_request = upsert_http_request(&app_handle, request)
|
||||||
let updated_request = upsert_http_request(db, request)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update request");
|
.expect("Failed to update request");
|
||||||
emit_and_return(&window, "upserted_model", updated_request)
|
emit_and_return(&window, "upserted_model", updated_request)
|
||||||
@@ -1277,11 +1254,10 @@ async fn cmd_update_http_request(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_grpc_request(
|
async fn cmd_delete_grpc_request(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
) -> Result<HttpRequest, String> {
|
) -> Result<HttpRequest, String> {
|
||||||
let db = &*db_state.lock().await;
|
let req = delete_request(&app_handle, request_id)
|
||||||
let req = delete_request(db, request_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete request");
|
.expect("Failed to delete request");
|
||||||
emit_and_return(&window, "deleted_model", req)
|
emit_and_return(&window, "deleted_model", req)
|
||||||
@@ -1290,11 +1266,10 @@ async fn cmd_delete_grpc_request(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_http_request(
|
async fn cmd_delete_http_request(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
) -> Result<HttpRequest, String> {
|
) -> Result<HttpRequest, String> {
|
||||||
let db = &*db_state.lock().await;
|
let req = delete_request(&app_handle, request_id)
|
||||||
let req = delete_request(db, request_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete request");
|
.expect("Failed to delete request");
|
||||||
emit_and_return(&window, "deleted_model", req)
|
emit_and_return(&window, "deleted_model", req)
|
||||||
@@ -1303,10 +1278,9 @@ async fn cmd_delete_http_request(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_folders(
|
async fn cmd_list_folders(
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<Folder>, String> {
|
) -> Result<Vec<Folder>, String> {
|
||||||
let db = &*db_state.lock().await;
|
list_folders(&app_handle, workspace_id)
|
||||||
list_folders(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -1318,11 +1292,10 @@ async fn cmd_create_folder(
|
|||||||
sort_priority: f64,
|
sort_priority: f64,
|
||||||
folder_id: Option<&str>,
|
folder_id: Option<&str>,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Folder, String> {
|
) -> Result<Folder, String> {
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let created_request = upsert_folder(
|
let created_request = upsert_folder(
|
||||||
db,
|
&app_handle,
|
||||||
Folder {
|
Folder {
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
@@ -1341,10 +1314,9 @@ async fn cmd_create_folder(
|
|||||||
async fn cmd_update_folder(
|
async fn cmd_update_folder(
|
||||||
folder: Folder,
|
folder: Folder,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Folder, String> {
|
) -> Result<Folder, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated_folder = upsert_folder(&app_handle, folder)
|
||||||
let updated_folder = upsert_folder(db, folder)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update request");
|
.expect("Failed to update request");
|
||||||
emit_and_return(&window, "upserted_model", updated_folder)
|
emit_and_return(&window, "upserted_model", updated_folder)
|
||||||
@@ -1353,11 +1325,10 @@ async fn cmd_update_folder(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_folder(
|
async fn cmd_delete_folder(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
folder_id: &str,
|
folder_id: &str,
|
||||||
) -> Result<Folder, String> {
|
) -> Result<Folder, String> {
|
||||||
let db = &*db_state.lock().await;
|
let req = delete_folder(&app_handle, folder_id)
|
||||||
let req = delete_folder(db, folder_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete folder");
|
.expect("Failed to delete folder");
|
||||||
emit_and_return(&window, "deleted_model", req)
|
emit_and_return(&window, "deleted_model", req)
|
||||||
@@ -1366,11 +1337,10 @@ async fn cmd_delete_folder(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_environment(
|
async fn cmd_delete_environment(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
environment_id: &str,
|
environment_id: &str,
|
||||||
) -> Result<Environment, String> {
|
) -> Result<Environment, String> {
|
||||||
let db = &*db_state.lock().await;
|
let req = delete_environment(&app_handle, environment_id)
|
||||||
let req = delete_environment(db, environment_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete environment");
|
.expect("Failed to delete environment");
|
||||||
emit_and_return(&window, "deleted_model", req)
|
emit_and_return(&window, "deleted_model", req)
|
||||||
@@ -1379,10 +1349,9 @@ async fn cmd_delete_environment(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_grpc_connections(
|
async fn cmd_list_grpc_connections(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<GrpcConnection>, String> {
|
) -> Result<Vec<GrpcConnection>, String> {
|
||||||
let db = &*db_state.lock().await;
|
list_grpc_connections(&app_handle, request_id)
|
||||||
list_grpc_connections(db, request_id)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -1390,10 +1359,9 @@ async fn cmd_list_grpc_connections(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_grpc_messages(
|
async fn cmd_list_grpc_messages(
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<GrpcMessage>, String> {
|
) -> Result<Vec<GrpcMessage>, String> {
|
||||||
let db = &*db_state.lock().await;
|
list_grpc_messages(&app_handle, connection_id)
|
||||||
list_grpc_messages(db, connection_id)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -1401,10 +1369,9 @@ async fn cmd_list_grpc_messages(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_grpc_requests(
|
async fn cmd_list_grpc_requests(
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<GrpcRequest>, String> {
|
) -> Result<Vec<GrpcRequest>, String> {
|
||||||
let db = &*db_state.lock().await;
|
let requests = list_grpc_requests(&app_handle, workspace_id)
|
||||||
let requests = list_grpc_requests(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
Ok(requests)
|
Ok(requests)
|
||||||
@@ -1413,10 +1380,9 @@ async fn cmd_list_grpc_requests(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_http_requests(
|
async fn cmd_list_http_requests(
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<HttpRequest>, String> {
|
) -> Result<Vec<HttpRequest>, String> {
|
||||||
let db = &*db_state.lock().await;
|
let requests = list_requests(&app_handle, workspace_id)
|
||||||
let requests = list_requests(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find requests");
|
.expect("Failed to find requests");
|
||||||
// .map_err(|e| e.to_string())
|
// .map_err(|e| e.to_string())
|
||||||
@@ -1426,10 +1392,9 @@ async fn cmd_list_http_requests(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_environments(
|
async fn cmd_list_environments(
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<Environment>, String> {
|
) -> Result<Vec<Environment>, String> {
|
||||||
let db = &*db_state.lock().await;
|
let environments = list_environments(&app_handle, workspace_id)
|
||||||
let environments = list_environments(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find environments");
|
.expect("Failed to find environments");
|
||||||
|
|
||||||
@@ -1437,19 +1402,17 @@ async fn cmd_list_environments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_settings(db_state: State<'_, Mutex<Pool<Sqlite>>>) -> Result<Settings, ()> {
|
async fn cmd_get_settings(app_handle: AppHandle) -> Result<Settings, ()> {
|
||||||
let db = &*db_state.lock().await;
|
Ok(get_or_create_settings(&app_handle).await)
|
||||||
Ok(get_or_create_settings(db).await)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_update_settings(
|
async fn cmd_update_settings(
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Settings, String> {
|
) -> Result<Settings, String> {
|
||||||
let db = &*db_state.lock().await;
|
let updated_settings = update_settings(&app_handle, settings)
|
||||||
let updated_settings = update_settings(db, settings)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to update settings");
|
.expect("Failed to update settings");
|
||||||
|
|
||||||
@@ -1457,52 +1420,43 @@ async fn cmd_update_settings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_folder(
|
async fn cmd_get_folder(id: &str, app_handle: AppHandle) -> Result<Folder, String> {
|
||||||
id: &str,
|
get_folder(&app_handle, id).await.map_err(|e| e.to_string())
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
) -> Result<Folder, String> {
|
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
get_folder(db, id).await.map_err(|e| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_grpc_request(id: &str, app_handle: AppHandle<Wry>) -> Result<GrpcRequest, String> {
|
async fn cmd_get_grpc_request(id: &str, app_handle: AppHandle) -> Result<GrpcRequest, String> {
|
||||||
get_grpc_request(&app_handle, id)
|
get_grpc_request(&app_handle, id)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_http_request(
|
async fn cmd_get_http_request(id: &str, app_handle: AppHandle) -> Result<HttpRequest, String> {
|
||||||
id: &str,
|
get_http_request(&app_handle, id)
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
.await
|
||||||
) -> Result<HttpRequest, String> {
|
.map_err(|e| e.to_string())
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
get_http_request(db, id).await.map_err(|e| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_cookie_jar(
|
async fn cmd_get_cookie_jar(id: &str, app_handle: AppHandle) -> Result<CookieJar, String> {
|
||||||
id: &str,
|
get_cookie_jar(&app_handle, id)
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
.await
|
||||||
) -> Result<CookieJar, String> {
|
.map_err(|e| e.to_string())
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
get_cookie_jar(db, id).await.map_err(|e| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_cookie_jars(
|
async fn cmd_list_cookie_jars(
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<CookieJar>, String> {
|
) -> Result<Vec<CookieJar>, String> {
|
||||||
let db = &*db_state.lock().await;
|
let cookie_jars = list_cookie_jars(&app_handle, workspace_id)
|
||||||
let cookie_jars = list_cookie_jars(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find cookie jars");
|
.expect("Failed to find cookie jars");
|
||||||
|
|
||||||
if cookie_jars.is_empty() {
|
if cookie_jars.is_empty() {
|
||||||
let cookie_jar = upsert_cookie_jar(
|
let cookie_jar = upsert_cookie_jar(
|
||||||
db,
|
&app_handle,
|
||||||
&CookieJar {
|
&CookieJar {
|
||||||
name: "Default".to_string(),
|
name: "Default".to_string(),
|
||||||
workspace_id: workspace_id.to_string(),
|
workspace_id: workspace_id.to_string(),
|
||||||
@@ -1518,31 +1472,26 @@ async fn cmd_list_cookie_jars(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_environment(
|
async fn cmd_get_environment(id: &str, app_handle: AppHandle) -> Result<Environment, String> {
|
||||||
id: &str,
|
get_environment(&app_handle, id)
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
.await
|
||||||
) -> Result<Environment, String> {
|
.map_err(|e| e.to_string())
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
get_environment(db, id).await.map_err(|e| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_workspace(
|
async fn cmd_get_workspace(id: &str, app_handle: AppHandle) -> Result<Workspace, String> {
|
||||||
id: &str,
|
get_workspace(&app_handle, id)
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
.await
|
||||||
) -> Result<Workspace, String> {
|
.map_err(|e| e.to_string())
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
get_workspace(db, id).await.map_err(|e| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_http_responses(
|
async fn cmd_list_http_responses(
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<Vec<HttpResponse>, String> {
|
) -> Result<Vec<HttpResponse>, String> {
|
||||||
let db = &*db_state.lock().await;
|
list_responses(&app_handle, request_id, limit)
|
||||||
list_responses(db, request_id, limit)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -1551,37 +1500,29 @@ async fn cmd_list_http_responses(
|
|||||||
async fn cmd_delete_response(
|
async fn cmd_delete_response(
|
||||||
id: &str,
|
id: &str,
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
) -> Result<HttpResponse, String> {
|
) -> Result<HttpResponse, String> {
|
||||||
let db = &*db_state.lock().await;
|
let response = delete_response(&app_handle, id)
|
||||||
let response = delete_response(db, id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete response");
|
.expect("Failed to delete response");
|
||||||
emit_and_return(&window, "deleted_model", response)
|
emit_and_return(&window, "deleted_model", response)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_all_responses(
|
async fn cmd_delete_all_responses(request_id: &str, app_handle: AppHandle) -> Result<(), String> {
|
||||||
request_id: &str,
|
delete_all_responses(&app_handle, request_id)
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
delete_all_responses(db, request_id)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_list_workspaces(
|
async fn cmd_list_workspaces(app_handle: AppHandle) -> Result<Vec<Workspace>, String> {
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
let workspaces = list_workspaces(&app_handle)
|
||||||
) -> Result<Vec<Workspace>, String> {
|
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let workspaces = list_workspaces(db)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find workspaces");
|
.expect("Failed to find workspaces");
|
||||||
if workspaces.is_empty() {
|
if workspaces.is_empty() {
|
||||||
let workspace = upsert_workspace(
|
let workspace = upsert_workspace(
|
||||||
db,
|
&app_handle,
|
||||||
Workspace {
|
Workspace {
|
||||||
name: "Yaak".to_string(),
|
name: "Yaak".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -1604,11 +1545,10 @@ async fn cmd_new_window(window: Window<Wry>, url: &str) -> Result<(), String> {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_delete_workspace(
|
async fn cmd_delete_workspace(
|
||||||
window: Window<Wry>,
|
window: Window<Wry>,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
app_handle: AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Workspace, String> {
|
) -> Result<Workspace, String> {
|
||||||
let db = &*db_state.lock().await;
|
let workspace = delete_workspace(&app_handle, workspace_id)
|
||||||
let workspace = delete_workspace(db, workspace_id)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to delete Workspace");
|
.expect("Failed to delete Workspace");
|
||||||
emit_and_return(&window, "deleted_model", workspace)
|
emit_and_return(&window, "deleted_model", workspace)
|
||||||
@@ -1616,12 +1556,10 @@ async fn cmd_delete_workspace(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_check_for_updates(
|
async fn cmd_check_for_updates(
|
||||||
app_handle: AppHandle<Wry>,
|
app_handle: AppHandle,
|
||||||
db_state: State<'_, Mutex<Pool<Sqlite>>>,
|
|
||||||
yaak_updater: State<'_, Mutex<YaakUpdater>>,
|
yaak_updater: State<'_, Mutex<YaakUpdater>>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let db = &*db_state.lock().await;
|
let update_mode = get_update_mode(&app_handle).await;
|
||||||
let update_mode = get_update_mode(db).await;
|
|
||||||
yaak_updater
|
yaak_updater
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
@@ -1694,7 +1632,8 @@ fn main() {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to migrate database");
|
.expect("Failed to migrate database");
|
||||||
app.manage(m);
|
app.manage(m);
|
||||||
let _ = cancel_pending_responses(&pool).await;
|
let h = app.handle();
|
||||||
|
let _ = cancel_pending_responses(&h).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1790,9 +1729,7 @@ fn main() {
|
|||||||
|
|
||||||
let h = app_handle.clone();
|
let h = app_handle.clone();
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let db_state: State<'_, Mutex<Pool<Sqlite>>> = h.state();
|
let info = analytics::track_launch_event(&h).await;
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let info = analytics::track_launch_event(&h, db).await;
|
|
||||||
info!("Launched Yaak {:?}", info);
|
info!("Launched Yaak {:?}", info);
|
||||||
|
|
||||||
// Wait for window render and give a chance for the user to notice
|
// Wait for window render and give a chance for the user to notice
|
||||||
@@ -1811,9 +1748,7 @@ fn main() {
|
|||||||
// Run update check whenever window is focused
|
// Run update check whenever window is focused
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let val: State<'_, Mutex<YaakUpdater>> = h.state();
|
let val: State<'_, Mutex<YaakUpdater>> = h.state();
|
||||||
let db_state: State<'_, Mutex<Pool<Sqlite>>> = h.state();
|
let update_mode = get_update_mode(&h).await;
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
let update_mode = get_update_mode(&db).await;
|
|
||||||
_ = val.lock().await.check(&h, update_mode).await;
|
_ = val.lock().await.check(&h, update_mode).await;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1833,7 +1768,7 @@ fn is_dev() -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_window(handle: &AppHandle<Wry>, url: Option<&str>) -> Window<Wry> {
|
fn create_window(handle: &AppHandle, url: Option<&str>) -> Window<Wry> {
|
||||||
let app_menu = window_menu::os_default("Yaak".to_string().as_str());
|
let app_menu = window_menu::os_default("Yaak".to_string().as_str());
|
||||||
let window_num = handle.windows().len();
|
let window_num = handle.windows().len();
|
||||||
let window_id = format!("wnd_{}", window_num);
|
let window_id = format!("wnd_{}", window_num);
|
||||||
@@ -1934,12 +1869,12 @@ fn emit_and_return<S: Serialize + Clone, E>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Emit an event to all windows, used for side-effects where there is no source window to attribute. This
|
/// Emit an event to all windows, used for side-effects where there is no source window to attribute. This
|
||||||
fn emit_side_effect<S: Serialize + Clone>(app_handle: AppHandle<Wry>, event: &str, payload: S) {
|
fn emit_side_effect<S: Serialize + Clone>(app_handle: &AppHandle, event: &str, payload: S) {
|
||||||
app_handle.emit_all(event, &payload).unwrap();
|
app_handle.emit_all(event, &payload).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_update_mode(db: &Pool<Sqlite>) -> UpdateMode {
|
async fn get_update_mode(app_handle: &AppHandle) -> UpdateMode {
|
||||||
let settings = get_or_create_settings(db).await;
|
let settings = get_or_create_settings(app_handle).await;
|
||||||
update_mode_from_str(settings.update_channel.as_str())
|
update_mode_from_str(settings.update_channel.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -258,32 +258,32 @@ pub struct KeyValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_key_value_string(
|
pub async fn set_key_value_string(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
value: &str,
|
value: &str,
|
||||||
) -> (KeyValue, bool) {
|
) -> (KeyValue, bool) {
|
||||||
let encoded = serde_json::to_string(value);
|
let encoded = serde_json::to_string(value);
|
||||||
set_key_value_raw(db, namespace, key, &encoded.unwrap()).await
|
set_key_value_raw(app_handle, namespace, key, &encoded.unwrap()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_key_value_int(
|
pub async fn set_key_value_int(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
value: i32,
|
value: i32,
|
||||||
) -> (KeyValue, bool) {
|
) -> (KeyValue, bool) {
|
||||||
let encoded = serde_json::to_string(&value);
|
let encoded = serde_json::to_string(&value);
|
||||||
set_key_value_raw(db, namespace, key, &encoded.unwrap()).await
|
set_key_value_raw(app_handle, namespace, key, &encoded.unwrap()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_key_value_string(
|
pub async fn get_key_value_string(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
default: &str,
|
default: &str,
|
||||||
) -> String {
|
) -> String {
|
||||||
match get_key_value_raw(db, namespace, key).await {
|
match get_key_value_raw(app_handle, namespace, key).await {
|
||||||
None => default.to_string(),
|
None => default.to_string(),
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let result = serde_json::from_str(&v.value);
|
let result = serde_json::from_str(&v.value);
|
||||||
@@ -298,8 +298,13 @@ pub async fn get_key_value_string(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_key_value_int(db: &Pool<Sqlite>, namespace: &str, key: &str, default: i32) -> i32 {
|
pub async fn get_key_value_int(
|
||||||
match get_key_value_raw(db, namespace, key).await {
|
app_handle: &AppHandle,
|
||||||
|
namespace: &str,
|
||||||
|
key: &str,
|
||||||
|
default: i32,
|
||||||
|
) -> i32 {
|
||||||
|
match get_key_value_raw(app_handle, namespace, key).await {
|
||||||
None => default.clone(),
|
None => default.clone(),
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let result = serde_json::from_str(&v.value);
|
let result = serde_json::from_str(&v.value);
|
||||||
@@ -315,12 +320,13 @@ pub async fn get_key_value_int(db: &Pool<Sqlite>, namespace: &str, key: &str, de
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_key_value_raw(
|
pub async fn set_key_value_raw(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
namespace: &str,
|
namespace: &str,
|
||||||
key: &str,
|
key: &str,
|
||||||
value: &str,
|
value: &str,
|
||||||
) -> (KeyValue, bool) {
|
) -> (KeyValue, bool) {
|
||||||
let existing = get_key_value_raw(db, namespace, key).await;
|
let db = get_db(app_handle).await;
|
||||||
|
let existing = get_key_value_raw(app_handle, namespace, key).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO key_values (namespace, key, value)
|
INSERT INTO key_values (namespace, key, value)
|
||||||
@@ -332,17 +338,22 @@ pub async fn set_key_value_raw(
|
|||||||
key,
|
key,
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to insert key value");
|
.expect("Failed to insert key value");
|
||||||
|
|
||||||
let kv = get_key_value_raw(db, namespace, key)
|
let kv = get_key_value_raw(app_handle, namespace, key)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get key value");
|
.expect("Failed to get key value");
|
||||||
(kv, existing.is_none())
|
(kv, existing.is_none())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_key_value_raw(db: &Pool<Sqlite>, namespace: &str, key: &str) -> Option<KeyValue> {
|
pub async fn get_key_value_raw(
|
||||||
|
app_handle: &AppHandle,
|
||||||
|
namespace: &str,
|
||||||
|
key: &str,
|
||||||
|
) -> Option<KeyValue> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
KeyValue,
|
KeyValue,
|
||||||
r#"
|
r#"
|
||||||
@@ -353,12 +364,13 @@ pub async fn get_key_value_raw(db: &Pool<Sqlite>, namespace: &str, key: &str) ->
|
|||||||
namespace,
|
namespace,
|
||||||
key,
|
key,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_workspaces(db: &Pool<Sqlite>) -> Result<Vec<Workspace>, sqlx::Error> {
|
pub async fn list_workspaces(app_handle: &AppHandle) -> Result<Vec<Workspace>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Workspace,
|
Workspace,
|
||||||
r#"
|
r#"
|
||||||
@@ -369,11 +381,12 @@ pub async fn list_workspaces(db: &Pool<Sqlite>) -> Result<Vec<Workspace>, sqlx::
|
|||||||
FROM workspaces
|
FROM workspaces
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace, sqlx::Error> {
|
pub async fn get_workspace(app_handle: &AppHandle, id: &str) -> Result<Workspace, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Workspace,
|
Workspace,
|
||||||
r#"
|
r#"
|
||||||
@@ -385,12 +398,13 @@ pub async fn get_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace, sql
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace, sqlx::Error> {
|
pub async fn delete_workspace(app_handle: &AppHandle, id: &str) -> Result<Workspace, sqlx::Error> {
|
||||||
let workspace = get_workspace(db, id).await?;
|
let db = get_db(app_handle).await;
|
||||||
|
let workspace = get_workspace(app_handle, id).await?;
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM workspaces
|
DELETE FROM workspaces
|
||||||
@@ -398,17 +412,18 @@ pub async fn delete_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace,
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
for r in list_responses_by_workspace_id(db, id).await? {
|
for r in list_responses_by_workspace_id(app_handle, id).await? {
|
||||||
delete_response(db, &r.id).await?;
|
delete_response(app_handle, &r.id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(workspace)
|
Ok(workspace)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar, sqlx::Error> {
|
pub async fn get_cookie_jar(app_handle: &AppHandle, id: &str) -> Result<CookieJar, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
CookieJar,
|
CookieJar,
|
||||||
r#"
|
r#"
|
||||||
@@ -419,14 +434,15 @@ pub async fn get_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar, sq
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_cookie_jars(
|
pub async fn list_cookie_jars(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<CookieJar>, sqlx::Error> {
|
) -> Result<Vec<CookieJar>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
CookieJar,
|
CookieJar,
|
||||||
r#"
|
r#"
|
||||||
@@ -437,12 +453,13 @@ pub async fn list_cookie_jars(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar, sqlx::Error> {
|
pub async fn delete_cookie_jar(app_handle: &AppHandle, id: &str) -> Result<CookieJar, sqlx::Error> {
|
||||||
let cookie_jar = get_cookie_jar(db, id).await?;
|
let cookie_jar = get_cookie_jar(app_handle, id).await?;
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
|
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
@@ -451,7 +468,7 @@ pub async fn delete_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar,
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(cookie_jar)
|
Ok(cookie_jar)
|
||||||
@@ -512,9 +529,7 @@ pub async fn get_grpc_request(
|
|||||||
app_handle: &AppHandle,
|
app_handle: &AppHandle,
|
||||||
id: &str,
|
id: &str,
|
||||||
) -> Result<GrpcRequest, sqlx::Error> {
|
) -> Result<GrpcRequest, sqlx::Error> {
|
||||||
let db_state = app_handle.state::<Mutex<Pool<Sqlite>>>();
|
let db = get_db(app_handle).await;
|
||||||
let db = &*db_state.lock().await;
|
|
||||||
|
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
GrpcRequest,
|
GrpcRequest,
|
||||||
r#"
|
r#"
|
||||||
@@ -526,14 +541,15 @@ pub async fn get_grpc_request(
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_grpc_requests(
|
pub async fn list_grpc_requests(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<GrpcRequest>, sqlx::Error> {
|
) -> Result<Vec<GrpcRequest>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
GrpcRequest,
|
GrpcRequest,
|
||||||
r#"
|
r#"
|
||||||
@@ -545,7 +561,7 @@ pub async fn list_grpc_requests(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,9 +616,10 @@ pub async fn get_grpc_connection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_grpc_connections(
|
pub async fn list_grpc_connections(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
) -> Result<Vec<GrpcConnection>, sqlx::Error> {
|
) -> Result<Vec<GrpcConnection>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
GrpcConnection,
|
GrpcConnection,
|
||||||
r#"
|
r#"
|
||||||
@@ -613,7 +630,7 @@ pub async fn list_grpc_connections(
|
|||||||
"#,
|
"#,
|
||||||
request_id,
|
request_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,9 +694,10 @@ pub async fn get_grpc_message(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_grpc_messages(
|
pub async fn list_grpc_messages(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
) -> Result<Vec<GrpcMessage>, sqlx::Error> {
|
) -> Result<Vec<GrpcMessage>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
GrpcMessage,
|
GrpcMessage,
|
||||||
r#"
|
r#"
|
||||||
@@ -691,12 +709,12 @@ pub async fn list_grpc_messages(
|
|||||||
"#,
|
"#,
|
||||||
connection_id,
|
connection_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upsert_cookie_jar(
|
pub async fn upsert_cookie_jar(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
cookie_jar: &CookieJar,
|
cookie_jar: &CookieJar,
|
||||||
) -> Result<CookieJar, sqlx::Error> {
|
) -> Result<CookieJar, sqlx::Error> {
|
||||||
let id = match cookie_jar.id.as_str() {
|
let id = match cookie_jar.id.as_str() {
|
||||||
@@ -704,6 +722,8 @@ pub async fn upsert_cookie_jar(
|
|||||||
_ => cookie_jar.id.to_string(),
|
_ => cookie_jar.id.to_string(),
|
||||||
};
|
};
|
||||||
let trimmed_name = cookie_jar.name.trim();
|
let trimmed_name = cookie_jar.name.trim();
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO cookie_jars (
|
INSERT INTO cookie_jars (
|
||||||
@@ -720,16 +740,17 @@ pub async fn upsert_cookie_jar(
|
|||||||
trimmed_name,
|
trimmed_name,
|
||||||
cookie_jar.cookies,
|
cookie_jar.cookies,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
get_cookie_jar(db, &id).await
|
get_cookie_jar(&app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_environments(
|
pub async fn list_environments(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<Environment>, sqlx::Error> {
|
) -> Result<Vec<Environment>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Environment,
|
Environment,
|
||||||
r#"
|
r#"
|
||||||
@@ -740,12 +761,16 @@ pub async fn list_environments(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environment, sqlx::Error> {
|
pub async fn delete_environment(
|
||||||
let env = get_environment(db, id).await?;
|
app_handle: &AppHandle,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<Environment, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
|
let env = get_environment(app_handle, id).await?;
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM environments
|
DELETE FROM environments
|
||||||
@@ -753,13 +778,14 @@ pub async fn delete_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environme
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(env)
|
Ok(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_settings(db: &Pool<Sqlite>) -> Result<Settings, sqlx::Error> {
|
async fn get_settings(app_handle: &AppHandle) -> Result<Settings, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Settings,
|
Settings,
|
||||||
r#"
|
r#"
|
||||||
@@ -769,32 +795,36 @@ async fn get_settings(db: &Pool<Sqlite>) -> Result<Settings, sqlx::Error> {
|
|||||||
WHERE id = 'default'
|
WHERE id = 'default'
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_or_create_settings(db: &Pool<Sqlite>) -> Settings {
|
pub async fn get_or_create_settings(app_handle: &AppHandle) -> Settings {
|
||||||
if let Ok(settings) = get_settings(db).await {
|
if let Ok(settings) = get_settings(app_handle).await {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO settings (id)
|
INSERT INTO settings (id)
|
||||||
VALUES ('default')
|
VALUES ('default')
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to insert settings");
|
.expect("Failed to insert settings");
|
||||||
|
|
||||||
get_settings(db).await.expect("Failed to get settings")
|
get_settings(&app_handle)
|
||||||
|
.await
|
||||||
|
.expect("Failed to get settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_settings(
|
pub async fn update_settings(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
) -> Result<Settings, sqlx::Error> {
|
) -> Result<Settings, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
UPDATE settings SET (
|
UPDATE settings SET (
|
||||||
@@ -805,13 +835,13 @@ pub async fn update_settings(
|
|||||||
settings.appearance,
|
settings.appearance,
|
||||||
settings.update_channel
|
settings.update_channel
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
get_settings(db).await
|
get_settings(app_handle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upsert_environment(
|
pub async fn upsert_environment(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
environment: Environment,
|
environment: Environment,
|
||||||
) -> Result<Environment, sqlx::Error> {
|
) -> Result<Environment, sqlx::Error> {
|
||||||
let id = match environment.id.as_str() {
|
let id = match environment.id.as_str() {
|
||||||
@@ -819,6 +849,7 @@ pub async fn upsert_environment(
|
|||||||
_ => environment.id.to_string(),
|
_ => environment.id.to_string(),
|
||||||
};
|
};
|
||||||
let trimmed_name = environment.name.trim();
|
let trimmed_name = environment.name.trim();
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO environments (
|
INSERT INTO environments (
|
||||||
@@ -835,12 +866,13 @@ pub async fn upsert_environment(
|
|||||||
trimmed_name,
|
trimmed_name,
|
||||||
environment.variables,
|
environment.variables,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
get_environment(db, &id).await
|
get_environment(app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environment, sqlx::Error> {
|
pub async fn get_environment(app_handle: &AppHandle, id: &str) -> Result<Environment, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Environment,
|
Environment,
|
||||||
r#"
|
r#"
|
||||||
@@ -852,11 +884,12 @@ pub async fn get_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environment,
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::Error> {
|
pub async fn get_folder(app_handle: &AppHandle, id: &str) -> Result<Folder, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Folder,
|
Folder,
|
||||||
r#"
|
r#"
|
||||||
@@ -867,14 +900,15 @@ pub async fn get_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::Err
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_folders(
|
pub async fn list_folders(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<Folder>, sqlx::Error> {
|
) -> Result<Vec<Folder>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Folder,
|
Folder,
|
||||||
r#"
|
r#"
|
||||||
@@ -885,12 +919,13 @@ pub async fn list_folders(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::Error> {
|
pub async fn delete_folder(app_handle: &AppHandle, id: &str) -> Result<Folder, sqlx::Error> {
|
||||||
let env = get_folder(db, id).await?;
|
let env = get_folder(app_handle, id).await?;
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM folders
|
DELETE FROM folders
|
||||||
@@ -898,19 +933,20 @@ pub async fn delete_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(env)
|
Ok(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upsert_folder(db: &Pool<Sqlite>, r: Folder) -> Result<Folder, sqlx::Error> {
|
pub async fn upsert_folder(app_handle: &AppHandle, r: Folder) -> Result<Folder, sqlx::Error> {
|
||||||
let id = match r.id.as_str() {
|
let id = match r.id.as_str() {
|
||||||
"" => generate_id(Some("fl")),
|
"" => generate_id(Some("fl")),
|
||||||
_ => r.id.to_string(),
|
_ => r.id.to_string(),
|
||||||
};
|
};
|
||||||
let trimmed_name = r.name.trim();
|
let trimmed_name = r.name.trim();
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO folders (
|
INSERT INTO folders (
|
||||||
@@ -929,23 +965,23 @@ pub async fn upsert_folder(db: &Pool<Sqlite>, r: Folder) -> Result<Folder, sqlx:
|
|||||||
trimmed_name,
|
trimmed_name,
|
||||||
r.sort_priority,
|
r.sort_priority,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
get_folder(db, &id).await
|
get_folder(&app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn duplicate_http_request(
|
pub async fn duplicate_http_request(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
id: &str,
|
id: &str,
|
||||||
) -> Result<HttpRequest, sqlx::Error> {
|
) -> Result<HttpRequest, sqlx::Error> {
|
||||||
let mut request = get_http_request(db, id).await?.clone();
|
let mut request = get_http_request(app_handle, id).await?.clone();
|
||||||
request.id = "".to_string();
|
request.id = "".to_string();
|
||||||
upsert_http_request(db, request).await
|
upsert_http_request(app_handle, request).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upsert_http_request(
|
pub async fn upsert_http_request(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
r: HttpRequest,
|
r: HttpRequest,
|
||||||
) -> Result<HttpRequest, sqlx::Error> {
|
) -> Result<HttpRequest, sqlx::Error> {
|
||||||
let id = match r.id.as_str() {
|
let id = match r.id.as_str() {
|
||||||
@@ -956,6 +992,8 @@ pub async fn upsert_http_request(
|
|||||||
let auth_json = Json(r.authentication);
|
let auth_json = Json(r.authentication);
|
||||||
let trimmed_name = r.name.trim();
|
let trimmed_name = r.name.trim();
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO http_requests (
|
INSERT INTO http_requests (
|
||||||
@@ -991,16 +1029,17 @@ pub async fn upsert_http_request(
|
|||||||
headers_json,
|
headers_json,
|
||||||
r.sort_priority,
|
r.sort_priority,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
get_http_request(db, &id).await
|
get_http_request(app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_requests(
|
pub async fn list_requests(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<HttpRequest>, sqlx::Error> {
|
) -> Result<Vec<HttpRequest>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
r#"
|
r#"
|
||||||
@@ -1016,11 +1055,16 @@ pub async fn list_requests(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_http_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
pub async fn get_http_request(
|
||||||
|
app_handle: &AppHandle,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<HttpRequest, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
|
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
r#"
|
r#"
|
||||||
@@ -1036,16 +1080,17 @@ pub async fn get_http_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
pub async fn delete_request(app_handle: &AppHandle, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
||||||
let req = get_http_request(db, id).await?;
|
let req = get_http_request(app_handle, id).await?;
|
||||||
|
|
||||||
// DB deletes will cascade but this will delete the files
|
// DB deletes will cascade but this will delete the files
|
||||||
delete_all_responses(db, id).await?;
|
delete_all_responses(app_handle, id).await?;
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM http_requests
|
DELETE FROM http_requests
|
||||||
@@ -1053,7 +1098,7 @@ pub async fn delete_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest,
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(req)
|
Ok(req)
|
||||||
@@ -1061,7 +1106,7 @@ pub async fn delete_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest,
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn create_response(
|
pub async fn create_response(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
elapsed: i64,
|
elapsed: i64,
|
||||||
elapsed_headers: i64,
|
elapsed_headers: i64,
|
||||||
@@ -1074,9 +1119,10 @@ pub async fn create_response(
|
|||||||
version: Option<&str>,
|
version: Option<&str>,
|
||||||
remote_addr: Option<&str>,
|
remote_addr: Option<&str>,
|
||||||
) -> Result<HttpResponse, sqlx::Error> {
|
) -> Result<HttpResponse, sqlx::Error> {
|
||||||
let req = get_http_request(db, request_id).await?;
|
let req = get_http_request(app_handle, request_id).await?;
|
||||||
let id = generate_id(Some("rp"));
|
let id = generate_id(Some("rp"));
|
||||||
let headers_json = Json(headers);
|
let headers_json = Json(headers);
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO http_responses (
|
INSERT INTO http_responses (
|
||||||
@@ -1099,13 +1145,14 @@ pub async fn create_response(
|
|||||||
version,
|
version,
|
||||||
remote_addr,
|
remote_addr,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
get_response(db, &id).await
|
get_response(app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cancel_pending_responses(db: &Pool<Sqlite>) -> Result<(), sqlx::Error> {
|
pub async fn cancel_pending_responses(app_handle: &AppHandle) -> Result<(), sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
UPDATE http_responses
|
UPDATE http_responses
|
||||||
@@ -1113,24 +1160,24 @@ pub async fn cancel_pending_responses(db: &Pool<Sqlite>) -> Result<(), sqlx::Err
|
|||||||
WHERE elapsed = 0;
|
WHERE elapsed = 0;
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_response_if_id(
|
pub async fn update_response_if_id(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
response: &HttpResponse,
|
response: &HttpResponse,
|
||||||
) -> Result<HttpResponse, sqlx::Error> {
|
) -> Result<HttpResponse, sqlx::Error> {
|
||||||
if response.id.is_empty() {
|
if response.id.is_empty() {
|
||||||
Ok(response.clone())
|
Ok(response.clone())
|
||||||
} else {
|
} else {
|
||||||
update_response(db, response).await
|
update_response(app_handle, response).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn upsert_workspace(
|
pub async fn upsert_workspace(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
) -> Result<Workspace, sqlx::Error> {
|
) -> Result<Workspace, sqlx::Error> {
|
||||||
let id = match workspace.id.as_str() {
|
let id = match workspace.id.as_str() {
|
||||||
@@ -1138,6 +1185,8 @@ pub async fn upsert_workspace(
|
|||||||
_ => workspace.id.to_string(),
|
_ => workspace.id.to_string(),
|
||||||
};
|
};
|
||||||
let trimmed_name = workspace.name.trim();
|
let trimmed_name = workspace.name.trim();
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO workspaces (
|
INSERT INTO workspaces (
|
||||||
@@ -1162,17 +1211,18 @@ pub async fn upsert_workspace(
|
|||||||
workspace.setting_follow_redirects,
|
workspace.setting_follow_redirects,
|
||||||
workspace.setting_validate_certificates,
|
workspace.setting_validate_certificates,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
get_workspace(db, &id).await
|
get_workspace(app_handle, &id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_response(
|
pub async fn update_response(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
response: &HttpResponse,
|
response: &HttpResponse,
|
||||||
) -> Result<HttpResponse, sqlx::Error> {
|
) -> Result<HttpResponse, sqlx::Error> {
|
||||||
let headers_json = Json(&response.headers);
|
let headers_json = Json(&response.headers);
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
UPDATE http_responses SET (
|
UPDATE http_responses SET (
|
||||||
@@ -1193,12 +1243,13 @@ pub async fn update_response(
|
|||||||
response.remote_addr,
|
response.remote_addr,
|
||||||
response.id,
|
response.id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await?;
|
.await?;
|
||||||
get_response(db, &response.id).await
|
get_response(app_handle, &response.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse, sqlx::Error> {
|
pub async fn get_response(app_handle: &AppHandle, id: &str) -> Result<HttpResponse, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
r#"
|
r#"
|
||||||
@@ -1212,16 +1263,17 @@ pub async fn get_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse, s
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_responses(
|
pub async fn list_responses(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
request_id: &str,
|
request_id: &str,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
||||||
let limit_unwrapped = limit.unwrap_or_else(|| i64::MAX);
|
let limit_unwrapped = limit.unwrap_or_else(|| i64::MAX);
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
r#"
|
r#"
|
||||||
@@ -1238,14 +1290,15 @@ pub async fn list_responses(
|
|||||||
request_id,
|
request_id,
|
||||||
limit_unwrapped,
|
limit_unwrapped,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_responses_by_workspace_id(
|
pub async fn list_responses_by_workspace_id(
|
||||||
db: &Pool<Sqlite>,
|
app_handle: &AppHandle,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
r#"
|
r#"
|
||||||
@@ -1260,12 +1313,15 @@ pub async fn list_responses_by_workspace_id(
|
|||||||
"#,
|
"#,
|
||||||
workspace_id,
|
workspace_id,
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(&db)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse, sqlx::Error> {
|
pub async fn delete_response(
|
||||||
let resp = get_response(db, id).await?;
|
app_handle: &AppHandle,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<HttpResponse, sqlx::Error> {
|
||||||
|
let resp = get_response(app_handle, id).await?;
|
||||||
|
|
||||||
// Delete the body file if it exists
|
// Delete the body file if it exists
|
||||||
if let Some(p) = resp.body_path.clone() {
|
if let Some(p) = resp.body_path.clone() {
|
||||||
@@ -1274,6 +1330,7 @@ pub async fn delete_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let db = get_db(app_handle).await;
|
||||||
let _ = sqlx::query!(
|
let _ = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
DELETE FROM http_responses
|
DELETE FROM http_responses
|
||||||
@@ -1281,15 +1338,18 @@ pub async fn delete_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse
|
|||||||
"#,
|
"#,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(db)
|
.execute(&db)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
Ok(resp)
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_all_responses(db: &Pool<Sqlite>, request_id: &str) -> Result<(), sqlx::Error> {
|
pub async fn delete_all_responses(
|
||||||
for r in list_responses(db, request_id, None).await? {
|
app_handle: &AppHandle,
|
||||||
delete_response(db, &r.id).await?;
|
request_id: &str,
|
||||||
|
) -> Result<(), sqlx::Error> {
|
||||||
|
for r in list_responses(app_handle, request_id, None).await? {
|
||||||
|
delete_response(app_handle, &r.id).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -1322,10 +1382,9 @@ pub struct WorkspaceExportResources {
|
|||||||
|
|
||||||
pub async fn get_workspace_export_resources(
|
pub async fn get_workspace_export_resources(
|
||||||
app_handle: &AppHandle,
|
app_handle: &AppHandle,
|
||||||
db: &Pool<Sqlite>,
|
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> WorkspaceExport {
|
) -> WorkspaceExport {
|
||||||
let workspace = get_workspace(db, workspace_id)
|
let workspace = get_workspace(app_handle, workspace_id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get workspace");
|
.expect("Failed to get workspace");
|
||||||
return WorkspaceExport {
|
return WorkspaceExport {
|
||||||
@@ -1334,13 +1393,13 @@ pub async fn get_workspace_export_resources(
|
|||||||
timestamp: chrono::Utc::now().naive_utc(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
resources: WorkspaceExportResources {
|
resources: WorkspaceExportResources {
|
||||||
workspaces: vec![workspace],
|
workspaces: vec![workspace],
|
||||||
environments: list_environments(db, workspace_id)
|
environments: list_environments(app_handle, workspace_id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get environments"),
|
.expect("Failed to get environments"),
|
||||||
folders: list_folders(db, workspace_id)
|
folders: list_folders(app_handle, workspace_id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get folders"),
|
.expect("Failed to get folders"),
|
||||||
requests: list_requests(db, workspace_id)
|
requests: list_requests(app_handle, workspace_id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get requests"),
|
.expect("Failed to get requests"),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use tauri::{AppHandle, updater, Window, Wry};
|
|
||||||
use tauri::api::dialog;
|
use tauri::api::dialog;
|
||||||
|
use tauri::{updater, AppHandle, Window};
|
||||||
|
|
||||||
use crate::is_dev;
|
use crate::is_dev;
|
||||||
|
|
||||||
@@ -27,14 +27,17 @@ impl YaakUpdater {
|
|||||||
}
|
}
|
||||||
pub async fn force_check(
|
pub async fn force_check(
|
||||||
&mut self,
|
&mut self,
|
||||||
app_handle: &AppHandle<Wry>,
|
app_handle: &AppHandle,
|
||||||
mode: UpdateMode,
|
mode: UpdateMode,
|
||||||
) -> Result<bool, updater::Error> {
|
) -> Result<bool, updater::Error> {
|
||||||
self.last_update_check = SystemTime::now();
|
self.last_update_check = SystemTime::now();
|
||||||
|
|
||||||
let update_mode = get_update_mode_str(mode);
|
let update_mode = get_update_mode_str(mode);
|
||||||
let enabled = !is_dev();
|
let enabled = !is_dev();
|
||||||
info!("Checking for updates mode={} enabled={}", update_mode, enabled);
|
info!(
|
||||||
|
"Checking for updates mode={} enabled={}",
|
||||||
|
update_mode, enabled
|
||||||
|
);
|
||||||
|
|
||||||
if !enabled {
|
if !enabled {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -89,10 +92,11 @@ impl YaakUpdater {
|
|||||||
}
|
}
|
||||||
pub async fn check(
|
pub async fn check(
|
||||||
&mut self,
|
&mut self,
|
||||||
app_handle: &AppHandle<Wry>,
|
app_handle: &AppHandle,
|
||||||
mode: UpdateMode,
|
mode: UpdateMode,
|
||||||
) -> Result<bool, updater::Error> {
|
) -> Result<bool, updater::Error> {
|
||||||
let ignore_check = self.last_update_check.elapsed().unwrap().as_secs() < MAX_UPDATE_CHECK_SECONDS;
|
let ignore_check =
|
||||||
|
self.last_update_check.elapsed().unwrap().as_secs() < MAX_UPDATE_CHECK_SECONDS;
|
||||||
if ignore_check {
|
if ignore_check {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { RadioDropdown } from './core/RadioDropdown';
|
|||||||
import { Separator } from './core/Separator';
|
import { Separator } from './core/Separator';
|
||||||
import { SplitLayout } from './core/SplitLayout';
|
import { SplitLayout } from './core/SplitLayout';
|
||||||
import { HStack, VStack } from './core/Stacks';
|
import { HStack, VStack } from './core/Stacks';
|
||||||
import { StatusTag } from './core/StatusTag';
|
|
||||||
import { GrpcEditor } from './GrpcEditor';
|
import { GrpcEditor } from './GrpcEditor';
|
||||||
import { UrlBar } from './UrlBar';
|
import { UrlBar } from './UrlBar';
|
||||||
|
|
||||||
@@ -276,6 +275,7 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
</Banner>
|
</Banner>
|
||||||
) : messages.length >= 0 ? (
|
) : messages.length >= 0 ? (
|
||||||
<SplitLayout
|
<SplitLayout
|
||||||
|
forceVertical
|
||||||
name={
|
name={
|
||||||
!activeMethod?.clientStreaming && !activeMethod?.serverStreaming
|
!activeMethod?.clientStreaming && !activeMethod?.serverStreaming
|
||||||
? 'grpc_messages_unary'
|
? 'grpc_messages_unary'
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface Props {
|
|||||||
defaultRatio?: number;
|
defaultRatio?: number;
|
||||||
minHeightPx?: number;
|
minHeightPx?: number;
|
||||||
minWidthPx?: number;
|
minWidthPx?: number;
|
||||||
|
forceVertical?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const areaL = { gridArea: 'left' };
|
const areaL = { gridArea: 'left' };
|
||||||
@@ -37,6 +38,7 @@ export function SplitLayout({
|
|||||||
secondSlot,
|
secondSlot,
|
||||||
className,
|
className,
|
||||||
name,
|
name,
|
||||||
|
forceVertical,
|
||||||
defaultRatio = 0.5,
|
defaultRatio = 0.5,
|
||||||
minHeightPx = 10,
|
minHeightPx = 10,
|
||||||
minWidthPx = 10,
|
minWidthPx = 10,
|
||||||
@@ -66,14 +68,15 @@ export function SplitLayout({
|
|||||||
const styles = useMemo<CSSProperties>(() => {
|
const styles = useMemo<CSSProperties>(() => {
|
||||||
return {
|
return {
|
||||||
...style,
|
...style,
|
||||||
gridTemplate: vertical
|
gridTemplate:
|
||||||
? `
|
forceVertical || vertical
|
||||||
|
? `
|
||||||
' ${areaL.gridArea}' minmax(0,${1 - height}fr)
|
' ${areaL.gridArea}' minmax(0,${1 - height}fr)
|
||||||
' ${areaD.gridArea}' 0
|
' ${areaD.gridArea}' 0
|
||||||
' ${areaR.gridArea}' minmax(${minHeightPx}px,${height}fr)
|
' ${areaR.gridArea}' minmax(${minHeightPx}px,${height}fr)
|
||||||
/ 1fr
|
/ 1fr
|
||||||
`
|
`
|
||||||
: `
|
: `
|
||||||
' ${areaL.gridArea} ${areaD.gridArea} ${areaR.gridArea}' minmax(0,1fr)
|
' ${areaL.gridArea} ${areaD.gridArea} ${areaR.gridArea}' minmax(0,1fr)
|
||||||
/ ${1 - width}fr 0 ${width}fr
|
/ ${1 - width}fr 0 ${width}fr
|
||||||
`,
|
`,
|
||||||
|
|||||||
Reference in New Issue
Block a user