fix(plugin): close plugin tabs safely and hide load flash
This commit is contained in:
8 files changed
+66
-13
No files matched your search
@@ -28,6 +28,7 @@ export interface PluginHostBridgeApi {
|
||||
readAsset(pluginId: string, path: string): Promise<PluginUiAssetPayload>;
|
||||
openWorkbench?(pluginId: string, contributionId: string, context?: PluginWorkbenchContext): Promise<void> | void;
|
||||
openFilesystem?(pluginId: string, providerId: string, context?: PluginWorkbenchContext): Promise<void> | void;
|
||||
closeTab?(): Promise<void> | void;
|
||||
}
|
||||
|
||||
interface PluginRequestMessage {
|
||||
@@ -68,6 +69,10 @@ export class PluginHostBridge {
|
||||
this.sendInit();
|
||||
return true;
|
||||
}
|
||||
if (event.data.type === "shortcut" && event.data.shortcut === "closeTab") {
|
||||
void this.api.closeTab?.();
|
||||
return true;
|
||||
}
|
||||
if (event.data.type !== "request" || !validRequestMessage(event.data)) return false;
|
||||
void this.handleRequest(event.data, target);
|
||||
return true;
|
||||
@@ -397,6 +402,13 @@ function pluginSdkSource(): string {
|
||||
dispatchEvent(new CustomEvent('dbx-plugin-binary', { detail: payload }));
|
||||
}
|
||||
});
|
||||
addEventListener('keydown', (event) => {
|
||||
const key = typeof event.key === 'string' ? event.key.toLowerCase() : '';
|
||||
if (key !== 'w' || (!event.metaKey && !event.ctrlKey) || event.altKey || event.shiftKey || event.isComposing) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
parent.postMessage({ source: '${PLUGIN_MESSAGE_SOURCE}', version: ${BRIDGE_VERSION}, type: 'shortcut', shortcut: 'closeTab' }, '*');
|
||||
}, true);
|
||||
parent.postMessage({ source: '${PLUGIN_MESSAGE_SOURCE}', version: ${BRIDGE_VERSION}, type: 'ready' }, '*');
|
||||
})();`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user