From ec515c0a3f3db41bf062fe6703e076fc8f6df43c Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 4 Feb 2019 11:27:36 -0600 Subject: [PATCH] Skip unsupported actions and menu items Using this to skip the toggle developer tools action since there doesn't seem to be any way to do that from the browser. There might be others we will need to add. --- packages/vscode/src/client.ts | 2 ++ packages/vscode/src/fill/menuRegistry.ts | 21 +++++++++++++++++ packages/vscode/src/fill/windowsService.ts | 2 +- packages/vscode/src/fill/workbenchRegistry.ts | 23 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 packages/vscode/src/fill/menuRegistry.ts create mode 100644 packages/vscode/src/fill/workbenchRegistry.ts diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index e0ba5484..12f94f00 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -6,6 +6,8 @@ import "./fill/environmentService"; import "./fill/vscodeTextmate"; import "./fill/codeEditor"; import "./fill/mouseEvent"; +import "./fill/menuRegistry"; +import "./fill/workbenchRegistry"; import { PasteAction } from "./fill/paste"; import "./fill/dom"; import "./vscode.scss"; diff --git a/packages/vscode/src/fill/menuRegistry.ts b/packages/vscode/src/fill/menuRegistry.ts new file mode 100644 index 00000000..c1f41f47 --- /dev/null +++ b/packages/vscode/src/fill/menuRegistry.ts @@ -0,0 +1,21 @@ +import { logger } from "@coder/logger"; +import { IDisposable } from "vs/base/common/lifecycle"; +import * as actions from "vs/platform/actions/common/actions"; +import { ToggleDevToolsAction } from "vs/workbench/electron-browser/actions"; + +// Intercept appending menu items so we can skip items that won't work. +const originalAppend = actions.MenuRegistry.appendMenuItem.bind(actions.MenuRegistry); +actions.MenuRegistry.appendMenuItem = (id: actions.MenuId, item: actions.IMenuItem | actions.ISubmenuItem): IDisposable => { + if (actions.isIMenuItem(item)) { + switch (item.command.id) { + case ToggleDevToolsAction.ID: // There appears to be no way to toggle this programmatically. + logger.debug(`Skipping unsupported menu item ${item.command.id}`); + + return { + dispose: (): void => undefined, + }; + } + } + + return originalAppend(id, item); +}; diff --git a/packages/vscode/src/fill/windowsService.ts b/packages/vscode/src/fill/windowsService.ts index 6945e8d4..5f68d98d 100644 --- a/packages/vscode/src/fill/windowsService.ts +++ b/packages/vscode/src/fill/windowsService.ts @@ -87,7 +87,7 @@ class WindowsService implements IWindowsService { } public toggleDevTools(_windowId: number): Promise { - throw new Error("not implemented"); + throw new Error("Toggling developer tools from JavaScript is not supported."); } public closeWorkspace(_windowId: number): Promise { diff --git a/packages/vscode/src/fill/workbenchRegistry.ts b/packages/vscode/src/fill/workbenchRegistry.ts new file mode 100644 index 00000000..85e62840 --- /dev/null +++ b/packages/vscode/src/fill/workbenchRegistry.ts @@ -0,0 +1,23 @@ +import { logger } from "@coder/logger"; +import { IDisposable } from "vs/base/common/lifecycle"; +import { Registry } from "vs/platform/registry/common/platform"; +import { IWorkbenchActionRegistry, Extensions } from "vs/workbench/common/actions"; +import { SyncActionDescriptor } from "vs/platform/actions/common/actions"; +import { ContextKeyExpr } from "vs/platform/contextkey/common/contextkey"; +import { ToggleDevToolsAction } from "vs/workbench/electron-browser/actions"; + +// Intercept adding workbench actions so we can skip actions that won't work. +const registry = Registry.as(Extensions.WorkbenchActions); +const originalRegister = registry.registerWorkbenchAction.bind(registry); +registry.registerWorkbenchAction = (descriptor: SyncActionDescriptor, alias: string, category?: string, when?: ContextKeyExpr): IDisposable => { + switch (descriptor.id) { + case ToggleDevToolsAction.ID: // There appears to be no way to toggle this programmatically. + logger.debug(`Skipping unsupported workbench action ${descriptor.id}`); + + return { + dispose: (): void => undefined, + }; + } + + return originalRegister(descriptor, alias, category, when); +};