mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-05 14:49:06 +00:00
Improved error handling & added delete secret as well
This commit is contained in:
parent
62e16f2897
commit
463bd7e435
@ -2,22 +2,83 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use keyring::Entry;
|
||||
use serde::Serialize;
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![store_secret, get_secret])
|
||||
.invoke_handler(tauri::generate_handler![store_secret, get_secret, delete_secret])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn store_secret(destination: String, user_name: String, secret: String) {
|
||||
fn store_secret(destination: String, user_name: String, secret: String) -> StoreSecretResponse {
|
||||
let entry = Entry::new(&format!("mindwork-ai-studio::{}", destination), user_name.as_str()).unwrap();
|
||||
entry.set_password(secret.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,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_secret(destination: String, user_name: String) -> String {
|
||||
fn get_secret(destination: String, user_name: String) -> RequestedSecret {
|
||||
let entry = Entry::new(&format!("mindwork-ai-studio::{}", destination), user_name.as_str()).unwrap();
|
||||
entry.get_password().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,
|
||||
}
|
Loading…
Reference in New Issue
Block a user