Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(desktop): close plugin panel on reload and clean up failed panel loads

Totopo27d65403a050a9
diff --git a/apps/desktop/electron/main/plugin-panel-host.ts b/apps/desktop/electron/main/plugin-panel-host.ts
index 08c7ed7db..15244454f 100644
--- a/apps/desktop/electron/main/plugin-panel-host.ts
+++ b/apps/desktop/electron/main/plugin-panel-host.ts
@@ -538,8 +538,17 @@ export class PluginPanelHost {
// registered before the document loads and released only when the page is
// gone (see the `closed` handler above).
this.senders.register(webContentsId, request.pluginId);
- await win.loadURL(pathToFileURL(request.htmlPath).toString());
- win.show();
+ try {
+ await win.loadURL(pathToFileURL(request.htmlPath).toString());
+ if (!win.isDestroyed()) {
+ win.show();
+ }
+ } catch (error) {
+ if (!win.isDestroyed()) {
+ win.destroy();
+ }
+ throw error;
+ }
}
/**
diff --git a/apps/desktop/electron/main/services/plugin-services.ts b/apps/desktop/electron/main/services/plugin-services.ts
index ed8998e06..43a8ecf3d 100644
--- a/apps/desktop/electron/main/services/plugin-services.ts
+++ b/apps/desktop/electron/main/services/plugin-services.ts
@@ -463,6 +463,7 @@ export function createPluginServices({
});
// Views were loaded from the previous revision of the plugin's files.
pluginViews.closePlugin(pluginId);
+ void pluginPanels.close(pluginId);
if (pluginId === BROWSER_PLUGIN_ID) browserHost.disposeGuest();
sendToRenderer(IPC.event.pluginChanged,{ reason: "reload", pluginId });
},
diff --git a/apps/desktop/test/plugin-hot-reload.test.mjs b/apps/desktop/test/plugin-hot-reload.test.mjs
index 380e7e9cd..59a6a0613 100644
--- a/apps/desktop/test/plugin-hot-reload.test.mjs
+++ b/apps/desktop/test/plugin-hot-reload.test.mjs
@@ -136,5 +136,6 @@ test("watchers are released on teardown and reloads reach the renderer", () => {
);
assert.match(reported, /IPC\.event\.toast/);
assert.match(reported, /IPC\.event\.pluginChanged,\s*\{ reason: "reload", pluginId \}/);
+ assert.match(reported, /pluginPanels\.close\(pluginId\)/);
assert.match(reported, /Reload failed/);
});
diff --git a/apps/desktop/test/plugin-panel-window.test.mjs b/apps/desktop/test/plugin-panel-window.test.mjs
index 3ec758478..eda94e63a 100644
--- a/apps/desktop/test/plugin-panel-window.test.mjs
+++ b/apps/desktop/test/plugin-panel-window.test.mjs
@@ -96,6 +96,8 @@ test("plugin panel close does not read destroyed webContents", () => {
hostSource.indexOf("this.windows.set(request.pluginId, win);"),
);
assert.doesNotMatch(closedHandler, /win\.webContents/);
+ assert.match(hostSource, /await win\.loadURL\(/);
+ assert.match(hostSource, /if \(!win\.isDestroyed\(\)\) \{\s*win\.destroy\(\);\s*\}/);
});
test("plugin content is offset below the strict 46px host drag band", () => {