A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: Add build progress toast and open output folder
esengine4d67f37c09d6
diff --git a/desktop/src-tauri/capabilities/default.json b/desktop/src-tauri/capabilities/default.jsonindex e932f3b3c..44d3c33f8 100644--- a/desktop/src-tauri/capabilities/default.json+++ b/desktop/src-tauri/capabilities/default.json@@ -10,21 +10,49 @@"dialog:allow-open","dialog:allow-save","fs:default",- "fs:allow-read-text-file",- "fs:allow-write-text-file",- "fs:allow-read-file",- "fs:allow-stat",- "fs:allow-exists",- "fs:allow-mkdir",- "fs:allow-read-dir",- {- "identifier": "fs:scope",- "allow": [- "$HOME/**",- "$DOCUMENT/**",- "$DESKTOP/**",- "**"- ]+ {+ "identifier": "fs:allow-read-text-file",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-write-text-file",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-write-file",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-read-file",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-stat",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-exists",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-mkdir",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-read-dir",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-copy-file",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-remove",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]+ },+ {+ "identifier": "fs:allow-rename",+ "allow": [{ "path": "$HOME/**/*" }, { "path": "$DOCUMENT/**/*" }, { "path": "/Users/**/*" }]}]}diff --git a/desktop/src-tauri/gen/schemas/capabilities.json b/desktop/src-tauri/gen/schemas/capabilities.jsonindex 6e8ef73dc..92ce009da 100644--- a/desktop/src-tauri/gen/schemas/capabilities.json+++ b/desktop/src-tauri/gen/schemas/capabilities.json@@ -1 +1 @@-{"default":{"identifier":"default","description":"Default capabilities for ESEngine Editor","local":true,"windows":["main"],"permissions":["core:default","shell:allow-open","dialog:default","dialog:allow-open","dialog:allow-save","fs:default","fs:allow-read-text-file","fs:allow-write-text-file","fs:allow-read-file","fs:allow-stat","fs:allow-exists","fs:allow-mkdir","fs:allow-read-dir",{"identifier":"fs:scope","allow":["$HOME/**","$DOCUMENT/**","$DESKTOP/**","**"]}]}}\ No newline at end of file+{"default":{"identifier":"default","description":"Default capabilities for ESEngine Editor","local":true,"windows":["main"],"permissions":["core:default","shell:allow-open","dialog:default","dialog:allow-open","dialog:allow-save","fs:default",{"identifier":"fs:allow-read-text-file","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-write-text-file","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-write-file","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-read-file","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-stat","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-exists","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-mkdir","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-read-dir","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-copy-file","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-remove","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]},{"identifier":"fs:allow-rename","allow":[{"path":"$HOME/**/*"},{"path":"$DOCUMENT/**/*"},{"path":"/Users/**/*"}]}]}}\ No newline at end of filediff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rsindex 0663582c2..efd645f5d 100644--- a/desktop/src-tauri/src/lib.rs+++ b/desktop/src-tauri/src/lib.rs@@ -54,6 +54,11 @@ fn open_preview_in_browser(port: u16) -> Result<(), String> {open::that(&url).map_err(|e| e.to_string())}+#[tauri::command]+fn open_folder(path: String) -> Result<(), String> {+ open::that(&path).map_err(|e| e.to_string())+}+// =============================================================================// Entry Point// =============================================================================@@ -71,6 +76,7 @@ pub fn run() {start_preview_server,stop_preview_server,open_preview_in_browser,+ open_folder,]).run(tauri::generate_context!()).expect("error while running tauri application");diff --git a/desktop/src-tauri/tauri.conf.json b/desktop/src-tauri/tauri.conf.jsonindex 043fc4bd6..a153664e3 100644--- a/desktop/src-tauri/tauri.conf.json+++ b/desktop/src-tauri/tauri.conf.json@@ -29,7 +29,11 @@}}},- "plugins": {},+ "plugins": {+ "fs": {+ "requireLiteralLeadingDot": false+ }+ },"bundle": {"active": true,"targets": "all",diff --git a/desktop/src/native-fs.ts b/desktop/src/native-fs.tsindex b88613cb6..1e85957b5 100644--- a/desktop/src/native-fs.ts+++ b/desktop/src/native-fs.ts@@ -13,6 +13,7 @@ import {readDir,stat,} from '@tauri-apps/plugin-fs';+import { invoke } from '@tauri-apps/api/core';export interface DirectoryEntry {name: string;@@ -51,6 +52,7 @@ export interface NativeFS {callback: (event: FileChangeEvent) => void,options?: { recursive?: boolean }): Promise<UnwatchFn>;+ openFolder(path: string): Promise<boolean>;}export function injectNativeFS(): void {@@ -208,6 +210,16 @@ export function injectNativeFS(): void {// File watching not yet supported - use manual refreshreturn () => {};},++ async openFolder(path: string) {+ try {+ await invoke('open_folder', { path });+ return true;+ } catch (err) {+ console.error('Failed to open folder:', err);+ return false;+ }+ },};(window as any).__esengine_fs = nativeFS;diff --git a/editor/src/Editor.ts b/editor/src/Editor.tsindex 4b70c1878..a260b5cad 100644--- a/editor/src/Editor.ts+++ b/editor/src/Editor.ts@@ -485,10 +485,7 @@ export class Editor {showBuildSettingsDialog({projectPath: this.projectPath_,onBuild: async (config) => {- const result = await buildService.build(config);- if (!result.success) {- throw new Error(result.error ?? 'Build failed');- }+ return await buildService.build(config);},onClose: () => {},});diff --git a/editor/src/builder/BuildSettingsDialog.ts b/editor/src/builder/BuildSettingsDialog.tsindex 40c19913d..8e1706246 100644--- a/editor/src/builder/BuildSettingsDialog.ts+++ b/editor/src/builder/BuildSettingsDialog.ts@@ -12,6 +12,8 @@ import {createDefaultBuildConfig,createDefaultBuildSettings,} from '../types/BuildTypes';+import { type BuildResult } from './BuildService';+import { showProgressToast, updateToast, dismissToast, showToast } from '../ui/Toast';// =============================================================================// Types@@ -19,7 +21,7 @@ import {export interface BuildSettingsDialogOptions {projectPath: string;- onBuild: (config: BuildConfig) => Promise<void>;+ onBuild: (config: BuildConfig) => Promise<BuildResult>;onClose: () => void;}@@ -622,21 +624,99 @@ export class BuildSettingsDialog {private async handleBuild(config: BuildConfig): Promise<void> {const buildBtn = this.overlay_.querySelector('[data-action="build"]') as HTMLButtonElement;+ const switchBtn = this.overlay_.querySelector('[data-action="switch-config"]') as HTMLButtonElement;++ // Disable buttonsif (buildBtn) {buildBtn.disabled = true;buildBtn.innerHTML = `${icons.refresh(14)} 构建中...`;}+ if (switchBtn) {+ switchBtn.disabled = true;+ }++ // Show progress toast+ const platformName = this.getPlatformName(config.platform);+ const toastId = showProgressToast(+ `正在构建 ${config.name}`,+ `目标平台: ${platformName}`+ );try {- await this.options_.onBuild(config);- alert('构建完成!');+ const result = await this.options_.onBuild(config);++ dismissToast(toastId);++ if (result.success && result.outputPath) {+ // Show success toast with action to open folder+ showToast({+ type: 'success',+ title: '构建完成',+ message: `输出: ${this.getFileName(result.outputPath)}`,+ duration: 0,+ actions: [+ {+ label: '打开文件夹',+ primary: true,+ onClick: () => this.openOutputFolder(result.outputPath!),+ },+ {+ label: '关闭',+ onClick: () => {},+ },+ ],+ });+ } else if (!result.success) {+ showToast({+ type: 'error',+ title: '构建失败',+ message: result.error || '未知错误',+ duration: 5000,+ });+ }} catch (err) {- alert(`构建失败: ${err}`);+ dismissToast(toastId);+ showToast({+ type: 'error',+ title: '构建失败',+ message: String(err),+ duration: 5000,+ });} finally {+ // Re-enable buttonsif (buildBtn) {buildBtn.disabled = false;buildBtn.innerHTML = `${icons.play(14)} 构建`;}+ if (switchBtn) {+ switchBtn.disabled = false;+ }+ }+ }++ private getFileName(path: string): string {+ const parts = path.replace(/\\/g, '/').split('/');+ return parts[parts.length - 1] || path;+ }++ private async openOutputFolder(outputPath: string): Promise<void> {+ try {+ // Get directory from output path+ const dirPath = outputPath.replace(/\\/g, '/').split('/').slice(0, -1).join('/');++ // Use Tauri shell plugin to open folder+ const shell = (window as any).__TAURI__?.shell;+ if (shell?.open) {+ await shell.open(dirPath);+ } else {+ // Fallback: try using the fs adapter+ const fs = (window as any).__esengine_fs;+ if (fs?.openFolder) {+ await fs.openFolder(dirPath);+ }+ }+ } catch (err) {+ console.error('Failed to open folder:', err);}}diff --git a/editor/src/styles/editor.css b/editor/src/styles/editor.cssindex bc4f39209..4b09b889e 100644--- a/editor/src/styles/editor.css+++ b/editor/src/styles/editor.css@@ -2920,3 +2920,166 @@ svg {.es-build-define-add .es-btn-icon:hover {background: var(--es-bg-hover);}++/* =============================================================================+ Toast Notifications+ ============================================================================= */++.es-toast-container {+ position: fixed;+ bottom: 20px;+ right: 20px;+ z-index: 10000;+ display: flex;+ flex-direction: column-reverse;+ gap: 10px;+ pointer-events: none;+}++.es-toast {+ display: flex;+ align-items: flex-start;+ gap: 12px;+ min-width: 320px;+ max-width: 420px;+ padding: 14px 16px;+ background: var(--es-bg-secondary);+ border: 1px solid var(--es-border);+ border-radius: 6px;+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);+ pointer-events: auto;+ transform: translateX(100%);+ opacity: 0;+ transition: transform 0.2s ease, opacity 0.2s ease;+}++.es-toast-show {+ transform: translateX(0);+ opacity: 1;+}++.es-toast-hide {+ transform: translateX(100%);+ opacity: 0;+}++.es-toast-icon {+ flex-shrink: 0;+ width: 24px;+ height: 24px;+ display: flex;+ align-items: center;+ justify-content: center;+ color: var(--es-text-secondary);+}++.es-toast-success .es-toast-icon {+ color: var(--es-success, #4caf50);+}++.es-toast-error .es-toast-icon {+ color: var(--es-danger, #f44336);+}++.es-toast-progress .es-toast-icon {+ color: var(--es-accent, #0078d4);+}++.es-toast-content {+ flex: 1;+ min-width: 0;+}++.es-toast-title {+ font-size: 13px;+ font-weight: 500;+ color: var(--es-text-primary);+ margin-bottom: 2px;+}++.es-toast-message {+ font-size: 12px;+ color: var(--es-text-secondary);+ margin-top: 4px;+ word-break: break-word;+}++.es-toast-close {+ flex-shrink: 0;+ width: 20px;+ height: 20px;+ display: flex;+ align-items: center;+ justify-content: center;+ background: none;+ border: none;+ color: var(--es-text-tertiary);+ cursor: pointer;+ border-radius: 3px;+ transition: background 0.15s, color 0.15s;+}++.es-toast-close:hover {+ background: var(--es-bg-hover);+ color: var(--es-text-primary);+}++.es-toast-progress-bar {+ margin-top: 10px;+ height: 4px;+ background: var(--es-bg-tertiary);+ border-radius: 2px;+ overflow: hidden;+}++.es-toast-progress-fill {+ height: 100%;+ background: var(--es-accent, #0078d4);+ border-radius: 2px;+ transition: width 0.3s ease;+}++.es-toast-spinner {+ width: 18px;+ height: 18px;+ border: 2px solid var(--es-bg-tertiary);+ border-top-color: var(--es-accent, #0078d4);+ border-radius: 50%;+ animation: es-toast-spin 0.8s linear infinite;+}++@keyframes es-toast-spin {+ to { transform: rotate(360deg); }+}++.es-toast-actions {+ display: flex;+ gap: 8px;+ margin-top: 12px;+}++.es-toast-btn {+ padding: 6px 12px;+ font-size: 12px;+ border: 1px solid var(--es-border);+ border-radius: 4px;+ background: var(--es-bg-tertiary);+ color: var(--es-text-primary);+ cursor: pointer;+ transition: background 0.15s, border-color 0.15s;+}++.es-toast-btn:hover {+ background: var(--es-bg-hover);+}++.es-toast-btn-primary {+ background: var(--es-accent, #0078d4);+ border-color: var(--es-accent, #0078d4);+ color: white;+}++.es-toast-btn-primary:hover {+ background: #3d9ee0;+ border-color: #3d9ee0;+}diff --git a/editor/src/ui/Toast.ts b/editor/src/ui/Toast.tsnew file mode 100644index 000000000..238dca9a0--- /dev/null+++ b/editor/src/ui/Toast.ts@@ -0,0 +1,209 @@+/**+ * @file Toast.ts+ * @brief Toast notification component for build progress and status+ */++import { icons } from '../utils/icons';++// =============================================================================+// Types+// =============================================================================++export type ToastType = 'info' | 'success' | 'error' | 'progress';++export interface ToastOptions {+ type: ToastType;+ title: string;+ message?: string;+ duration?: number; // ms, 0 = manual close+ progress?: number; // 0-100, only for progress type+ actions?: ToastAction[];+}++export interface ToastAction {+ label: string;+ primary?: boolean;+ onClick: () => void;+}++// =============================================================================+// Toast Manager (Singleton)+// =============================================================================++class ToastManager {+ private container_: HTMLElement | null = null;+ private toasts_: Map<string, HTMLElement> = new Map();+ private counter_ = 0;++ private getContainer(): HTMLElement {+ if (!this.container_) {+ this.container_ = document.createElement('div');+ this.container_.className = 'es-toast-container';+ document.body.appendChild(this.container_);+ }+ return this.container_;+ }++ show(options: ToastOptions): string {+ const id = `toast-${++this.counter_}`;+ const container = this.getContainer();++ const toast = document.createElement('div');+ toast.className = `es-toast es-toast-${options.type}`;+ toast.dataset.toastId = id;++ const iconHtml = this.getIcon(options.type);+ const progressHtml = options.type === 'progress'+ ? `<div class="es-toast-progress-bar"><div class="es-toast-progress-fill" style="width: ${options.progress ?? 0}%"></div></div>`+ : '';++ const actionsHtml = options.actions?.length+ ? `<div class="es-toast-actions">${options.actions.map((a, i) =>+ `<button class="es-toast-btn ${a.primary ? 'es-toast-btn-primary' : ''}" data-action-index="${i}">${a.label}</button>`+ ).join('')}</div>`+ : '';++ toast.innerHTML = `+ <div class="es-toast-icon">${iconHtml}</div>+ <div class="es-toast-content">+ <div class="es-toast-title">${options.title}</div>+ ${options.message ? `<div class="es-toast-message">${options.message}</div>` : ''}+ ${progressHtml}+ ${actionsHtml}+ </div>+ <button class="es-toast-close">${icons.x(12)}</button>+ `;++ // Event listeners+ toast.querySelector('.es-toast-close')?.addEventListener('click', () => {+ this.dismiss(id);+ });++ if (options.actions) {+ options.actions.forEach((action, index) => {+ toast.querySelector(`[data-action-index="${index}"]`)?.addEventListener('click', () => {+ action.onClick();+ this.dismiss(id);+ });+ });+ }++ container.appendChild(toast);+ this.toasts_.set(id, toast);++ // Animate in+ requestAnimationFrame(() => {+ toast.classList.add('es-toast-show');+ });++ // Auto dismiss+ if (options.duration && options.duration > 0) {+ setTimeout(() => this.dismiss(id), options.duration);+ }++ return id;+ }++ update(id: string, updates: Partial<ToastOptions>): void {+ const toast = this.toasts_.get(id);+ if (!toast) return;++ if (updates.title !== undefined) {+ const titleEl = toast.querySelector('.es-toast-title');+ if (titleEl) titleEl.textContent = updates.title;+ }++ if (updates.message !== undefined) {+ let messageEl = toast.querySelector('.es-toast-message');+ if (updates.message) {+ if (!messageEl) {+ messageEl = document.createElement('div');+ messageEl.className = 'es-toast-message';+ toast.querySelector('.es-toast-content')?.appendChild(messageEl);+ }+ messageEl.textContent = updates.message;+ } else if (messageEl) {+ messageEl.remove();+ }+ }++ if (updates.progress !== undefined) {+ const fillEl = toast.querySelector('.es-toast-progress-fill') as HTMLElement;+ if (fillEl) {+ fillEl.style.width = `${updates.progress}%`;+ }+ }++ if (updates.type !== undefined) {+ toast.className = `es-toast es-toast-${updates.type} es-toast-show`;+ const iconEl = toast.querySelector('.es-toast-icon');+ if (iconEl) iconEl.innerHTML = this.getIcon(updates.type);+ }+ }++ dismiss(id: string): void {+ const toast = this.toasts_.get(id);+ if (!toast) return;++ toast.classList.remove('es-toast-show');+ toast.classList.add('es-toast-hide');++ setTimeout(() => {+ toast.remove();+ this.toasts_.delete(id);+ }, 200);+ }++ dismissAll(): void {+ for (const id of this.toasts_.keys()) {+ this.dismiss(id);+ }+ }++ private getIcon(type: ToastType): string {+ switch (type) {+ case 'success':+ return icons.check(18);+ case 'error':+ return icons.x(18);+ case 'progress':+ return `<div class="es-toast-spinner"></div>`;+ default:+ return icons.cog(18);+ }+ }+}++// =============================================================================+// Singleton Export+// =============================================================================++export const toast = new ToastManager();++// =============================================================================+// Convenience Functions+// =============================================================================++export function showToast(options: ToastOptions): string {+ return toast.show(options);+}++export function showSuccessToast(title: string, message?: string, duration = 3000): string {+ return toast.show({ type: 'success', title, message, duration });+}++export function showErrorToast(title: string, message?: string, duration = 5000): string {+ return toast.show({ type: 'error', title, message, duration });+}++export function showProgressToast(title: string, message?: string): string {+ return toast.show({ type: 'progress', title, message, progress: 0, duration: 0 });+}++export function updateToast(id: string, updates: Partial<ToastOptions>): void {+ toast.update(id, updates);+}++export function dismissToast(id: string): void {+ toast.dismiss(id);+}diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex b3bcddb2d..4ace2e5ab 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -2,3 +2,5 @@ packages:- 'sdk'- 'editor'- 'desktop'+onlyBuiltDependencies:+ - esbuild