Files
yaoayanui/src-tauri/src/lib.rs
fengchuanhn@gmail.com cdbf605205 1
2026-05-18 15:11:59 +08:00

88 lines
3.4 KiB
Rust

pub mod api_client;
pub mod api_crypto;
pub mod app_config;
pub mod audio_db;
pub mod audio_store;
pub mod avatar_db;
pub mod avatar_store;
pub mod local_config;
pub mod asr;
pub mod auth_session;
pub mod chat;
pub mod commands;
pub mod ffmpeg;
pub mod http;
pub mod js_runtime;
pub mod nodejs;
pub mod oss;
use tauri::Manager;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let _ = env_logger::try_init();
tauri::Builder::default()
.manage(auth_session::AuthSession::default())
.manage(app_config::AppConfig::new())
.manage(avatar_store::AvatarStore::new())
.manage(audio_store::AudioStore::new())
.setup(|app| {
let handle = app.handle().clone();
tauri::async_runtime::block_on(async move {
let app_config = handle.state::<app_config::AppConfig>();
let avatar_store = handle.state::<avatar_store::AvatarStore>();
let audio_store = handle.state::<audio_store::AudioStore>();
let dir = handle
.path()
.app_data_dir()
.map_err(|e| format!("无法获取应用数据目录: {e}"))?;
let db_path = dir.join("local_config.db");
app_config.init_local_store(db_path).await?;
avatar_store.init(dir.join("avatars.db")).await?;
audio_store.init(dir.join("generated_audios.db")).await?;
Ok::<(), String>(())
})
.map_err(|e| -> Box<dyn std::error::Error> { e.into() })?;
Ok(())
})
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
if let Some(window) = app.get_webview_window("main") {
let _ = window.unminimize();
let _ = window.show();
let _ = window.set_focus();
}
}))
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.invoke_handler(tauri::generate_handler![
commands::api::api_request,
commands::auth::sync_auth_session,
commands::app_config::get_app_config,
commands::app_config::get_app_config_last_message,
commands::app_config::get_server_app_config,
commands::app_config::get_app_config_detail,
commands::app_config::list_local_app_config,
commands::app_config::set_local_app_config,
commands::app_config::delete_local_app_config,
commands::quickjs::run_quickjs_script,
commands::quickjs::run_quickjs_script_source,
commands::quickjs::list_quickjs_scripts,
commands::nodejs::run_nodejs_script,
commands::nodejs::run_nodejs_script_source,
commands::nodejs::list_nodejs_scripts,
commands::fs_util::read_local_file_base64,
commands::avatar::list_avatars,
commands::avatar::insert_avatar,
commands::avatar::update_avatar_name,
commands::avatar::delete_avatar,
commands::avatar::avatar_name_exists,
commands::avatar::import_avatar_video,
commands::audio::list_generated_audios,
commands::audio::insert_generated_audio,
commands::audio::delete_generated_audio,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}