modules system init

This commit is contained in:
2026-02-15 19:29:17 +08:00
parent 9a87231572
commit 285fdcab1f
3 changed files with 90 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ use crate::{
active_app::init_foreground_app_change_listener,
auth::get_session_token,
cursor::init_cursor_tracking,
modules::init_modules,
scene::{close_splash_window, open_splash_window},
welcome::open_welcome_window,
},
@@ -25,6 +26,7 @@ pub async fn launch_app() {
init_app_state();
init_system_tray();
init_cursor_tracking().await;
init_modules();
init_foreground_app_change_listener();
if let Err(err) = validate_server_health().await {

View File

@@ -11,6 +11,7 @@ pub mod doll_editor;
pub mod health_manager;
pub mod health_monitor;
pub mod interaction;
pub mod modules;
pub mod scene;
pub mod sprite_recolor;
pub mod welcome;

View File

@@ -0,0 +1,87 @@
use tauri::Manager;
use tracing::{error, info, warn};
use crate::get_app_handle;
use serde::{Deserialize, Serialize};
use serde_json;
use std::{fs, path::PathBuf};
#[derive(Serialize, Deserialize, Debug)]
pub struct ModuleMetadata {
pub name: String,
pub version: String,
pub description: Option<String>,
}
fn get_module_metadata(path: PathBuf) -> Option<ModuleMetadata> {
let metadata_path = path.join("metadata.json");
if metadata_path.exists() {
match fs::read_to_string(&metadata_path) {
Ok(content) => match serde_json::from_str::<ModuleMetadata>(&content) {
Ok(metadata) => {
info!(
"Loaded module metadata: {} v{} - {:?}",
metadata.name, metadata.version, metadata.description
);
return Some(metadata);
}
Err(e) => {
warn!("Failed to parse metadata.json in {}: {}", path.display(), e);
None
}
},
Err(e) => {
warn!("Failed to read metadata.json in {}: {}", path.display(), e);
None
}
}
} else {
None
}
}
/// Initialize installed modules
pub fn init_modules() {
let modules_path = get_app_handle()
.path()
.app_data_dir()
.expect("App data directory is unavailable.")
.join("modules");
if !modules_path.exists() {
if let Err(e) = fs::create_dir_all(&modules_path) {
error!("Failed to create modules directory: {}", e);
return;
}
return;
}
let entries = match fs::read_dir(&modules_path) {
Ok(entries) => entries,
Err(e) => {
error!("Failed to read app data directory: {}", e);
return;
}
};
for entry in entries {
let entry = match entry {
Ok(entry) => entry,
Err(e) => {
warn!("Failed to read directory entry: {}", e);
continue;
}
};
let path = entry.path();
if path.is_dir() {
let module_metadata = match get_module_metadata(path) {
Some(metadata) => metadata,
None => continue,
};
dbg!(module_metadata);
// TODO: Initialize the module based on metadata
}
}
}