AI-Studio/runtime/src/main.rs

84 lines
2.3 KiB
Rust
Raw Normal View History

2024-03-28 21:26:48 +00:00
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2024-04-05 20:23:01 +00:00
use keyring::Entry;
use serde::Serialize;
2024-04-05 20:23:01 +00:00
2024-03-28 21:26:48 +00:00
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![store_secret, get_secret, delete_secret])
2024-03-28 21:26:48 +00:00
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
2024-04-05 20:23:01 +00:00
#[tauri::command]
fn store_secret(destination: String, user_name: String, secret: String) -> StoreSecretResponse {
2024-04-05 20:23:01 +00:00
let entry = Entry::new(&format!("mindwork-ai-studio::{}", destination), user_name.as_str()).unwrap();
let result = entry.set_password(secret.as_str());
match result {
Ok(_) => StoreSecretResponse {
success: true,
issue: String::from(""),
},
Err(e) => StoreSecretResponse {
success: false,
issue: e.to_string(),
},
}
}
#[derive(Serialize)]
struct StoreSecretResponse {
success: bool,
issue: String,
2024-04-05 20:23:01 +00:00
}
#[tauri::command]
fn get_secret(destination: String, user_name: String) -> RequestedSecret {
2024-04-05 20:23:01 +00:00
let entry = Entry::new(&format!("mindwork-ai-studio::{}", destination), user_name.as_str()).unwrap();
let secret = entry.get_password();
match secret {
Ok(s) => RequestedSecret {
success: true,
secret: s,
issue: String::from(""),
},
Err(e) => RequestedSecret {
success: false,
secret: String::from(""),
issue: e.to_string(),
},
}
}
#[derive(Serialize)]
struct RequestedSecret {
success: bool,
secret: String,
issue: String,
}
#[tauri::command]
fn delete_secret(destination: String, user_name: String) -> DeleteSecretResponse {
let entry = Entry::new(&format!("mindwork-ai-studio::{}", destination), user_name.as_str()).unwrap();
let result = entry.delete_password();
match result {
Ok(_) => DeleteSecretResponse {
success: true,
issue: String::from(""),
},
Err(e) => DeleteSecretResponse {
success: false,
issue: e.to_string(),
},
}
}
#[derive(Serialize)]
struct DeleteSecretResponse {
success: bool,
issue: String,
2024-04-05 20:23:01 +00:00
}