Files
esengine/packages/editor-app/src/api/tauri.ts

176 lines
4.4 KiB
TypeScript
Raw Normal View History

2025-10-14 22:53:26 +08:00
import { invoke } from '@tauri-apps/api/core';
/**
* Tauri IPC
*/
export class TauriAPI {
/**
*
*/
static async greet(name: string): Promise<string> {
return await invoke<string>('greet', { name });
}
2025-10-15 00:23:19 +08:00
static async openProjectDialog(): Promise<string | null> {
return await invoke<string | null>('open_project_dialog');
}
2025-10-14 22:53:26 +08:00
static async openProject(path: string): Promise<string> {
return await invoke<string>('open_project', { path });
}
/**
*
*/
static async saveProject(path: string, data: string): Promise<void> {
return await invoke<void>('save_project', { path, data });
}
/**
*
*/
static async exportBinary(data: Uint8Array, outputPath: string): Promise<void> {
return await invoke<void>('export_binary', {
data: Array.from(data),
outputPath
});
}
2025-10-15 00:40:27 +08:00
/**
*
*/
static async scanDirectory(path: string, pattern: string): Promise<string[]> {
return await invoke<string[]>('scan_directory', { path, pattern });
}
/**
*
*/
static async readFileContent(path: string): Promise<string> {
return await invoke<string>('read_file_content', { path });
}
2025-10-15 09:43:48 +08:00
/**
*
*/
static async listDirectory(path: string): Promise<DirectoryEntry[]> {
return await invoke<DirectoryEntry[]>('list_directory', { path });
}
2025-10-15 17:15:05 +08:00
/**
* Custom Protocol
*/
static async setProjectBasePath(path: string): Promise<void> {
return await invoke<void>('set_project_base_path', { path });
}
2025-10-15 20:23:55 +08:00
/**
* debug模式下可用
*/
static async toggleDevtools(): Promise<void> {
return await invoke<void>('toggle_devtools');
}
2025-10-17 18:13:31 +08:00
/**
*
* @param defaultName
* @returns null
*/
static async saveSceneDialog(defaultName?: string): Promise<string | null> {
return await invoke<string | null>('save_scene_dialog', { defaultName });
}
/**
*
* @returns null
*/
static async openSceneDialog(): Promise<string | null> {
return await invoke<string | null>('open_scene_dialog');
}
/**
*
* @param path
*/
static async createDirectory(path: string): Promise<void> {
return await invoke<void>('create_directory', { path });
}
/**
*
* @param path
* @param content
*/
static async writeFileContent(path: string, content: string): Promise<void> {
return await invoke<void>('write_file_content', { path, content });
}
/**
*
* @param path
* @returns
*/
static async pathExists(path: string): Promise<boolean> {
return await invoke<boolean>('path_exists', { path });
}
/**
* 使
* @param path
*/
static async openFileWithSystemApp(path: string): Promise<void> {
await invoke('open_file_with_default_app', { filePath: path });
}
/**
*
* @param path
*/
static async showInFolder(path: string): Promise<void> {
await invoke('show_in_folder', { filePath: path });
}
/**
*
* @returns null
*/
static async openBehaviorTreeDialog(): Promise<string | null> {
return await invoke<string | null>('open_behavior_tree_dialog');
}
/**
*
* @param projectPath
* @returns ID列表 .ecs/behaviors
*/
static async scanBehaviorTrees(projectPath: string): Promise<string[]> {
return await invoke<string[]>('scan_behavior_trees', { projectPath });
}
2025-10-15 09:43:48 +08:00
}
export interface DirectoryEntry {
name: string;
path: string;
is_dir: boolean;
size?: number;
modified?: number;
2025-10-14 22:53:26 +08:00
}
/**
*
*/
export interface ProjectInfo {
name: string;
path: string;
version: string;
}
/**
*
*/
export interface EditorConfig {
theme: string;
autoSave: boolean;
recentProjects: string[];
}