Tauri 编辑器应用框架

This commit is contained in:
YHH
2025-10-14 22:53:26 +08:00
parent b20b2ae4ce
commit bd839cf431
18 changed files with 1702 additions and 5 deletions

View File

@@ -0,0 +1,29 @@
[package]
name = "ecs-editor"
version = "1.0.0"
description = "ECS Framework Editor - Cross-platform desktop editor"
authors = ["yhh"]
edition = "2021"
[lib]
name = "ecs_editor_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
[profile.dev]
incremental = true
[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = true

View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@@ -0,0 +1,25 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ProjectInfo {
pub name: String,
pub path: String,
pub version: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EditorConfig {
pub theme: String,
pub auto_save: bool,
pub recent_projects: Vec<String>,
}
impl Default for EditorConfig {
fn default() -> Self {
Self {
theme: "dark".to_string(),
auto_save: true,
recent_projects: Vec::new(),
}
}
}

View File

@@ -0,0 +1,7 @@
// ECS Editor Library
pub mod commands;
pub mod project;
pub use commands::*;
pub use project::*;

View File

@@ -0,0 +1,54 @@
// Prevents additional console window on Windows in release
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::Manager;
// IPC Commands
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! Welcome to ECS Framework Editor.", name)
}
#[tauri::command]
fn open_project(path: String) -> Result<String, String> {
// 项目打开逻辑
Ok(format!("Project opened: {}", path))
}
#[tauri::command]
fn save_project(path: String, data: String) -> Result<(), String> {
// 项目保存逻辑
std::fs::write(&path, data)
.map_err(|e| format!("Failed to save project: {}", e))?;
Ok(())
}
#[tauri::command]
fn export_binary(data: Vec<u8>, output_path: String) -> Result<(), String> {
// 二进制导出逻辑
std::fs::write(&output_path, data)
.map_err(|e| format!("Failed to export binary: {}", e))?;
Ok(())
}
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.setup(|app| {
// 应用启动时的初始化逻辑
#[cfg(debug_assertions)]
{
let window = app.get_webview_window("main").unwrap();
window.open_devtools();
}
Ok(())
})
.invoke_handler(tauri::generate_handler![
greet,
open_project,
save_project,
export_binary
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,42 @@
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Project {
pub name: String,
pub path: PathBuf,
pub scenes: Vec<String>,
pub assets: Vec<String>,
}
impl Project {
pub fn new(name: String, path: PathBuf) -> Self {
Self {
name,
path,
scenes: Vec::new(),
assets: Vec::new(),
}
}
pub fn load(path: &PathBuf) -> Result<Self, String> {
let content = std::fs::read_to_string(path)
.map_err(|e| format!("Failed to read project file: {}", e))?;
serde_json::from_str(&content)
.map_err(|e| format!("Failed to parse project file: {}", e))
}
pub fn save(&self) -> Result<(), String> {
let mut project_file = self.path.clone();
project_file.push("project.json");
let content = serde_json::to_string_pretty(self)
.map_err(|e| format!("Failed to serialize project: {}", e))?;
std::fs::write(&project_file, content)
.map_err(|e| format!("Failed to write project file: {}", e))?;
Ok(())
}
}

View File

@@ -0,0 +1,59 @@
{
"productName": "ECS Framework Editor",
"version": "1.0.0",
"identifier": "com.esengine.editor",
"build": {
"beforeDevCommand": "npm run dev",
"devUrl": "http://localhost:5173",
"beforeBuildCommand": "npm run build",
"frontendDist": "../dist"
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
},
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
}
},
"app": {
"windows": [
{
"title": "ECS Framework Editor",
"width": 1280,
"height": 800,
"minWidth": 800,
"minHeight": 600,
"resizable": true,
"fullscreen": false,
"decorations": true,
"transparent": false,
"center": true,
"skipTaskbar": false
}
],
"security": {
"csp": null
}
},
"plugins": {
"shell": {
"open": true
}
}
}