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-05-03 20:55:21 +00:00
|
|
|
use arboard::Clipboard;
|
2024-04-05 20:23:01 +00:00
|
|
|
use keyring::Entry;
|
2024-04-20 15:03:39 +00:00
|
|
|
use serde::Serialize;
|
2024-04-05 20:23:01 +00:00
|
|
|
|
2024-03-28 21:26:48 +00:00
|
|
|
fn main() {
|
|
|
|
tauri::Builder::default()
|
2024-05-03 20:55:21 +00:00
|
|
|
.invoke_handler(tauri::generate_handler![store_secret, get_secret, delete_secret, set_clipboard])
|
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]
|
2024-04-20 15:03:39 +00:00
|
|
|
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();
|
2024-04-20 15:03:39 +00:00
|
|
|
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]
|
2024-04-20 15:03:39 +00:00
|
|
|
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();
|
2024-04-20 15:03:39 +00:00
|
|
|
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-05-03 20:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tauri::command]
|
|
|
|
fn set_clipboard(text: String) -> SetClipboardResponse {
|
|
|
|
let clipboard_result = Clipboard::new();
|
|
|
|
let mut clipboard = match clipboard_result {
|
|
|
|
Ok(clipboard) => clipboard,
|
|
|
|
Err(e) => return SetClipboardResponse {
|
|
|
|
success: false,
|
|
|
|
issue: e.to_string(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let set_text_result = clipboard.set_text(text);
|
|
|
|
match set_text_result {
|
|
|
|
Ok(_) => SetClipboardResponse {
|
|
|
|
success: true,
|
|
|
|
issue: String::from(""),
|
|
|
|
},
|
|
|
|
|
|
|
|
Err(e) => SetClipboardResponse {
|
|
|
|
success: false,
|
|
|
|
issue: e.to_string(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
struct SetClipboardResponse {
|
|
|
|
success: bool,
|
|
|
|
issue: String,
|
2024-04-05 20:23:01 +00:00
|
|
|
}
|