This commit is contained in:
Julian Freeman
2026-04-19 08:55:44 -04:00
parent eb1d802f5b
commit e256e596c5
7 changed files with 161 additions and 80 deletions

View File

@@ -1,6 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
/target*/
# Generated by Tauri
# will have schema files for capabilities auto-completion

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::time::Instant;
use serde::{Serialize, Deserialize};
use tauri::State;
#[derive(Serialize, Deserialize)]
struct HttpResponse {
@@ -39,8 +40,13 @@ struct AuthConfig {
api_key: ApiKeyAuth,
}
struct AppState {
client: reqwest::Client,
}
#[tauri::command]
async fn execute_request(
state: State<'_, AppState>,
method: String,
url: String,
headers: HashMap<String, String>,
@@ -48,14 +54,8 @@ async fn execute_request(
query_params: Option<HashMap<String, String>>,
auth: Option<AuthConfig>,
) -> Result<HttpResponse, String> {
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.map_err(|e| e.to_string())?;
let req_method = method.parse::<reqwest::Method>().map_err(|e| e.to_string())?;
let mut request_builder = client.request(req_method, &url);
let mut request_builder = state.client.request(req_method, &url);
// Add Query Params
if let Some(params) = query_params {
@@ -126,9 +126,15 @@ async fn execute_request(
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.expect("failed to create HTTP client");
tauri::Builder::default()
.manage(AppState { client })
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![execute_request])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}