Initial commit
This commit is contained in:
48
src-tauri/src/main.rs
Normal file
48
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
struct Keys {
|
||||
openrouter_api_key: Option<String>,
|
||||
elevenlabs_api_key: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_env_keys() -> Keys {
|
||||
// In development, the CWD is `src-tauri/target/debug`, so we go up two levels
|
||||
// to find the project root.
|
||||
if let Ok(path) = std::env::current_dir() {
|
||||
if let Some(p) = path.ancestors().nth(2) {
|
||||
let env_path = p.join(".env");
|
||||
dotenvy::from_path(env_path).ok();
|
||||
}
|
||||
} else {
|
||||
dotenvy::dotenv().ok();
|
||||
}
|
||||
|
||||
let openrouter_api_key = std::env::var("OPENROUTER_API_KEY").ok();
|
||||
let elevenlabs_api_key = std::env::var("ELEVENLABS_API_KEY").ok();
|
||||
Keys { openrouter_api_key, elevenlabs_api_key }
|
||||
}
|
||||
|
||||
// Commands that can be called from the frontend
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! Welcome to EVE.", name)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![greet, get_env_keys])
|
||||
.setup(|_app| {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
// DevTools are available via F12 or the context menu
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
Reference in New Issue
Block a user