* refactor: reorganize package structure and decouple framework packages ## Package Structure Reorganization - Reorganized 55 packages into categorized subdirectories: - packages/framework/ - Generic framework (Laya/Cocos compatible) - packages/engine/ - ESEngine core modules - packages/rendering/ - Rendering modules (WASM dependent) - packages/physics/ - Physics modules - packages/streaming/ - World streaming - packages/network-ext/ - Network extensions - packages/editor/ - Editor framework and plugins - packages/rust/ - Rust WASM engine - packages/tools/ - Build tools and SDK ## Framework Package Decoupling - Decoupled behavior-tree and blueprint packages from ESEngine dependencies - Created abstracted interfaces (IBTAssetManager, IBehaviorTreeAssetContent) - ESEngine-specific code moved to esengine/ subpath exports - Framework packages now usable with Cocos/Laya without ESEngine ## CI Configuration - Updated CI to only type-check and lint framework packages - Added type-check:framework and lint:framework scripts ## Breaking Changes - Package import paths changed due to directory reorganization - ESEngine integrations now use subpath imports (e.g., '@esengine/behavior-tree/esengine') * fix: update es-engine file path after directory reorganization * docs: update README to focus on framework over engine * ci: only build framework packages, remove Rust/WASM dependencies * fix: remove esengine subpath from behavior-tree and blueprint builds ESEngine integration code will only be available in full engine builds. Framework packages are now purely engine-agnostic. * fix: move network-protocols to framework, build both in CI * fix: update workflow paths from packages/core to packages/framework/core * fix: exclude esengine folder from type-check in behavior-tree and blueprint * fix: update network tsconfig references to new paths * fix: add test:ci:framework to only test framework packages in CI * fix: only build core and math npm packages in CI * fix: exclude test files from CodeQL and fix string escaping security issue
213 lines
7.6 KiB
Rust
213 lines
7.6 KiB
Rust
//! ESEngine Editor - Tauri Backend
|
|
//!
|
|
//! Clean entry point that handles application setup and command registration.
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
mod commands;
|
|
mod profiler_ws;
|
|
mod state;
|
|
|
|
use std::collections::HashMap;
|
|
use std::sync::{Arc, Mutex};
|
|
use tauri::Manager;
|
|
|
|
use state::{ProfilerState, ProjectPaths, ScriptWatcherState};
|
|
|
|
fn main() {
|
|
// Initialize shared state | 初始化共享状态
|
|
let project_paths: ProjectPaths = Arc::new(Mutex::new(HashMap::new()));
|
|
let project_paths_for_protocol = Arc::clone(&project_paths);
|
|
|
|
let profiler_state = ProfilerState::new();
|
|
let script_watcher_state = ScriptWatcherState::new();
|
|
|
|
// Build and run the Tauri application
|
|
tauri::Builder::default()
|
|
// Register plugins
|
|
.plugin(tauri_plugin_shell::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_fs::init())
|
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
|
.plugin(tauri_plugin_http::init())
|
|
.plugin(tauri_plugin_cli::init())
|
|
// Register custom URI scheme for project files
|
|
.register_uri_scheme_protocol("project", move |_app, request| {
|
|
handle_project_protocol(request, &project_paths_for_protocol)
|
|
})
|
|
// Setup application state | 设置应用状态
|
|
.setup(move |app| {
|
|
app.manage(project_paths);
|
|
app.manage(profiler_state);
|
|
app.manage(script_watcher_state);
|
|
Ok(())
|
|
})
|
|
// Register all commands
|
|
.invoke_handler(tauri::generate_handler![
|
|
// Project management
|
|
commands::open_project,
|
|
commands::save_project,
|
|
commands::export_binary,
|
|
commands::set_project_base_path,
|
|
commands::scan_behavior_trees,
|
|
// File system operations
|
|
commands::read_file_content,
|
|
commands::write_file_content,
|
|
commands::write_binary_file,
|
|
commands::append_to_log,
|
|
commands::path_exists,
|
|
commands::create_directory,
|
|
commands::create_file,
|
|
commands::delete_file,
|
|
commands::delete_folder,
|
|
commands::rename_file_or_folder,
|
|
commands::list_directory,
|
|
commands::scan_directory,
|
|
commands::read_file_as_base64,
|
|
commands::copy_file,
|
|
commands::get_file_mtime,
|
|
// Dialog operations
|
|
commands::open_folder_dialog,
|
|
commands::open_file_dialog,
|
|
commands::save_file_dialog,
|
|
// Profiler server
|
|
commands::start_profiler_server,
|
|
commands::stop_profiler_server,
|
|
commands::get_profiler_status,
|
|
// Plugin management
|
|
commands::build_plugin,
|
|
commands::install_marketplace_plugin,
|
|
commands::uninstall_marketplace_plugin,
|
|
// System operations
|
|
commands::toggle_devtools,
|
|
commands::open_file_with_default_app,
|
|
commands::open_folder,
|
|
commands::show_in_folder,
|
|
commands::get_temp_dir,
|
|
commands::open_with_editor,
|
|
commands::update_project_tsconfig,
|
|
commands::get_app_resource_dir,
|
|
commands::get_current_dir,
|
|
commands::start_local_server,
|
|
commands::stop_local_server,
|
|
commands::get_local_ip,
|
|
commands::generate_qrcode,
|
|
// User code compilation | 用户代码编译
|
|
commands::compile_typescript,
|
|
commands::check_types,
|
|
commands::watch_scripts,
|
|
commands::watch_assets,
|
|
commands::stop_watch_scripts,
|
|
commands::check_environment,
|
|
commands::install_esbuild,
|
|
// Build commands | 构建命令
|
|
commands::prepare_build_directory,
|
|
commands::copy_directory,
|
|
commands::bundle_scripts,
|
|
commands::generate_html,
|
|
commands::get_file_size,
|
|
commands::get_directory_size,
|
|
commands::write_json_file,
|
|
commands::list_files_by_extension,
|
|
commands::read_binary_file_as_base64,
|
|
commands::read_binary_file,
|
|
// Engine modules | 引擎模块
|
|
commands::read_engine_modules_index,
|
|
commands::read_module_manifest,
|
|
commands::get_engine_modules_base_path,
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|
|
|
|
/// Handle the custom 'project://' URI scheme protocol
|
|
///
|
|
/// This allows the frontend to load project files through a custom protocol,
|
|
/// enabling features like hot-reloading plugins from the project directory.
|
|
fn handle_project_protocol(
|
|
request: tauri::http::Request<Vec<u8>>,
|
|
project_paths: &ProjectPaths,
|
|
) -> tauri::http::Response<Vec<u8>> {
|
|
let uri = request.uri();
|
|
let path = uri.path();
|
|
|
|
// Debug logging
|
|
println!("[project://] Full URI: {}", uri);
|
|
println!("[project://] Path: {}", path);
|
|
|
|
let file_path = {
|
|
let paths = match project_paths.lock() {
|
|
Ok(p) => p,
|
|
Err(_) => {
|
|
return tauri::http::Response::builder()
|
|
.status(500)
|
|
.body(Vec::new())
|
|
.unwrap();
|
|
}
|
|
};
|
|
|
|
match paths.get("current") {
|
|
Some(base_path) => format!("{}{}", base_path, path),
|
|
None => {
|
|
return tauri::http::Response::builder()
|
|
.status(404)
|
|
.body(Vec::new())
|
|
.unwrap();
|
|
}
|
|
}
|
|
};
|
|
|
|
match std::fs::read(&file_path) {
|
|
Ok(content) => {
|
|
let mime_type = get_mime_type(&file_path);
|
|
|
|
tauri::http::Response::builder()
|
|
.status(200)
|
|
.header("Content-Type", mime_type)
|
|
// CORS headers for dynamic ES module imports | 动态 ES 模块导入所需的 CORS 头
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
.header("Access-Control-Allow-Methods", "GET, OPTIONS")
|
|
.header("Access-Control-Allow-Headers", "Content-Type")
|
|
.header("Access-Control-Expose-Headers", "Content-Length")
|
|
// Allow cross-origin script loading | 允许跨域脚本加载
|
|
.header("Cross-Origin-Resource-Policy", "cross-origin")
|
|
.body(content)
|
|
.unwrap()
|
|
}
|
|
Err(e) => {
|
|
eprintln!("Failed to read file {}: {}", file_path, e);
|
|
tauri::http::Response::builder()
|
|
.status(404)
|
|
.header("Access-Control-Allow-Origin", "*")
|
|
.body(Vec::new())
|
|
.unwrap()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Get MIME type based on file extension
|
|
/// 根据文件扩展名获取 MIME 类型
|
|
fn get_mime_type(file_path: &str) -> &'static str {
|
|
if file_path.ends_with(".ts") || file_path.ends_with(".tsx") {
|
|
"application/javascript"
|
|
} else if file_path.ends_with(".js") || file_path.ends_with(".mjs") {
|
|
"application/javascript"
|
|
} else if file_path.ends_with(".json") {
|
|
"application/json"
|
|
} else if file_path.ends_with(".wasm") {
|
|
"application/wasm"
|
|
} else if file_path.ends_with(".css") {
|
|
"text/css"
|
|
} else if file_path.ends_with(".html") {
|
|
"text/html"
|
|
} else if file_path.ends_with(".png") {
|
|
"image/png"
|
|
} else if file_path.ends_with(".jpg") || file_path.ends_with(".jpeg") {
|
|
"image/jpeg"
|
|
} else if file_path.ends_with(".svg") {
|
|
"image/svg+xml"
|
|
} else {
|
|
"application/octet-stream"
|
|
}
|
|
}
|