mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-23 18:01:08 +01:00
Refactor commands and DB
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use prost::Message;
|
||||
use prost_reflect::{DynamicMessage, SerializeOptions};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Deserializer;
|
||||
use tokio_stream::{Stream, StreamExt};
|
||||
use tokio_stream::Stream;
|
||||
use tonic::transport::Uri;
|
||||
use tonic::{IntoRequest, Response, Streaming};
|
||||
|
||||
@@ -77,7 +76,7 @@ impl Stream for ClientStream {
|
||||
|
||||
fn poll_next(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
cx: &mut std::task::Context<'_>,
|
||||
_cx: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Option<Self::Item>> {
|
||||
println!("poll_next");
|
||||
todo!()
|
||||
|
||||
@@ -3,8 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use sqlx::types::JsonValue;
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
use tokio::sync::Mutex;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::{is_dev, models};
|
||||
|
||||
@@ -126,17 +125,15 @@ pub struct LaunchEventInfo {
|
||||
pub num_launches: i32,
|
||||
}
|
||||
|
||||
pub async fn track_launch_event(app_handle: &AppHandle) -> LaunchEventInfo {
|
||||
pub async fn track_launch_event(app_handle: &AppHandle, db: &Pool<Sqlite>) -> LaunchEventInfo {
|
||||
let namespace = "analytics";
|
||||
let last_tracked_version_key = "last_tracked_version";
|
||||
let db_instance: State<'_, Mutex<Pool<Sqlite>>> = app_handle.state();
|
||||
let pool = &*db_instance.lock().await;
|
||||
|
||||
let mut info = LaunchEventInfo::default();
|
||||
|
||||
info.num_launches = models::get_key_value_int(namespace, "num_launches", 0, pool).await + 1;
|
||||
info.num_launches = models::get_key_value_int(db, namespace, "num_launches", 0).await + 1;
|
||||
info.previous_version =
|
||||
models::get_key_value_string(namespace, last_tracked_version_key, "", pool).await;
|
||||
models::get_key_value_string(db, namespace, last_tracked_version_key, "").await;
|
||||
info.current_version = app_handle.package_info().version.to_string();
|
||||
|
||||
if info.previous_version.is_empty() {
|
||||
@@ -167,19 +164,18 @@ pub async fn track_launch_event(app_handle: &AppHandle) -> LaunchEventInfo {
|
||||
AnalyticsAction::Launch,
|
||||
Some(json!({ "num_launches": info.num_launches })),
|
||||
)
|
||||
.await;
|
||||
|
||||
.await;
|
||||
|
||||
// Update key values
|
||||
|
||||
models::set_key_value_string(
|
||||
db,
|
||||
namespace,
|
||||
last_tracked_version_key,
|
||||
info.current_version.as_str(),
|
||||
pool,
|
||||
)
|
||||
.await;
|
||||
models::set_key_value_int(namespace, "num_launches", info.num_launches, pool).await;
|
||||
models::set_key_value_int(db, namespace, "num_launches", info.num_launches).await;
|
||||
|
||||
info
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ use tauri::{AppHandle, Wry};
|
||||
use crate::{emit_side_effect, models, render, response_err};
|
||||
|
||||
pub async fn send_http_request(
|
||||
app_handle: &AppHandle<Wry>,
|
||||
db: &Pool<Sqlite>,
|
||||
request: models::HttpRequest,
|
||||
response: &models::HttpResponse,
|
||||
environment: Option<models::Environment>,
|
||||
cookie_jar: Option<models::CookieJar>,
|
||||
app_handle: &AppHandle<Wry>,
|
||||
pool: &Pool<Sqlite>,
|
||||
download_path: Option<PathBuf>,
|
||||
) -> Result<models::HttpResponse, String> {
|
||||
let environment_ref = environment.as_ref();
|
||||
let workspace = models::get_workspace(&request.workspace_id, pool)
|
||||
let workspace = models::get_workspace(db, &request.workspace_id)
|
||||
.await
|
||||
.expect("Failed to get Workspace");
|
||||
|
||||
@@ -88,7 +88,7 @@ pub async fn send_http_request(
|
||||
let url = match Url::from_str(url_string.as_str()) {
|
||||
Ok(u) => u,
|
||||
Err(e) => {
|
||||
return response_err(response, e.to_string(), app_handle, pool).await;
|
||||
return response_err(response, e.to_string(), app_handle, db).await;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -293,7 +293,7 @@ pub async fn send_http_request(
|
||||
let sendable_req = match request_builder.build() {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
return response_err(response, e.to_string(), app_handle, pool).await;
|
||||
return response_err(response, e.to_string(), app_handle, db).await;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -362,7 +362,7 @@ pub async fn send_http_request(
|
||||
);
|
||||
}
|
||||
|
||||
response = models::update_response_if_id(&response, pool)
|
||||
response = models::update_response_if_id(db, &response)
|
||||
.await
|
||||
.expect("Failed to update response");
|
||||
if !request.id.is_empty() {
|
||||
@@ -397,7 +397,7 @@ pub async fn send_http_request(
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
cookie_jar.cookies = json_cookies;
|
||||
match models::upsert_cookie_jar(pool, &cookie_jar).await {
|
||||
match models::upsert_cookie_jar(db, &cookie_jar).await {
|
||||
Ok(updated_jar) => {
|
||||
emit_side_effect(app_handle, "updated_model", &updated_jar);
|
||||
}
|
||||
@@ -409,6 +409,6 @@ pub async fn send_http_request(
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
Err(e) => response_err(response, e.to_string(), app_handle, pool).await,
|
||||
Err(e) => response_err(response, e.to_string(), app_handle, db).await,
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -58,9 +58,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct CookieX {
|
||||
|
||||
}
|
||||
pub struct CookieX {}
|
||||
|
||||
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
@@ -260,32 +258,32 @@ pub struct KeyValue {
|
||||
}
|
||||
|
||||
pub async fn set_key_value_string(
|
||||
db: &Pool<Sqlite>,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
value: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> (KeyValue, bool) {
|
||||
let encoded = serde_json::to_string(value);
|
||||
set_key_value_raw(namespace, key, &encoded.unwrap(), pool).await
|
||||
set_key_value_raw(db, namespace, key, &encoded.unwrap()).await
|
||||
}
|
||||
|
||||
pub async fn set_key_value_int(
|
||||
db: &Pool<Sqlite>,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
value: i32,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> (KeyValue, bool) {
|
||||
let encoded = serde_json::to_string(&value);
|
||||
set_key_value_raw(namespace, key, &encoded.unwrap(), pool).await
|
||||
set_key_value_raw(db, namespace, key, &encoded.unwrap()).await
|
||||
}
|
||||
|
||||
pub async fn get_key_value_string(
|
||||
db: &Pool<Sqlite>,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
default: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> String {
|
||||
match get_key_value_raw(namespace, key, pool).await {
|
||||
match get_key_value_raw(db, namespace, key).await {
|
||||
None => default.to_string(),
|
||||
Some(v) => {
|
||||
let result = serde_json::from_str(&v.value);
|
||||
@@ -296,17 +294,12 @@ pub async fn get_key_value_string(
|
||||
default.to_string()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_key_value_int(
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
default: i32,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> i32 {
|
||||
match get_key_value_raw(namespace, key, pool).await {
|
||||
pub async fn get_key_value_int(db: &Pool<Sqlite>, namespace: &str, key: &str, default: i32) -> i32 {
|
||||
match get_key_value_raw(db, namespace, key).await {
|
||||
None => default.clone(),
|
||||
Some(v) => {
|
||||
let result = serde_json::from_str(&v.value);
|
||||
@@ -317,17 +310,17 @@ pub async fn get_key_value_int(
|
||||
default.clone()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_key_value_raw(
|
||||
db: &Pool<Sqlite>,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
value: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> (KeyValue, bool) {
|
||||
let existing = get_key_value_raw(namespace, key, pool).await;
|
||||
let existing = get_key_value_raw(db, namespace, key).await;
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO key_values (namespace, key, value)
|
||||
@@ -339,17 +332,17 @@ pub async fn set_key_value_raw(
|
||||
key,
|
||||
value,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await
|
||||
.expect("Failed to insert key value");
|
||||
|
||||
let kv = get_key_value_raw(namespace, key, pool)
|
||||
let kv = get_key_value_raw(db, namespace, key)
|
||||
.await
|
||||
.expect("Failed to get key value");
|
||||
(kv, existing.is_none())
|
||||
}
|
||||
|
||||
pub async fn get_key_value_raw(namespace: &str, key: &str, pool: &Pool<Sqlite>) -> Option<KeyValue> {
|
||||
pub async fn get_key_value_raw(db: &Pool<Sqlite>, namespace: &str, key: &str) -> Option<KeyValue> {
|
||||
sqlx::query_as!(
|
||||
KeyValue,
|
||||
r#"
|
||||
@@ -360,12 +353,12 @@ pub async fn get_key_value_raw(namespace: &str, key: &str, pool: &Pool<Sqlite>)
|
||||
namespace,
|
||||
key,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn find_workspaces(pool: &Pool<Sqlite>) -> Result<Vec<Workspace>, sqlx::Error> {
|
||||
pub async fn find_workspaces(db: &Pool<Sqlite>) -> Result<Vec<Workspace>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Workspace,
|
||||
r#"
|
||||
@@ -383,11 +376,11 @@ pub async fn find_workspaces(pool: &Pool<Sqlite>) -> Result<Vec<Workspace>, sqlx
|
||||
FROM workspaces
|
||||
"#,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_workspace(id: &str, pool: &Pool<Sqlite>) -> Result<Workspace, sqlx::Error> {
|
||||
pub async fn get_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Workspace,
|
||||
r#"
|
||||
@@ -406,12 +399,12 @@ pub async fn get_workspace(id: &str, pool: &Pool<Sqlite>) -> Result<Workspace, s
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_workspace(id: &str, pool: &Pool<Sqlite>) -> Result<Workspace, sqlx::Error> {
|
||||
let workspace = get_workspace(id, pool).await?;
|
||||
pub async fn delete_workspace(db: &Pool<Sqlite>, id: &str) -> Result<Workspace, sqlx::Error> {
|
||||
let workspace = get_workspace(db, id).await?;
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM workspaces
|
||||
@@ -419,17 +412,17 @@ pub async fn delete_workspace(id: &str, pool: &Pool<Sqlite>) -> Result<Workspace
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
for r in find_responses_by_workspace_id(id, pool).await? {
|
||||
delete_response(&r.id, pool).await?;
|
||||
for r in find_responses_by_workspace_id(db, id).await? {
|
||||
delete_response(db, &r.id).await?;
|
||||
}
|
||||
|
||||
Ok(workspace)
|
||||
}
|
||||
|
||||
pub async fn get_cookie_jar(id: &str, pool: &Pool<Sqlite>) -> Result<CookieJar, sqlx::Error> {
|
||||
pub async fn get_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
CookieJar,
|
||||
r#"
|
||||
@@ -445,11 +438,14 @@ pub async fn get_cookie_jar(id: &str, pool: &Pool<Sqlite>) -> Result<CookieJar,
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_cookie_jars(workspace_id: &str, pool: &Pool<Sqlite>) -> Result<Vec<CookieJar>, sqlx::Error> {
|
||||
pub async fn find_cookie_jars(
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
) -> Result<Vec<CookieJar>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
CookieJar,
|
||||
r#"
|
||||
@@ -465,12 +461,12 @@ pub async fn find_cookie_jars(workspace_id: &str, pool: &Pool<Sqlite>) -> Result
|
||||
"#,
|
||||
workspace_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_cookie_jar(id: &str, pool: &Pool<Sqlite>) -> Result<CookieJar, sqlx::Error> {
|
||||
let cookie_jar = get_cookie_jar(id, pool).await?;
|
||||
pub async fn delete_cookie_jar(db: &Pool<Sqlite>, id: &str) -> Result<CookieJar, sqlx::Error> {
|
||||
let cookie_jar = get_cookie_jar(db, id).await?;
|
||||
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
@@ -479,14 +475,14 @@ pub async fn delete_cookie_jar(id: &str, pool: &Pool<Sqlite>) -> Result<CookieJa
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.await;
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
Ok(cookie_jar)
|
||||
}
|
||||
|
||||
pub async fn upsert_cookie_jar(
|
||||
pool: &Pool<Sqlite>,
|
||||
db: &Pool<Sqlite>,
|
||||
cookie_jar: &CookieJar,
|
||||
) -> Result<CookieJar, sqlx::Error> {
|
||||
let id = match cookie_jar.id.as_str() {
|
||||
@@ -513,15 +509,15 @@ pub async fn upsert_cookie_jar(
|
||||
trimmed_name,
|
||||
cookie_jar.cookies,
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
get_cookie_jar(&id, pool).await
|
||||
get_cookie_jar(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn find_environments(
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Vec<Environment>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Environment,
|
||||
@@ -533,12 +529,12 @@ pub async fn find_environments(
|
||||
"#,
|
||||
workspace_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environment, sqlx::Error> {
|
||||
let env = get_environment(id, pool).await?;
|
||||
pub async fn delete_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environment, sqlx::Error> {
|
||||
let env = get_environment(db, id).await?;
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM environments
|
||||
@@ -546,13 +542,13 @@ pub async fn delete_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environ
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
async fn get_settings(pool: &Pool<Sqlite>) -> Result<Settings, sqlx::Error> {
|
||||
async fn get_settings(db: &Pool<Sqlite>) -> Result<Settings, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Settings,
|
||||
r#"
|
||||
@@ -568,28 +564,30 @@ async fn get_settings(pool: &Pool<Sqlite>) -> Result<Settings, sqlx::Error> {
|
||||
WHERE id = 'default'
|
||||
"#,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_or_create_settings(pool: &Pool<Sqlite>) -> Settings {
|
||||
if let Ok(settings) = get_settings(pool).await {
|
||||
settings
|
||||
} else {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
pub async fn get_or_create_settings(db: &Pool<Sqlite>) -> Settings {
|
||||
if let Ok(settings) = get_settings(db).await {
|
||||
return settings;
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO settings (id)
|
||||
VALUES ('default')
|
||||
"#,
|
||||
)
|
||||
.execute(pool)
|
||||
.await.expect("Failed to insert settings");
|
||||
get_settings(pool).await.expect("Failed to get settings")
|
||||
}
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
.expect("Failed to insert settings");
|
||||
|
||||
get_settings(db).await.expect("Failed to get settings")
|
||||
}
|
||||
|
||||
pub async fn update_settings(
|
||||
pool: &Pool<Sqlite>,
|
||||
db: &Pool<Sqlite>,
|
||||
settings: Settings,
|
||||
) -> Result<Settings, sqlx::Error> {
|
||||
sqlx::query!(
|
||||
@@ -604,13 +602,13 @@ pub async fn update_settings(
|
||||
settings.appearance,
|
||||
settings.update_channel
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
get_settings(pool).await
|
||||
get_settings(db).await
|
||||
}
|
||||
|
||||
pub async fn upsert_environment(
|
||||
pool: &Pool<Sqlite>,
|
||||
db: &Pool<Sqlite>,
|
||||
environment: Environment,
|
||||
) -> Result<Environment, sqlx::Error> {
|
||||
let id = match environment.id.as_str() {
|
||||
@@ -637,12 +635,12 @@ pub async fn upsert_environment(
|
||||
trimmed_name,
|
||||
environment.variables,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
get_environment(&id, pool).await
|
||||
get_environment(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn get_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environment, sqlx::Error> {
|
||||
pub async fn get_environment(db: &Pool<Sqlite>, id: &str) -> Result<Environment, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Environment,
|
||||
r#"
|
||||
@@ -659,11 +657,11 @@ pub async fn get_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environmen
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_folder(id: &str, pool: &Pool<Sqlite>) -> Result<Folder, sqlx::Error> {
|
||||
pub async fn get_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Folder,
|
||||
r#"
|
||||
@@ -681,13 +679,13 @@ pub async fn get_folder(id: &str, pool: &Pool<Sqlite>) -> Result<Folder, sqlx::E
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_folders(
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Vec<Folder>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Folder,
|
||||
@@ -706,12 +704,12 @@ pub async fn find_folders(
|
||||
"#,
|
||||
workspace_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_folder(id: &str, pool: &Pool<Sqlite>) -> Result<Folder, sqlx::Error> {
|
||||
let env = get_folder(id, pool).await?;
|
||||
pub async fn delete_folder(db: &Pool<Sqlite>, id: &str) -> Result<Folder, sqlx::Error> {
|
||||
let env = get_folder(db, id).await?;
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM folders
|
||||
@@ -719,13 +717,13 @@ pub async fn delete_folder(id: &str, pool: &Pool<Sqlite>) -> Result<Folder, sqlx
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
pub async fn upsert_folder(pool: &Pool<Sqlite>, r: Folder) -> Result<Folder, sqlx::Error> {
|
||||
pub async fn upsert_folder(db: &Pool<Sqlite>, r: Folder) -> Result<Folder, sqlx::Error> {
|
||||
let id = match r.id.as_str() {
|
||||
"" => generate_id(Some("fl")),
|
||||
_ => r.id.to_string(),
|
||||
@@ -754,22 +752,19 @@ pub async fn upsert_folder(pool: &Pool<Sqlite>, r: Folder) -> Result<Folder, sql
|
||||
trimmed_name,
|
||||
r.sort_priority,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
get_folder(&id, pool).await
|
||||
get_folder(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn duplicate_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
||||
let mut request = get_request(id, pool).await?.clone();
|
||||
pub async fn duplicate_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
||||
let mut request = get_request(db, id).await?.clone();
|
||||
request.id = "".to_string();
|
||||
upsert_request(pool, request).await
|
||||
upsert_request(db, request).await
|
||||
}
|
||||
|
||||
pub async fn upsert_request(
|
||||
pool: &Pool<Sqlite>,
|
||||
r: HttpRequest,
|
||||
) -> Result<HttpRequest, sqlx::Error> {
|
||||
pub async fn upsert_request(db: &Pool<Sqlite>, r: HttpRequest) -> Result<HttpRequest, sqlx::Error> {
|
||||
let id = match r.id.as_str() {
|
||||
"" => generate_id(Some("rq")),
|
||||
_ => r.id.to_string(),
|
||||
@@ -824,15 +819,15 @@ pub async fn upsert_request(
|
||||
headers_json,
|
||||
r.sort_priority,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
get_request(&id, pool).await
|
||||
get_request(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn find_requests(
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Vec<HttpRequest>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
HttpRequest,
|
||||
@@ -859,11 +854,11 @@ pub async fn find_requests(
|
||||
"#,
|
||||
workspace_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
||||
pub async fn get_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
HttpRequest,
|
||||
r#"
|
||||
@@ -889,15 +884,15 @@ pub async fn get_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, s
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
||||
let req = get_request(id, pool).await?;
|
||||
pub async fn delete_request(db: &Pool<Sqlite>, id: &str) -> Result<HttpRequest, sqlx::Error> {
|
||||
let req = get_request(db, id).await?;
|
||||
|
||||
// DB deletes will cascade but this will delete the files
|
||||
delete_all_responses(id, pool).await?;
|
||||
delete_all_responses(db, id).await?;
|
||||
|
||||
let _ = sqlx::query!(
|
||||
r#"
|
||||
@@ -906,7 +901,7 @@ pub async fn delete_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
Ok(req)
|
||||
@@ -914,6 +909,7 @@ pub async fn delete_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn create_response(
|
||||
db: &Pool<Sqlite>,
|
||||
request_id: &str,
|
||||
elapsed: i64,
|
||||
elapsed_headers: i64,
|
||||
@@ -925,9 +921,8 @@ pub async fn create_response(
|
||||
headers: Vec<HttpResponseHeader>,
|
||||
version: Option<&str>,
|
||||
remote_addr: Option<&str>,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<HttpResponse, sqlx::Error> {
|
||||
let req = get_request(request_id, pool).await?;
|
||||
let req = get_request(db, request_id).await?;
|
||||
let id = generate_id(Some("rp"));
|
||||
let headers_json = Json(headers);
|
||||
sqlx::query!(
|
||||
@@ -963,13 +958,13 @@ pub async fn create_response(
|
||||
version,
|
||||
remote_addr,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
get_response(&id, pool).await
|
||||
get_response(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn cancel_pending_responses(pool: &Pool<Sqlite>) -> Result<(), sqlx::Error> {
|
||||
pub async fn cancel_pending_responses(db: &Pool<Sqlite>) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE http_responses
|
||||
@@ -977,24 +972,24 @@ pub async fn cancel_pending_responses(pool: &Pool<Sqlite>) -> Result<(), sqlx::E
|
||||
WHERE elapsed = 0;
|
||||
"#,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn update_response_if_id(
|
||||
db: &Pool<Sqlite>,
|
||||
response: &HttpResponse,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<HttpResponse, sqlx::Error> {
|
||||
if response.id.is_empty() {
|
||||
Ok(response.clone())
|
||||
} else {
|
||||
update_response(response, pool).await
|
||||
update_response(db, response).await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn upsert_workspace(
|
||||
pool: &Pool<Sqlite>,
|
||||
db: &Pool<Sqlite>,
|
||||
workspace: Workspace,
|
||||
) -> Result<Workspace, sqlx::Error> {
|
||||
let id = match workspace.id.as_str() {
|
||||
@@ -1031,15 +1026,15 @@ pub async fn upsert_workspace(
|
||||
workspace.setting_follow_redirects,
|
||||
workspace.setting_validate_certificates,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
|
||||
get_workspace(&id, pool).await
|
||||
get_workspace(db, &id).await
|
||||
}
|
||||
|
||||
pub async fn update_response(
|
||||
db: &Pool<Sqlite>,
|
||||
response: &HttpResponse,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<HttpResponse, sqlx::Error> {
|
||||
let headers_json = Json(&response.headers);
|
||||
sqlx::query!(
|
||||
@@ -1072,12 +1067,12 @@ pub async fn update_response(
|
||||
response.remote_addr,
|
||||
response.id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await?;
|
||||
get_response(&response.id, pool).await
|
||||
get_response(db, &response.id).await
|
||||
}
|
||||
|
||||
pub async fn get_response(id: &str, pool: &Pool<Sqlite>) -> Result<HttpResponse, sqlx::Error> {
|
||||
pub async fn get_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
HttpResponse,
|
||||
r#"
|
||||
@@ -1091,14 +1086,14 @@ pub async fn get_response(id: &str, pool: &Pool<Sqlite>) -> Result<HttpResponse,
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_responses(
|
||||
db: &Pool<Sqlite>,
|
||||
request_id: &str,
|
||||
limit: Option<i64>,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
||||
let limit_unwrapped = limit.unwrap_or_else(|| i64::MAX);
|
||||
sqlx::query_as!(
|
||||
@@ -1117,13 +1112,13 @@ pub async fn find_responses(
|
||||
request_id,
|
||||
limit_unwrapped,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_responses_by_workspace_id(
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<Vec<HttpResponse>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
HttpResponse,
|
||||
@@ -1139,12 +1134,12 @@ pub async fn find_responses_by_workspace_id(
|
||||
"#,
|
||||
workspace_id,
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_response(id: &str, pool: &Pool<Sqlite>) -> Result<HttpResponse, sqlx::Error> {
|
||||
let resp = get_response(id, pool).await?;
|
||||
pub async fn delete_response(db: &Pool<Sqlite>, id: &str) -> Result<HttpResponse, sqlx::Error> {
|
||||
let resp = get_response(db, id).await?;
|
||||
|
||||
// Delete the body file if it exists
|
||||
if let Some(p) = resp.body_path.clone() {
|
||||
@@ -1160,18 +1155,15 @@ pub async fn delete_response(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRespon
|
||||
"#,
|
||||
id,
|
||||
)
|
||||
.execute(pool)
|
||||
.execute(db)
|
||||
.await;
|
||||
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
pub async fn delete_all_responses(
|
||||
request_id: &str,
|
||||
pool: &Pool<Sqlite>,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
for r in find_responses(request_id, None, pool).await? {
|
||||
delete_response(&r.id, pool).await?;
|
||||
pub async fn delete_all_responses(db: &Pool<Sqlite>, request_id: &str) -> Result<(), sqlx::Error> {
|
||||
for r in find_responses(db, request_id, None).await? {
|
||||
delete_response(db, &r.id).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1204,10 +1196,10 @@ pub struct WorkspaceExportResources {
|
||||
|
||||
pub async fn get_workspace_export_resources(
|
||||
app_handle: &AppHandle,
|
||||
pool: &Pool<Sqlite>,
|
||||
db: &Pool<Sqlite>,
|
||||
workspace_id: &str,
|
||||
) -> WorkspaceExport {
|
||||
let workspace = get_workspace(workspace_id, pool)
|
||||
let workspace = get_workspace(db, workspace_id)
|
||||
.await
|
||||
.expect("Failed to get workspace");
|
||||
return WorkspaceExport {
|
||||
@@ -1216,13 +1208,13 @@ pub async fn get_workspace_export_resources(
|
||||
timestamp: chrono::Utc::now().naive_utc(),
|
||||
resources: WorkspaceExportResources {
|
||||
workspaces: vec![workspace],
|
||||
environments: find_environments(workspace_id, pool)
|
||||
environments: find_environments(db, workspace_id)
|
||||
.await
|
||||
.expect("Failed to get environments"),
|
||||
folders: find_folders(workspace_id, pool)
|
||||
folders: find_folders(db, workspace_id)
|
||||
.await
|
||||
.expect("Failed to get folders"),
|
||||
requests: find_requests(workspace_id, pool)
|
||||
requests: find_requests(db, workspace_id)
|
||||
.await
|
||||
.expect("Failed to get requests"),
|
||||
},
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import useResizeObserver from '@react-hook/resize-observer';
|
||||
import classNames from 'classnames';
|
||||
import { format } from 'date-fns';
|
||||
import type { CSSProperties, FormEvent } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import React, { useRef, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useAlert } from '../hooks/useAlert';
|
||||
import type { GrpcMessage } from '../hooks/useGrpc';
|
||||
import { useGrpc } from '../hooks/useGrpc';
|
||||
@@ -129,6 +130,12 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
return { value, options };
|
||||
}, [grpc.schema, method.value, service.value]);
|
||||
|
||||
const [paneSize, setPaneSize] = useState(99999);
|
||||
const urlContainerEl = useRef<HTMLDivElement>(null);
|
||||
useResizeObserver<HTMLDivElement>(urlContainerEl.current, (entry) => {
|
||||
setPaneSize(entry.contentRect.width);
|
||||
});
|
||||
|
||||
if (url.isLoading || url.value == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -138,7 +145,13 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
style={style}
|
||||
leftSlot={() => (
|
||||
<VStack space={2}>
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto_auto] gap-1.5">
|
||||
<div
|
||||
ref={urlContainerEl}
|
||||
className={classNames(
|
||||
'grid grid-cols-[minmax(0,1fr)_auto_auto] gap-1.5',
|
||||
paneSize < 350 && '!grid-cols-1',
|
||||
)}
|
||||
>
|
||||
<UrlBar
|
||||
id="foo"
|
||||
url={url.value ?? ''}
|
||||
@@ -150,32 +163,34 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
isLoading={grpc.unary.isLoading}
|
||||
onUrlChange={url.set}
|
||||
/>
|
||||
<Select
|
||||
hideLabel
|
||||
name="service"
|
||||
label="Service"
|
||||
className="text-gray-800"
|
||||
size="sm"
|
||||
value={select.value}
|
||||
onChange={handleChangeService}
|
||||
options={select.options}
|
||||
/>
|
||||
<IconButton
|
||||
className="border border-highlight"
|
||||
size="sm"
|
||||
title="ofo"
|
||||
hotkeyAction="request.send"
|
||||
onClick={handleConnect}
|
||||
icon={
|
||||
!activeMethod?.clientStreaming && activeMethod?.serverStreaming
|
||||
? 'arrowDownToDot'
|
||||
: activeMethod?.clientStreaming && !activeMethod?.serverStreaming
|
||||
? 'arrowUpFromDot'
|
||||
: activeMethod?.clientStreaming && activeMethod?.serverStreaming
|
||||
? 'arrowUpDown'
|
||||
: 'sendHorizontal'
|
||||
}
|
||||
/>
|
||||
<HStack space={1.5}>
|
||||
<Select
|
||||
hideLabel
|
||||
name="service"
|
||||
label="Service"
|
||||
className="text-gray-800"
|
||||
size="sm"
|
||||
value={select.value}
|
||||
onChange={handleChangeService}
|
||||
options={select.options}
|
||||
/>
|
||||
<IconButton
|
||||
className="border border-highlight"
|
||||
size="sm"
|
||||
title="ofo"
|
||||
hotkeyAction="request.send"
|
||||
onClick={handleConnect}
|
||||
icon={
|
||||
!activeMethod?.clientStreaming && activeMethod?.serverStreaming
|
||||
? 'arrowDownToDot'
|
||||
: activeMethod?.clientStreaming && !activeMethod?.serverStreaming
|
||||
? 'arrowUpFromDot'
|
||||
: activeMethod?.clientStreaming && activeMethod?.serverStreaming
|
||||
? 'arrowUpDown'
|
||||
: 'sendHorizontal'
|
||||
}
|
||||
/>
|
||||
</HStack>
|
||||
</div>
|
||||
<GrpcEditor
|
||||
forceUpdateKey={[service, method].join('::')}
|
||||
|
||||
@@ -102,7 +102,7 @@ export function SettingsDropdown() {
|
||||
label: 'Check for Updates',
|
||||
leftSlot: <Icon icon="update" />,
|
||||
onSelect: async () => {
|
||||
const hasUpdate: boolean = await invoke('check_for_updates');
|
||||
const hasUpdate: boolean = await invoke('cmd_check_for_updates');
|
||||
if (!hasUpdate) {
|
||||
alert({
|
||||
id: 'no-updates',
|
||||
|
||||
@@ -59,7 +59,7 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
||||
onClick={async () => {
|
||||
hide();
|
||||
const environmentId = (await getRecentEnvironments(w.id))[0];
|
||||
await invoke('new_window', {
|
||||
await invoke('cmd_new_window', {
|
||||
url: routes.paths.workspace({ workspaceId: w.id, environmentId }),
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -6,6 +6,7 @@ const gapClasses = {
|
||||
0: 'gap-0',
|
||||
0.5: 'gap-0.5',
|
||||
1: 'gap-1',
|
||||
1.5: 'gap-1.5',
|
||||
2: 'gap-2',
|
||||
3: 'gap-3',
|
||||
4: 'gap-4',
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useCookieJars() {
|
||||
queryKey: cookieJarsQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspaceId == null) return [];
|
||||
return (await invoke('list_cookie_jars', { workspaceId })) as CookieJar[];
|
||||
return (await invoke('cmd_list_cookie_jars', { workspaceId })) as CookieJar[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useCreateCookieJar() {
|
||||
label: 'Name',
|
||||
defaultValue: 'My Jar',
|
||||
});
|
||||
return invoke('create_cookie_jar', { workspaceId, name });
|
||||
return invoke('cmd_create_cookie_jar', { workspaceId, name });
|
||||
},
|
||||
onSettled: () => trackEvent('CookieJar', 'Create'),
|
||||
onSuccess: async (cookieJar) => {
|
||||
|
||||
@@ -22,7 +22,7 @@ export function useCreateEnvironment() {
|
||||
label: 'Name',
|
||||
defaultValue: 'My Environment',
|
||||
});
|
||||
return invoke('create_environment', { name, variables: [], workspaceId });
|
||||
return invoke('cmd_create_environment', { name, variables: [], workspaceId });
|
||||
},
|
||||
onSettled: () => trackEvent('Environment', 'Create'),
|
||||
onSuccess: async (environment) => {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function useCreateFolder() {
|
||||
}
|
||||
patch.name = patch.name || 'New Folder';
|
||||
patch.sortPriority = patch.sortPriority || -Date.now();
|
||||
return invoke('create_folder', { workspaceId, ...patch });
|
||||
return invoke('cmd_create_folder', { workspaceId, ...patch });
|
||||
},
|
||||
onSettled: () => trackEvent('Folder', 'Create'),
|
||||
onSuccess: async (request) => {
|
||||
|
||||
@@ -34,7 +34,7 @@ export function useCreateRequest() {
|
||||
}
|
||||
}
|
||||
patch.folderId = patch.folderId || activeRequest?.folderId;
|
||||
return invoke('create_request', { workspaceId, name: '', ...patch });
|
||||
return invoke('cmd_create_request', { workspaceId, name: '', ...patch });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpRequest', 'Create'),
|
||||
onSuccess: async (request) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ export function useCreateWorkspace({ navigateAfter }: { navigateAfter: boolean }
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<Workspace, unknown, Pick<Workspace, 'name'>>({
|
||||
mutationFn: (patch) => {
|
||||
return invoke('create_workspace', patch);
|
||||
return invoke('cmd_create_workspace', patch);
|
||||
},
|
||||
onSettled: () => trackEvent('Workspace', 'Create'),
|
||||
onSuccess: async (workspace) => {
|
||||
|
||||
@@ -27,7 +27,7 @@ export function useDeleteAnyRequest() {
|
||||
),
|
||||
});
|
||||
if (!confirmed) return null;
|
||||
return invoke('delete_request', { requestId: id });
|
||||
return invoke('cmd_delete_request', { requestId: id });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpRequest', 'Delete'),
|
||||
onSuccess: async (request) => {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
||||
),
|
||||
});
|
||||
if (!confirmed) return null;
|
||||
return invoke('delete_cookie_jar', { cookieJarId: cookieJar?.id });
|
||||
return invoke('cmd_delete_cookie_jar', { cookieJarId: cookieJar?.id });
|
||||
},
|
||||
onSettled: () => trackEvent('CookieJar', 'Delete'),
|
||||
onSuccess: async (cookieJar) => {
|
||||
|
||||
@@ -23,7 +23,7 @@ export function useDeleteEnvironment(environment: Environment | null) {
|
||||
),
|
||||
});
|
||||
if (!confirmed) return null;
|
||||
return invoke('delete_environment', { environmentId: environment?.id });
|
||||
return invoke('cmd_delete_environment', { environmentId: environment?.id });
|
||||
},
|
||||
onSettled: () => trackEvent('Environment', 'Delete'),
|
||||
onSuccess: async (environment) => {
|
||||
|
||||
@@ -26,7 +26,7 @@ export function useDeleteFolder(id: string | null) {
|
||||
),
|
||||
});
|
||||
if (!confirmed) return null;
|
||||
return invoke('delete_folder', { folderId: id });
|
||||
return invoke('cmd_delete_folder', { folderId: id });
|
||||
},
|
||||
onSettled: () => trackEvent('Folder', 'Delete'),
|
||||
onSuccess: async (folder) => {
|
||||
|
||||
@@ -8,7 +8,7 @@ export function useDeleteResponse(id: string | null) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<HttpResponse>({
|
||||
mutationFn: async () => {
|
||||
return await invoke('delete_response', { id: id });
|
||||
return await invoke('cmd_delete_response', { id: id });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpResponse', 'Delete'),
|
||||
onSuccess: ({ requestId, id: responseId }) => {
|
||||
|
||||
@@ -8,7 +8,7 @@ export function useDeleteResponses(requestId?: string) {
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
if (requestId === undefined) return;
|
||||
await invoke('delete_all_responses', { requestId });
|
||||
await invoke('cmd_delete_all_responses', { requestId });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpResponse', 'DeleteMany'),
|
||||
onSuccess: async () => {
|
||||
|
||||
@@ -28,7 +28,7 @@ export function useDeleteWorkspace(workspace: Workspace | null) {
|
||||
),
|
||||
});
|
||||
if (!confirmed) return null;
|
||||
return invoke('delete_workspace', { workspaceId: workspace?.id });
|
||||
return invoke('cmd_delete_workspace', { workspaceId: workspace?.id });
|
||||
},
|
||||
onSettled: () => trackEvent('Workspace', 'Delete'),
|
||||
onSuccess: async (workspace) => {
|
||||
|
||||
@@ -21,7 +21,7 @@ export function useDuplicateRequest({
|
||||
return useMutation<HttpRequest, string>({
|
||||
mutationFn: async () => {
|
||||
if (id === null) throw new Error("Can't duplicate a null request");
|
||||
return invoke('duplicate_request', { id });
|
||||
return invoke('cmd_duplicate_request', { id });
|
||||
},
|
||||
onSettled: () => trackEvent('HttpRequest', 'Duplicate'),
|
||||
onSuccess: async (request) => {
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useEnvironments() {
|
||||
queryKey: environmentsQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspaceId == null) return [];
|
||||
return (await invoke('list_environments', { workspaceId })) as Environment[];
|
||||
return (await invoke('cmd_list_environments', { workspaceId })) as Environment[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -25,7 +25,7 @@ export function useExportData() {
|
||||
return;
|
||||
}
|
||||
|
||||
await invoke('export_data', { workspaceId: workspace.id, exportPath });
|
||||
await invoke('cmd_export_data', { workspaceId: workspace.id, exportPath });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export function useFilterResponse({
|
||||
return null;
|
||||
}
|
||||
|
||||
return (await invoke('filter_response', { responseId, filter })) as string | null;
|
||||
return (await invoke('cmd_filter_response', { responseId, filter })) as string | null;
|
||||
},
|
||||
}).data ?? null
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useFolders() {
|
||||
queryKey: foldersQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspaceId == null) return [];
|
||||
return (await invoke('list_folders', { workspaceId })) as Folder[];
|
||||
return (await invoke('cmd_list_folders', { workspaceId })) as Folder[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -30,7 +30,7 @@ export function useGrpc(url: string | null) {
|
||||
mutationKey: ['grpc_unary', url],
|
||||
mutationFn: async ({ service, method, message }) => {
|
||||
if (url === null) throw new Error('No URL provided');
|
||||
return (await invoke('grpc_call_unary', {
|
||||
return (await invoke('cmd_grpc_call_unary', {
|
||||
endpoint: url,
|
||||
service,
|
||||
method,
|
||||
@@ -50,7 +50,7 @@ export function useGrpc(url: string | null) {
|
||||
setMessages([
|
||||
{ isServer: false, message: JSON.stringify(JSON.parse(message)), time: new Date() },
|
||||
]);
|
||||
return (await invoke('grpc_server_streaming', {
|
||||
return (await invoke('cmd_grpc_server_streaming', {
|
||||
endpoint: url,
|
||||
service,
|
||||
method,
|
||||
@@ -64,7 +64,7 @@ export function useGrpc(url: string | null) {
|
||||
queryFn: async () => {
|
||||
if (url === null) return [];
|
||||
console.log('GETTING SCHEMA', url);
|
||||
return (await invoke('grpc_reflect', { endpoint: url })) as ReflectResponseService[];
|
||||
return (await invoke('cmd_grpc_reflect', { endpoint: url })) as ReflectResponseService[];
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export function useImportData() {
|
||||
environments: Environment[];
|
||||
folders: Folder[];
|
||||
requests: HttpRequest[];
|
||||
} = await invoke('import_data', {
|
||||
} = await invoke('cmd_import_data', {
|
||||
filePaths: Array.isArray(selected) ? selected : [selected],
|
||||
});
|
||||
const importedWorkspace = imported.workspaces[0];
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useRequests() {
|
||||
queryKey: requestsQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspaceId == null) return [];
|
||||
return (await invoke('list_requests', { workspaceId })) as HttpRequest[];
|
||||
return (await invoke('cmd_list_requests', { workspaceId })) as HttpRequest[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -13,7 +13,7 @@ export function useResponses(requestId: string | null) {
|
||||
initialData: [],
|
||||
queryKey: responsesQueryKey({ requestId: requestId ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
return (await invoke('list_responses', { requestId, limit: 200 })) as HttpResponse[];
|
||||
return (await invoke('cmd_list_responses', { requestId, limit: 200 })) as HttpResponse[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ export function useSendAnyRequest(options: { download?: boolean } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
return invoke('send_request', {
|
||||
return invoke('cmd_send_request', {
|
||||
requestId: id,
|
||||
environmentId,
|
||||
downloadDir: downloadDir,
|
||||
|
||||
@@ -11,7 +11,7 @@ export function useSettings() {
|
||||
useQuery({
|
||||
queryKey: settingsQueryKey(),
|
||||
queryFn: async () => {
|
||||
return (await invoke('get_settings')) as Settings;
|
||||
return (await invoke('cmd_get_settings')) as Settings;
|
||||
},
|
||||
}).data ?? undefined
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ export function useUpdateAnyFolder() {
|
||||
throw new Error("Can't update a null folder");
|
||||
}
|
||||
|
||||
await invoke('update_folder', { folder: update(folder) });
|
||||
await invoke('cmd_update_folder', { folder: update(folder) });
|
||||
},
|
||||
onMutate: async ({ id, update }) => {
|
||||
const folder = await getFolder(id);
|
||||
|
||||
@@ -20,7 +20,7 @@ export function useUpdateAnyRequest() {
|
||||
|
||||
const patchedRequest =
|
||||
typeof update === 'function' ? update(request) : { ...request, ...update };
|
||||
await invoke('update_request', { request: patchedRequest });
|
||||
await invoke('cmd_update_request', { request: patchedRequest });
|
||||
},
|
||||
onMutate: async ({ id, update }) => {
|
||||
const request = await getRequest(id);
|
||||
|
||||
@@ -15,7 +15,7 @@ export function useUpdateCookieJar(id: string | null) {
|
||||
|
||||
const newCookieJar = typeof v === 'function' ? v(cookieJar) : { ...cookieJar, ...v };
|
||||
console.log('NEW COOKIE JAR', newCookieJar.cookies.length);
|
||||
await invoke('update_cookie_jar', { cookieJar: newCookieJar });
|
||||
await invoke('cmd_update_cookie_jar', { cookieJar: newCookieJar });
|
||||
},
|
||||
onMutate: async (v) => {
|
||||
const cookieJar = await getCookieJar(id);
|
||||
|
||||
@@ -14,7 +14,7 @@ export function useUpdateEnvironment(id: string | null) {
|
||||
}
|
||||
|
||||
const newEnvironment = typeof v === 'function' ? v(environment) : { ...environment, ...v };
|
||||
await invoke('update_environment', { environment: newEnvironment });
|
||||
await invoke('cmd_update_environment', { environment: newEnvironment });
|
||||
},
|
||||
onMutate: async (v) => {
|
||||
const environment = await getEnvironment(id);
|
||||
|
||||
@@ -8,7 +8,7 @@ export function useUpdateSettings() {
|
||||
|
||||
return useMutation<void, unknown, Settings>({
|
||||
mutationFn: async (settings) => {
|
||||
await invoke('update_settings', { settings });
|
||||
await invoke('cmd_update_settings', { settings });
|
||||
},
|
||||
onMutate: async (settings) => {
|
||||
queryClient.setQueryData<Settings>(settingsQueryKey(), settings);
|
||||
|
||||
@@ -14,7 +14,7 @@ export function useUpdateWorkspace(id: string | null) {
|
||||
}
|
||||
|
||||
const newWorkspace = typeof v === 'function' ? v(workspace) : { ...workspace, ...v };
|
||||
await invoke('update_workspace', { workspace: newWorkspace });
|
||||
await invoke('cmd_update_workspace', { workspace: newWorkspace });
|
||||
},
|
||||
onMutate: async (v) => {
|
||||
const workspace = await getWorkspace(id);
|
||||
|
||||
@@ -11,7 +11,7 @@ export function useVariables({ environmentId }: { environmentId: string }) {
|
||||
useQuery({
|
||||
queryKey: variablesQueryKey({ environmentId }),
|
||||
queryFn: async () => {
|
||||
return (await invoke('list_variables', { environmentId })) as EnvironmentVariable[];
|
||||
return (await invoke('cmd_list_variables', { environmentId })) as EnvironmentVariable[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
@@ -10,7 +10,7 @@ export function workspacesQueryKey(_?: {}) {
|
||||
export function useWorkspaces() {
|
||||
return (
|
||||
useQuery(workspacesQueryKey(), async () => {
|
||||
return (await invoke('list_workspaces')) as Workspace[];
|
||||
return (await invoke('cmd_list_workspaces')) as Workspace[];
|
||||
}).data ?? []
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export function trackEvent(
|
||||
| 'Duplicate',
|
||||
attributes: Record<string, string | number> = {},
|
||||
) {
|
||||
invoke('track_event', {
|
||||
invoke('cmd_track_event', {
|
||||
resource: resource,
|
||||
action,
|
||||
attributes,
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function setKeyValue<T>({
|
||||
key: string | string[];
|
||||
value: T;
|
||||
}): Promise<void> {
|
||||
await invoke('set_key_value', {
|
||||
await invoke('cmd_set_key_value', {
|
||||
namespace,
|
||||
key: buildKeyValueKey(key),
|
||||
value: JSON.stringify(value),
|
||||
@@ -30,7 +30,7 @@ export async function getKeyValue<T>({
|
||||
key: string | string[];
|
||||
fallback: T;
|
||||
}) {
|
||||
const kv = (await invoke('get_key_value', {
|
||||
const kv = (await invoke('cmd_get_key_value', {
|
||||
namespace,
|
||||
key: buildKeyValueKey(key),
|
||||
})) as KeyValue | null;
|
||||
|
||||
@@ -7,5 +7,5 @@ export async function sendEphemeralRequest(
|
||||
): Promise<HttpResponse> {
|
||||
// Remove some things that we don't want to associate
|
||||
const newRequest = { ...request };
|
||||
return invoke('send_ephemeral_request', { request: newRequest, environmentId });
|
||||
return invoke('cmd_send_ephemeral_request', { request: newRequest, environmentId });
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ import { invoke } from '@tauri-apps/api';
|
||||
import type { CookieJar, Environment, Folder, HttpRequest, Settings, Workspace } from './models';
|
||||
|
||||
export async function getSettings(): Promise<Settings> {
|
||||
return invoke('get_settings', {});
|
||||
return invoke('cmd_get_settings', {});
|
||||
}
|
||||
|
||||
export async function getRequest(id: string | null): Promise<HttpRequest | null> {
|
||||
if (id === null) return null;
|
||||
const request: HttpRequest = (await invoke('get_request', { id })) ?? null;
|
||||
const request: HttpRequest = (await invoke('cmd_get_request', { id })) ?? null;
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export async function getRequest(id: string | null): Promise<HttpRequest | null>
|
||||
|
||||
export async function getEnvironment(id: string | null): Promise<Environment | null> {
|
||||
if (id === null) return null;
|
||||
const environment: Environment = (await invoke('get_environment', { id })) ?? null;
|
||||
const environment: Environment = (await invoke('cmd_get_environment', { id })) ?? null;
|
||||
if (environment == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export async function getEnvironment(id: string | null): Promise<Environment | n
|
||||
|
||||
export async function getFolder(id: string | null): Promise<Folder | null> {
|
||||
if (id === null) return null;
|
||||
const folder: Folder = (await invoke('get_folder', { id })) ?? null;
|
||||
const folder: Folder = (await invoke('cmd_get_folder', { id })) ?? null;
|
||||
if (folder == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export async function getFolder(id: string | null): Promise<Folder | null> {
|
||||
|
||||
export async function getWorkspace(id: string | null): Promise<Workspace | null> {
|
||||
if (id === null) return null;
|
||||
const workspace: Workspace = (await invoke('get_workspace', { id })) ?? null;
|
||||
const workspace: Workspace = (await invoke('cmd_get_workspace', { id })) ?? null;
|
||||
if (workspace == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export async function getWorkspace(id: string | null): Promise<Workspace | null>
|
||||
|
||||
export async function getCookieJar(id: string | null): Promise<CookieJar | null> {
|
||||
if (id === null) return null;
|
||||
const cookieJar: CookieJar = (await invoke('get_cookie_jar', { id })) ?? null;
|
||||
const cookieJar: CookieJar = (await invoke('cmd_get_cookie_jar', { id })) ?? null;
|
||||
if (cookieJar == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { type } from '@tauri-apps/api/os';
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { StrictMode } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { attachConsole } from 'tauri-plugin-log-api';
|
||||
import { App } from './components/App';
|
||||
import { maybeRestorePathname } from './lib/persistPathname';
|
||||
import './main.css';
|
||||
import { getSettings } from './lib/store';
|
||||
import type { Appearance } from './lib/theme/window';
|
||||
import { setAppearanceOnDocument } from './lib/theme/window';
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { type } from '@tauri-apps/api/os';
|
||||
|
||||
// Hide decorations here because it doesn't work in Rust for some reason (bug?)
|
||||
const osType = await type();
|
||||
@@ -17,8 +14,8 @@ if (osType !== 'Darwin') {
|
||||
await appWindow.setDecorations(false);
|
||||
}
|
||||
|
||||
await attachConsole();
|
||||
await maybeRestorePathname();
|
||||
// await attachConsole();
|
||||
// await maybeRestorePathname();
|
||||
|
||||
const settings = await getSettings();
|
||||
setAppearanceOnDocument(settings.appearance as Appearance);
|
||||
|
||||
Reference in New Issue
Block a user