Skip to content

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.

feat: add extensions panel with multi-window support and detachOnly handling

esenginedce550c65c85
diff --git a/editor/src/DockLayoutManager.ts b/editor/src/DockLayoutManager.ts
index af3c6562e..f8054ad3d 100644
--- a/editor/src/DockLayoutManager.ts
+++ b/editor/src/DockLayoutManager.ts
@@ -163,12 +163,19 @@ export class DockLayoutManager {
initialWidth: 260,
});
+ this.api_.addPanel({
+ id: 'content-browser',
+ component: 'content-browser',
+ title: 'Content Browser',
+ position: { referencePanel: 'scene', direction: 'below' },
+ initialHeight: 200,
+ });
+
this.api_.addPanel({
id: 'output',
component: 'output',
title: 'Output',
- position: { referencePanel: 'scene', direction: 'below' },
- initialHeight: 200,
+ position: { referencePanel: 'content-browser', direction: 'within' },
inactive: true,
});
}
@@ -219,6 +226,11 @@ export class DockLayoutManager {
const desc = getPanel(id);
if (!desc) return;
+ if (desc.detachOnly) {
+ this.handleDetachPanel(id, false);
+ return;
+ }
+
if (desc.position === 'center') {
this.api_.addPanel({
id: desc.id,
@@ -337,8 +349,9 @@ export class DockLayoutManager {
private listenPanelClosed(): void {
if (!this.detachContext_) return;
- this.panelClosedUnlisten_ = this.detachContext_.onPanelClosed((panelId) => {
- this.showPanel(panelId);
+ this.panelClosedUnlisten_ = this.detachContext_.onPanelClosed((_panelId) => {
+ // Detached panel was closed externally — do NOT re-show in main editor.
+ // User can re-open via View menu if needed.
});
}
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index ba9940fa5..07c2de6bc 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -247,6 +247,7 @@ export class Editor {
}
private async initializeAllScripts_(): Promise<void> {
+ await this.extensionService_.startListening();
await this.extensionService_.initialize();
await this.scriptService_.initialize();
}
diff --git a/editor/src/extension/ExtensionContext.ts b/editor/src/extension/ExtensionContext.ts
index 10b554a87..eaae7368b 100644
--- a/editor/src/extension/ExtensionContext.ts
+++ b/editor/src/extension/ExtensionContext.ts
@@ -2,11 +2,20 @@ import {
PostProcess, Material,
unregisterDrawCallback,
} from 'esengine';
+import type { EditorContainer } from '../container/EditorContainer';
+import { EditorExtensionAPI } from './EditorExtensionAPI';
export class ExtensionContext {
- createAPI(base: Record<string, unknown>): Record<string, unknown> {
+ private editorAPI_: EditorExtensionAPI | null = null;
+
+ createAPI(base: Record<string, unknown>, container?: EditorContainer): Record<string, unknown> {
+ if (container) {
+ this.editorAPI_ = new EditorExtensionAPI(container);
+ }
+
return {
...base,
+ editor: this.editorAPI_,
registerDrawCallback: (id: string, fn: Function) => {
if (this.disposed_) return;
(base.registerDrawCallback as Function)(id, fn);
@@ -49,6 +58,9 @@ export class ExtensionContext {
if (this.disposed_) return;
this.disposed_ = true;
+ this.editorAPI_?.dispose();
+ this.editorAPI_ = null;
+
for (let i = this.disposables_.length - 1; i >= 0; i--) {
try { this.disposables_[i](); } catch {}
}
diff --git a/editor/src/extension/ExtensionLoader.ts b/editor/src/extension/ExtensionLoader.ts
index 976bf6e51..a723a04c5 100644
--- a/editor/src/extension/ExtensionLoader.ts
+++ b/editor/src/extension/ExtensionLoader.ts
@@ -11,7 +11,10 @@ import { getEditorContext } from '../context/EditorContext';
import { initializeEsbuild } from '../builder/ArtifactBuilder';
import { ExtensionContext } from './ExtensionContext';
import { setEditorAPI } from './editorAPI';
+import { getEditorContainer } from '../container';
import { normalizePath, joinPath, getProjectDir } from '../utils/path';
+import { discoverPluginPackages } from './pluginDiscovery';
+import { getSettingsValue } from '../settings/SettingsRegistry';
// =============================================================================
// Native FS Access
@@ -21,6 +24,22 @@ function getNativeFS(): NativeFS | null {
return getEditorContext().fs ?? null;
}
+// =============================================================================
+// Plugin Info
+// =============================================================================
+
+export interface ExtensionPluginInfo {
+ id: string;
+ type: 'local' | 'npm';
+ name: string;
+ version?: string;
+ description?: string;
+ status: 'loaded' | 'error' | 'disabled';
+ error?: string;
+}
+
+const PLUGIN_ERRORS_KEY = '__esengine_plugin_errors__';
+
// =============================================================================
// Extension Loader
// =============================================================================
@@ -55,6 +74,10 @@ export class ExtensionLoader {
this.initialized_ = true;
}
+ getDiscoveredPlugins(): ExtensionPluginInfo[] {
+ return this.discoveredPlugins_;
+ }
+
async discover(): Promise<string[]> {
const fs = getNativeFS();
if (!fs) return [];
@@ -73,16 +96,56 @@ export class ExtensionLoader {
const fs = getNativeFS();
if (!fs) return false;
+ const disabled = getSettingsValue<string[]>('extensions.disabled') ?? [];
+ const disabledSet = new Set(disabled);
+
const scripts = await this.discover();
- if (scripts.length === 0) {
+ const infos: ExtensionPluginInfo[] = [];
+
+ const pluginImports: string[] = [];
+ try {
+ const plugins = await discoverPluginPackages(fs, this.projectDir_, 'editor');
+ for (const p of plugins) {
+ const info: ExtensionPluginInfo = {
+ id: p.packageName,
+ type: 'npm',
+ name: p.displayName ?? p.packageName,
+ version: p.version,
+ description: p.description,
+ status: disabledSet.has(p.packageName) ? 'disabled' : 'loaded',
+ };
+ infos.push(info);
+ if (info.status !== 'disabled') {
+ pluginImports.push(
+ `try { await import("${p.entryPath}"); } catch(e) { (window.${PLUGIN_ERRORS_KEY} ??= new Map()).set("${p.packageName}", String(e)); console.error("[plugin] ${p.packageName} failed:", e); }`
+ );
+ }
+ }
+ } catch (err) {
+ console.warn('ExtensionLoader: Plugin discovery failed:', err);
+ }
+
+ for (const path of scripts) {
+ const name = path.split('/').pop() ?? path;
+ infos.push({
+ id: path,
+ type: 'local',
+ name,
+ status: disabledSet.has(path) ? 'disabled' : 'loaded',
+ });
+ }
+
+ this.discoveredPlugins_ = infos;
+
+ const activeScripts = scripts.filter(p => !disabledSet.has(p));
+ if (activeScripts.length === 0 && pluginImports.length === 0) {
this.lastCompiled_ = null;
return true;
}
try {
- const entryContent = scripts
- .map(p => `import "${p}";`)
- .join('\n');
+ const localImports = activeScripts.map(p => `import "${p}";`).join('\n');
+ const entryContent = pluginImports.join('\n') + '\n' + localImports;
const result = await esbuild.build({
stdin: {
@@ -180,8 +243,9 @@ export class ExtensionLoader {
if (!compiled) return false;
if (!this.lastCompiled_) return true;
this.currentContext_ = new ExtensionContext();
- setEditorAPI(this.currentContext_.createAPI(this.baseAPI_));
+ setEditorAPI(this.currentContext_.createAPI(this.baseAPI_, getEditorContainer()));
const executed = await this.execute();
+ this.collectPluginErrors_();
if (executed) {
this.onAfterReload_?.();
}
@@ -240,6 +304,19 @@ export class ExtensionLoader {
// Private Methods
// =========================================================================
+ private collectPluginErrors_(): void {
+ const errors = (window as any)[PLUGIN_ERRORS_KEY] as Map<string, string> | undefined;
+ if (!errors) return;
+ for (const info of this.discoveredPlugins_) {
+ const err = errors.get(info.id);
+ if (err) {
+ info.status = 'error';
+ info.error = err;
+ }
+ }
+ delete (window as any)[PLUGIN_ERRORS_KEY];
+ }
+
private disposeCurrentUrl(): void {
if (this.currentBlobUrl_) {
URL.revokeObjectURL(this.currentBlobUrl_);
@@ -262,6 +339,7 @@ export class ExtensionLoader {
private currentContext_: ExtensionContext | null = null;
private unwatchFn_: (() => void) | null = null;
private recompileTimer_: number | null = null;
+ private discoveredPlugins_: ExtensionPluginInfo[] = [];
private onCompileError_?: (errors: CompileError[]) => void;
private onCompileSuccess_?: () => void;
private onCleanup_?: () => void;
diff --git a/editor/src/extension/index.ts b/editor/src/extension/index.ts
index b8b63cddb..59f927092 100644
--- a/editor/src/extension/index.ts
+++ b/editor/src/extension/index.ts
@@ -1,3 +1,4 @@
-export { ExtensionLoader, type ExtensionLoaderOptions } from './ExtensionLoader';
+export { ExtensionLoader, type ExtensionLoaderOptions, type ExtensionPluginInfo } from './ExtensionLoader';
export { ExtensionContext } from './ExtensionContext';
export { EditorExportService } from './EditorExportService';
+export { EditorExtensionAPI, type Disposable } from './EditorExtensionAPI';
diff --git a/editor/src/launcher/ProjectService.ts b/editor/src/launcher/ProjectService.ts
index d38638fdf..7694334b0 100644
--- a/editor/src/launcher/ProjectService.ts
+++ b/editor/src/launcher/ProjectService.ts
@@ -12,7 +12,7 @@ import type {
import { ENGINE_VERSION } from '../types/ProjectTypes';
import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT, DEFAULT_PIXELS_PER_UNIT } from 'esengine';
import { SdkExportService } from '../sdk';
-import { EditorExportService } from '../extension';
+import { EditorExportService } from '../extension/EditorExportService';
import { getEditorContext } from '../context/EditorContext';
import type { NativeFS } from '../types/NativeFS';
diff --git a/editor/src/multiwindow/protocol.ts b/editor/src/multiwindow/protocol.ts
index b30d91a7d..4278e508d 100644
--- a/editor/src/multiwindow/protocol.ts
+++ b/editor/src/multiwindow/protocol.ts
@@ -15,6 +15,10 @@ export const CHANNEL_PROFILER_STATS = 'editor:profiler-stats';
export const CHANNEL_FRAME_DEBUGGER_DATA = 'editor:frame-debugger-data';
export const CHANNEL_FRAME_DEBUGGER_REPLAY_REQ = 'editor:frame-debugger-replay-req';
export const CHANNEL_FRAME_DEBUGGER_SNAPSHOT = 'editor:frame-debugger-snapshot';
+export const CHANNEL_EXTENSIONS_DATA = 'editor:extensions-data';
+export const CHANNEL_EXTENSIONS_TOGGLE = 'editor:extensions-toggle';
+export const CHANNEL_EXTENSIONS_RELOAD = 'editor:extensions-reload';
+export const CHANNEL_EXTENSIONS_REQUEST = 'editor:extensions-request';
// =============================================================================
// State Snapshot
@@ -122,3 +126,28 @@ export interface FrameDebuggerSnapshotMessage {
width: number;
height: number;
}
+
+// =============================================================================
+// Extensions Messages
+// =============================================================================
+
+export interface ExtensionDataMessage {
+ plugins: ExtensionPluginData[];
+ reloading: boolean;
+}
+
+export interface ExtensionPluginData {
+ id: string;
+ type: 'local' | 'npm';
+ name: string;
+ version?: string;
+ description?: string;
+ status: 'loaded' | 'error' | 'disabled';
+ error?: string;
+}
+
+export interface ExtensionToggleMessage {
+ pluginId: string;
+}
+
+export interface ExtensionReloadMessage {}
diff --git a/editor/src/panels/ExtensionsPanel.ts b/editor/src/panels/ExtensionsPanel.ts
new file mode 100644
index 000000000..98a9a1430
--- /dev/null
+++ b/editor/src/panels/ExtensionsPanel.ts
@@ -0,0 +1,322 @@
+import type { PanelInstance } from './PanelRegistry';
+import type { ExtensionPluginInfo } from '../extension/ExtensionLoader';
+import { DisposableStore } from '../utils/Disposable';
+import { getExtensionService } from '../services';
+import { getSettingsValue, setSettingsValue } from '../settings';
+import { getEditorContext } from '../context/EditorContext';
+import { icons } from '../utils/icons';
+import {
+ CHANNEL_EXTENSIONS_DATA,
+ CHANNEL_EXTENSIONS_TOGGLE,
+ CHANNEL_EXTENSIONS_RELOAD,
+ CHANNEL_EXTENSIONS_REQUEST,
+ type ExtensionDataMessage,
+ type ExtensionPluginData,
+} from '../multiwindow/protocol';
+
+const ICON_SM = 12;
+
+type PluginItem = ExtensionPluginInfo | ExtensionPluginData;
+
+function isExternalWindow(): boolean {
+ try {
+ return typeof window !== 'undefined'
+ && '__TAURI_INTERNALS__' in window
+ && window.location.href.includes('panel-window');
+ } catch {
+ return false;
+ }
+}
+
+export class ExtensionsPanel implements PanelInstance {
+ private container_: HTMLElement;
+ private disposables_ = new DisposableStore();
+ private listEl_: HTMLElement | null = null;
+ private detailEl_: HTMLElement | null = null;
+ private selected_: PluginItem | null = null;
+ private plugins_: PluginItem[] = [];
+ private reloading_ = false;
+ private external_ = isExternalWindow();
+ private dataUnlisten_: (() => void) | null = null;
+
+ constructor(container: HTMLElement) {
+ this.container_ = container;
+ this.render_();
+ if (this.external_) {
+ this.startListening_();
+ } else {
+ this.refreshFromService_();
+ }
+ }
+
+ dispose(): void {
+ this.dataUnlisten_?.();
+ this.dataUnlisten_ = null;
+ this.disposables_.dispose();
+ this.container_.innerHTML = '';
+ }
+
+ private render_(): void {
+ this.container_.innerHTML = `
+ <div class="es-extensions-panel">
+ <div class="es-ext-toolbar">
+ <span class="es-ext-toolbar-title">${icons.package(ICON_SM)} Extensions</span>
+ <button class="es-ext-toolbar-btn" data-action="reload" title="Reload All">${icons.refresh(ICON_SM)}</button>
+ </div>
+ <div class="es-ext-body">
+ <div class="es-ext-list"></div>
+ <div class="es-ext-detail"></div>
+ </div>
+ </div>
+ `;
+
+ this.listEl_ = this.container_.querySelector('.es-ext-list');
+ this.detailEl_ = this.container_.querySelector('.es-ext-detail');
+
+ const reloadBtn = this.container_.querySelector('[data-action="reload"]');
+ if (reloadBtn) {
+ this.disposables_.addListener(reloadBtn, 'click', () => this.handleReload_());
+ }
+ }
+
+ private async startListening_(): Promise<void> {
+ const { listen, emit } = await import('@tauri-apps/api/event');
+ this.dataUnlisten_ = await listen<ExtensionDataMessage>(
+ CHANNEL_EXTENSIONS_DATA,
+ (event) => {
+ this.plugins_ = event.payload.plugins;
+ this.reloading_ = event.payload.reloading;
+ this.renderList_();
+ if (this.selected_) {
+ const updated = this.plugins_.find(p => p.id === this.selected_!.id);
+ this.selected_ = updated ?? null;
+ }
+ this.renderDetail_();
+ },
+ );
+ emit(CHANNEL_EXTENSIONS_REQUEST, {});
+ }
+
+ private refreshFromService_(): void {
+ try {
+ const svc = getExtensionService();
+ this.plugins_ = svc.getDiscoveredPlugins();
+ this.reloading_ = svc.isReloading;
+ } catch {
+ this.plugins_ = [];
+ this.reloading_ = false;
+ }
+ this.renderList_();
+ this.renderDetail_();
+ }
+
+ private renderList_(): void {
+ if (!this.listEl_) return;
+ this.listEl_.innerHTML = '';
+
+ if (this.reloading_) {
+ this.listEl_.innerHTML = `
+ <div class="es-ext-loading">
+ <div class="es-ext-spinner"></div>
+ <span>Reloading extensions...</span>
+ </div>`;
+ return;
+ }
+
+ if (this.plugins_.length === 0) {
+ this.listEl_.innerHTML = `
+ <div class="es-ext-empty">
+ <div class="es-ext-empty-icon">${icons.package(28)}</div>
+ <div class="es-ext-empty-title">No Extensions</div>
+ <div class="es-ext-empty-desc">
+ Add <code>.ts</code> files to <code>editor/src/</code>,
+ or install npm plugins with <code>esengine.type: "plugin"</code>.
+ </div>
+ </div>`;
+ return;
+ }
+
+ const npms = this.plugins_.filter(p => p.type === 'npm');
+ const locals = this.plugins_.filter(p => p.type === 'local');
+
+ if (npms.length > 0) this.listEl_.appendChild(this.createGroup_('Plugins', npms));
+ if (locals.length > 0) this.listEl_.appendChild(this.createGroup_('Local', locals));
+ }
+
+ private createGroup_(title: string, items: PluginItem[]): HTMLElement {
+ const group = document.createElement('div');
+ group.className = 'es-ext-group';
+
+ const header = document.createElement('div');
+ header.className = 'es-ext-group-header';
+ header.innerHTML = `<span>${title}</span><span class="es-ext-group-badge">${items.length}</span>`;
+ group.appendChild(header);
+
+ for (const item of items) {
+ group.appendChild(this.createRow_(item));
+ }
+
+ return group;
+ }
+
+ private createRow_(item: PluginItem): HTMLElement {
+ const row = document.createElement('div');
+ const isActive = item.status === 'loaded';
+ const isError = item.status === 'error';
+ const isDisabled = item.status === 'disabled';
+ const isSelected = this.selected_?.id === item.id;
+
+ row.className = 'es-ext-row';
+ if (isSelected) row.classList.add('es-selected');
+ if (isDisabled) row.classList.add('es-ext-row--off');
+
+ const statusClass = isActive ? 'es-ext-dot--on' : isError ? 'es-ext-dot--err' : 'es-ext-dot--off';
+
+ row.innerHTML = `
+ <span class="es-ext-dot ${statusClass}" title="${isActive ? 'Active' : isError ? 'Error' : 'Disabled'}"></span>
+ <span class="es-ext-row-name">${escapeHtml(item.name)}</span>
+ ${item.version ? `<span class="es-ext-row-ver">v${escapeHtml(item.version)}</span>` : ''}
+ <span class="es-ext-row-spacer"></span>
+ <button class="es-ext-row-action" data-role="toggle" title="${isDisabled ? 'Enable' : 'Disable'}">
+ ${isDisabled ? icons.play(10) : icons.pause(10)}
+ </button>
+ `;
+
+ const toggleBtn = row.querySelector('[data-role="toggle"]');
+ if (toggleBtn) {
+ this.disposables_.addListener(toggleBtn, 'click', (e) => {
+ e.stopPropagation();
+ this.handleToggle_(item);
+ });
+ }
+
+ this.disposables_.addListener(row, 'click', (e) => {
+ if ((e.target as HTMLElement).closest('[data-role="toggle"]')) return;
+ this.listEl_?.querySelectorAll('.es-ext-row').forEach(el => el.classList.remove('es-selected'));
+ row.classList.add('es-selected');
+ this.selected_ = item;
+ this.renderDetail_();
+ });
+
+ return row;
+ }
+
+ private renderDetail_(): void {
+ if (!this.detailEl_) return;
+
+ if (!this.selected_) {
+ this.detailEl_.innerHTML = `
+ <div class="es-ext-detail-empty">
+ <span>Select an extension to view details</span>
+ </div>`;
+ return;
+ }
+
+ const item = this.selected_;
+ const isDisabled = item.status === 'disabled';
+ const isError = item.status === 'error';
+
+ const statusDot = item.status === 'loaded' ? 'es-ext-dot--on'
+ : isError ? 'es-ext-dot--err' : 'es-ext-dot--off';
+ const statusLabel = item.status === 'loaded' ? 'Active'
+ : isError ? 'Error' : 'Disabled';
+
+ let html = '<div class="es-ext-detail-content">';
+
+ html += `<div class="es-ext-detail-header">`;
+ html += `<span class="es-ext-detail-name">${escapeHtml(item.name)}</span>`;
+ if (item.version) html += `<span class="es-ext-detail-ver">v${escapeHtml(item.version)}</span>`;
+ html += `</div>`;
+
+ if (item.description) {
+ html += `<div class="es-ext-detail-desc">${escapeHtml(item.description)}</div>`;
+ }
+
+ html += `<div class="es-ext-detail-fields">`;
+ html += `<div class="es-ext-detail-field"><span class="es-ext-field-key">Status</span><span class="es-ext-field-val"><span class="es-ext-dot ${statusDot}"></span> ${statusLabel}</span></div>`;
+ html += `<div class="es-ext-detail-field"><span class="es-ext-field-key">Type</span><span class="es-ext-field-val">${item.type === 'npm' ? 'npm package' : 'Local file'}</span></div>`;
+ html += `<div class="es-ext-detail-field"><span class="es-ext-field-key">ID</span><span class="es-ext-field-val es-ext-mono">${escapeHtml(item.id)}</span></div>`;
+ html += `</div>`;
+
+ if (item.error) {
+ html += `<div class="es-ext-detail-err-box">`;
+ html += `<div class="es-ext-detail-err-title">${icons.alertTriangle(ICON_SM)} Error</div>`;
+ html += `<pre class="es-ext-detail-err-msg">${escapeHtml(item.error)}</pre>`;
+ html += `</div>`;
+ }
+
+ html += `<div class="es-ext-detail-actions">`;
+ html += `<button class="es-btn es-btn-sm" data-action="toggle">${isDisabled ? 'Enable' : 'Disable'}</button>`;
+ if (item.type === 'npm') {
+ html += `<button class="es-btn es-btn-sm" data-action="open-folder">${icons.folderOpen(ICON_SM)} Open Folder</button>`;
+ }
+ html += `</div>`;
+
+ html += '</div>';
+ this.detailEl_.innerHTML = html;
+
+ const toggleBtn = this.detailEl_.querySelector('[data-action="toggle"]');
+ if (toggleBtn) {
+ this.disposables_.addListener(toggleBtn, 'click', () => this.handleToggle_(item));
+ }
+
+ const openBtn = this.detailEl_.querySelector('[data-action="open-folder"]');
+ if (openBtn) {
+ this.disposables_.addListener(openBtn, 'click', () => this.handleOpenFolder_(item));
+ }
+ }
+
+ private handleToggle_(item: PluginItem): void {
+ if (this.external_) {
+ import('@tauri-apps/api/event').then(({ emit }) => {
+ emit(CHANNEL_EXTENSIONS_TOGGLE, { pluginId: item.id });
+ });
+ return;
+ }
+
+ const disabled = getSettingsValue<string[]>('extensions.disabled') ?? [];
+ const set = new Set(disabled);
+ const willDisable = !set.has(item.id);
+ if (willDisable) {
+ set.add(item.id);
+ } else {
+ set.delete(item.id);
+ }
+ setSettingsValue('extensions.disabled', Array.from(set));
+ this.handleReload_();
+ }
+
+ private async handleReload_(): Promise<void> {
+ if (this.external_) {
+ const { emit } = await import('@tauri-apps/api/event');
+ emit(CHANNEL_EXTENSIONS_RELOAD, {});
+ return;
+ }
+
+ this.reloading_ = true;
+ this.renderList_();
+ try {
+ await getExtensionService().reload();
+ } finally {
+ this.reloading_ = false;
+ this.refreshFromService_();
+ }
+ }
+
+ private handleOpenFolder_(item: PluginItem): void {
+ const fs = getEditorContext().fs;
+ if (!fs || item.type !== 'npm') return;
+ const parts = item.id.split('/');
+ const folderPath = parts.length > 1
+ ? `node_modules/${parts[0]}/${parts[1]}`
+ : `node_modules/${item.id}`;
+ fs.openFolder(folderPath);
+ }
+}
+
+function escapeHtml(text: string): string {
+ return text
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+}
diff --git a/editor/src/services/ExtensionService.ts b/editor/src/services/ExtensionService.ts
index a0ff9fab2..3d601a814 100644
--- a/editor/src/services/ExtensionService.ts
+++ b/editor/src/services/ExtensionService.ts
@@ -4,7 +4,7 @@ import {
PostProcess, Renderer, RenderStage,
registerDrawCallback, unregisterDrawCallback, clearDrawCallbacks,
} from 'esengine';
-import { ExtensionLoader } from '../extension';
+import { ExtensionLoader, type ExtensionPluginInfo } from '../extension';
import { setEditorAPI, clearEditorAPI } from '../extension/editorAPI';
import { showToast, showSuccessToast, showErrorToast } from '../ui/Toast';
import { showContextMenu } from '../ui/ContextMenu';
@@ -18,10 +18,18 @@ import {
PANEL,
} from '../container';
import * as containerTokens from '../container/tokens';
+import { EditorExtensionAPI } from '../extension/EditorExtensionAPI';
import { getAllPanels } from '../panels/PanelRegistry';
import type { PanelManager } from '../PanelManager';
import type { MenuManager } from '../MenuManager';
import type { DockLayoutManager } from '../DockLayoutManager';
+import {
+ CHANNEL_EXTENSIONS_DATA,
+ CHANNEL_EXTENSIONS_TOGGLE,
+ CHANNEL_EXTENSIONS_RELOAD,
+ CHANNEL_EXTENSIONS_REQUEST,
+ type ExtensionToggleMessage,
+} from '../multiwindow/protocol';
export class ExtensionService {
private baseAPI_: Record<string, unknown> | null = null;
@@ -31,6 +39,10 @@ export class ExtensionService {
private menuManager_: MenuManager;
private container_: HTMLElement;
private dockLayout_: DockLayoutManager | null = null;
+ private unlistenToggle_: (() => void) | null = null;
+ private unlistenReload_: (() => void) | null = null;
+ private unlistenRequest_: (() => void) | null = null;
+ private reloading_ = false;
constructor(
projectPath: string | null,
@@ -48,6 +60,52 @@ export class ExtensionService {
this.dockLayout_ = dockLayout;
}
+ get isReloading(): boolean {
+ return this.reloading_;
+ }
+
+ async startListening(): Promise<void> {
+ if (typeof window === 'undefined' || !('__TAURI_INTERNALS__' in window)) return;
+ const { listen } = await import('@tauri-apps/api/event');
+
+ this.unlistenToggle_ = (await listen<ExtensionToggleMessage>(
+ CHANNEL_EXTENSIONS_TOGGLE,
+ (event) => this.handleRemoteToggle_(event.payload.pluginId),
+ )) as unknown as () => void;
+
+ this.unlistenReload_ = (await listen(
+ CHANNEL_EXTENSIONS_RELOAD,
+ () => this.reload(),
+ )) as unknown as () => void;
+
+ this.unlistenRequest_ = (await listen(
+ CHANNEL_EXTENSIONS_REQUEST,
+ () => this.broadcastPluginList(),
+ )) as unknown as () => void;
+ }
+
+ broadcastPluginList(): void {
+ if (typeof window === 'undefined' || !('__TAURI_INTERNALS__' in window)) return;
+ import('@tauri-apps/api/event').then(({ emit }) => {
+ emit(CHANNEL_EXTENSIONS_DATA, {
+ plugins: this.getDiscoveredPlugins(),
+ reloading: this.reloading_,
+ });
+ });
+ }
+
+ private handleRemoteToggle_(pluginId: string): void {
+ const disabled = getSettingsValue<string[]>('extensions.disabled') ?? [];
+ const set = new Set(disabled);
+ if (set.has(pluginId)) {
+ set.delete(pluginId);
+ } else {
+ set.add(pluginId);
+ }
+ setSettingsValue('extensions.disabled', Array.from(set));
+ this.reload();
+ }
+
setupEditorGlobals(): void {
const container = getEditorContainer();
const registrar = container as import('../container').PluginRegistrar;
@@ -79,6 +137,7 @@ export class ExtensionService {
registerDrawCallback,
unregisterDrawCallback,
clearDrawCallbacks,
+ editor: new EditorExtensionAPI(container),
};
setEditorAPI(this.baseAPI_);
}
@@ -138,16 +197,29 @@ export class ExtensionService {
this.menuManager_.rebuildMenuBar(this.container_);
}
+ getDiscoveredPlugins(): ExtensionPluginInfo[] {
+ return this.extensionLoader_?.getDiscoveredPlugins() ?? [];
+ }
+
async reload(): Promise<boolean> {
if (!this.extensionLoader_) {
if (this.projectPath_) {
await this.initialize();
+ this.broadcastPluginList();
return true;
}
return false;
}
- return this.extensionLoader_.reload();
+ this.reloading_ = true;
+ this.broadcastPluginList();
+ try {
+ const result = await this.extensionLoader_.reload();
+ return result;
+ } finally {
+ this.reloading_ = false;
+ this.broadcastPluginList();
+ }
}
clearAPI(): void {
@@ -155,6 +227,9 @@ export class ExtensionService {
}
dispose(): void {
+ this.unlistenToggle_?.();
+ this.unlistenReload_?.();
+ this.unlistenRequest_?.();
this.extensionLoader_?.dispose();
clearEditorAPI();
}
diff --git a/editor/src/styles/extensions.css b/editor/src/styles/extensions.css
new file mode 100644
index 000000000..61785aa0c
--- /dev/null
+++ b/editor/src/styles/extensions.css
@@ -0,0 +1,401 @@
+/* =============================================================================
+ * Extensions Panel
+ * ============================================================================= */
+
+.es-extensions-panel {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ background: var(--es-bg-primary);
+ font-family: var(--es-font-family);
+}
+
+/* Toolbar */
+
+.es-ext-toolbar {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0 var(--es-space-2);
+ min-height: var(--es-toolbar-height);
+ background: var(--es-bg-secondary);
+ border-bottom: 1px solid var(--es-border);
+ flex-shrink: 0;
+}
+
+.es-ext-toolbar-title {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ font-size: 11px;
+ font-weight: 600;
+ color: var(--es-text-secondary);
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+}
+
+.es-ext-toolbar-title svg {
+ color: var(--es-text-muted);
+}
+
+.es-ext-toolbar-btn {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 22px;
+ height: 22px;
+ padding: 0;
+ border: none;
+ border-radius: var(--es-radius-sm);
+ background: transparent;
+ color: var(--es-text-secondary);
+ cursor: pointer;
+ transition: all var(--es-transition-fast);
+}
+
+.es-ext-toolbar-btn:hover {
+ background: var(--es-bg-hover);
+ color: var(--es-text-primary);
+}
+
+/* Body */
+
+.es-ext-body {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-height: 0;
+}
+
+.es-ext-list {
+ flex: 1;
+ overflow-y: auto;
+ padding: var(--es-space-1) 0;
+}
+
+.es-ext-detail {
+ flex-shrink: 0;
+ border-top: 1px solid var(--es-border);
+ background: var(--es-bg-secondary);
+ max-height: 45%;
+ overflow-y: auto;
+}
+
+/* Group */
+
+.es-ext-group {
+ margin-bottom: 2px;
+}
+
+.es-ext-group-header {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 4px var(--es-space-3);
+ font-size: 10px;
+ font-weight: 600;
+ color: var(--es-text-muted);
+ text-transform: uppercase;
+ letter-spacing: 0.8px;
+ user-select: none;
+}
+
+.es-ext-group-badge {
+ font-size: 9px;
+ font-weight: 700;
+ color: var(--es-text-muted);
+ background: var(--es-bg-tertiary);
+ padding: 0 5px;
+ border-radius: 8px;
+ line-height: 16px;
+}
+
+/* Status dot */
+
+.es-ext-dot {
+ display: inline-block;
+ width: 6px;
+ height: 6px;
+ border-radius: 50%;
+ flex-shrink: 0;
+}
+
+.es-ext-dot--on {
+ background: var(--es-success);
+ box-shadow: 0 0 4px var(--es-success);
+}
+
+.es-ext-dot--err {
+ background: var(--es-danger);
+ box-shadow: 0 0 4px var(--es-danger);
+}
+
+.es-ext-dot--off {
+ background: var(--es-text-muted);
+ opacity: 0.5;
+}
+
+/* Row item */
+
+.es-ext-row {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ height: var(--es-row-height);
+ padding: 0 var(--es-space-3);
+ cursor: pointer;
+ font-size: 12px;
+ color: var(--es-text-primary);
+ border-left: 2px solid transparent;
+ transition: background var(--es-transition-fast), border-color var(--es-transition-fast);
+}
+
+.es-ext-row:hover {
+ background: var(--es-bg-tertiary);
+}
+
+.es-ext-row.es-selected {
+ background: var(--es-accent-subtle);
+ border-left-color: var(--es-accent);
+}
+
+.es-ext-row--off {
+ opacity: 0.5;
+}
+
+.es-ext-row--off:hover {
+ opacity: 0.75;
+}
+
+.es-ext-row-name {
+ font-weight: 500;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ min-width: 0;
+}
+
+.es-ext-row-ver {
+ font-size: 10px;
+ color: var(--es-text-muted);
+ font-family: var(--es-font-mono);
+ flex-shrink: 0;
+}
+
+.es-ext-row-spacer {
+ flex: 1;
+}
+
+.es-ext-row-action {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 18px;
+ height: 18px;
+ padding: 0;
+ border: none;
+ border-radius: var(--es-radius-sm);
+ background: transparent;
+ color: var(--es-text-muted);
+ cursor: pointer;
+ opacity: 0;
+ transition: all var(--es-transition-fast);
+ flex-shrink: 0;
+}
+
+.es-ext-row:hover .es-ext-row-action {
+ opacity: 1;
+}
+
+.es-ext-row-action:hover {
+ background: var(--es-bg-hover);
+ color: var(--es-text-primary);
+}
+
+/* Detail — empty */
+
+.es-ext-detail-empty {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: var(--es-space-4);
+ color: var(--es-text-muted);
+ font-size: 11px;
+}
+
+/* Detail — content */
+
+.es-ext-detail-content {
+ padding: var(--es-space-3);
+}
+
+.es-ext-detail-header {
+ display: flex;
+ align-items: baseline;
+ gap: 6px;
+ margin-bottom: var(--es-space-2);
+}
+
+.es-ext-detail-name {
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--es-text-primary);
+}
+
+.es-ext-detail-ver {
+ font-size: 11px;
+ color: var(--es-text-muted);
+ font-family: var(--es-font-mono);
+}
+
+.es-ext-detail-desc {
+ font-size: 11px;
+ color: var(--es-text-secondary);
+ line-height: 1.4;
+ margin-bottom: var(--es-space-2);
+}
+
+/* Detail fields */
+
+.es-ext-detail-fields {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ margin-bottom: var(--es-space-3);
+ font-size: 11px;
+}
+
+.es-ext-detail-field {
+ display: flex;
+ align-items: center;
+ gap: var(--es-space-2);
+ padding: 2px 0;
+}
+
+.es-ext-field-key {
+ width: 48px;
+ flex-shrink: 0;
+ color: var(--es-text-muted);
+}
+
+.es-ext-field-val {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ color: var(--es-text-primary);
+ word-break: break-all;
+}
+
+.es-ext-mono {
+ font-family: var(--es-font-mono);
+ font-size: 10px;
+}
+
+/* Detail error */
+
+.es-ext-detail-err-box {
+ margin-bottom: var(--es-space-3);
+}
+
+.es-ext-detail-err-title {
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 11px;
+ font-weight: 600;
+ color: var(--es-danger);
+ margin-bottom: 4px;
+}
+
+.es-ext-detail-err-msg {
+ margin: 0;
+ padding: var(--es-space-2);
+ background: hsla(4, 60%, 55%, 0.08);
+ border: 1px solid hsla(4, 60%, 55%, 0.2);
+ border-radius: var(--es-radius-sm);
+ font-family: var(--es-font-mono);
+ font-size: 10px;
+ color: var(--es-danger);
+ white-space: pre-wrap;
+ word-break: break-all;
+ max-height: 80px;
+ overflow-y: auto;
+ line-height: 1.4;
+}
+
+/* Detail actions */
+
+.es-ext-detail-actions {
+ display: flex;
+ gap: var(--es-space-2);
+}
+
+.es-ext-detail-actions .es-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 11px;
+}
+
+/* Loading */
+
+.es-ext-loading {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: var(--es-space-2);
+ padding: var(--es-space-6) var(--es-space-4);
+ color: var(--es-text-muted);
+ font-size: 11px;
+}
+
+.es-ext-spinner {
+ width: 16px;
+ height: 16px;
+ border: 2px solid var(--es-bg-hover);
+ border-top-color: var(--es-accent);
+ border-radius: 50%;
+ animation: es-ext-spin 0.6s linear infinite;
+}
+
+@keyframes es-ext-spin {
+ to { transform: rotate(360deg); }
+}
+
+/* Empty */
+
+.es-ext-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: var(--es-space-2);
+ padding: var(--es-space-6) var(--es-space-4);
+ text-align: center;
+}
+
+.es-ext-empty-icon {
+ color: var(--es-text-muted);
+ opacity: 0.25;
+}
+
+.es-ext-empty-title {
+ font-size: 12px;
+ font-weight: 600;
+ color: var(--es-text-secondary);
+}
+
+.es-ext-empty-desc {
+ font-size: 11px;
+ color: var(--es-text-muted);
+ line-height: 1.5;
+ max-width: 260px;
+}
+
+.es-ext-empty-desc code {
+ padding: 1px 3px;
+ border-radius: 2px;
+ background: var(--es-bg-tertiary);
+ font-family: var(--es-font-mono);
+ font-size: 10px;
+ color: var(--es-text-secondary);
+}
diff --git a/editor/src/utils/icons.ts b/editor/src/utils/icons.ts
index b30548c33..6537270cb 100644
--- a/editor/src/utils/icons.ts
+++ b/editor/src/utils/icons.ts
@@ -74,6 +74,8 @@ import {
Hexagon,
Link2,
GripVertical,
+ Info,
+ TriangleAlert,
} from 'lucide';
// =============================================================================
@@ -204,6 +206,8 @@ export const icons = {
hexagon: (size?: number) => renderIcon(Hexagon as IconNode, size),
link: (size?: number) => renderIcon(Link2 as IconNode, size),
grip: (size?: number) => renderIcon(GripVertical as IconNode, size),
+ info: (size?: number) => renderIcon(Info as IconNode, size),
+ alertTriangle: (size?: number) => renderIcon(TriangleAlert as IconNode, size),
};
export type IconName = keyof typeof icons;