Skip to content

Commit ec515c0

Browse files
code-asherkylecarbs
authored andcommitted
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.
1 parent 6bb6200 commit ec515c0

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

packages/vscode/src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import "./fill/environmentService";
66
import "./fill/vscodeTextmate";
77
import "./fill/codeEditor";
88
import "./fill/mouseEvent";
9+
import "./fill/menuRegistry";
10+
import "./fill/workbenchRegistry";
911
import { PasteAction } from "./fill/paste";
1012
import "./fill/dom";
1113
import "./vscode.scss";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { logger } from "@coder/logger";
2+
import { IDisposable } from "vs/base/common/lifecycle";
3+
import * as actions from "vs/platform/actions/common/actions";
4+
import { ToggleDevToolsAction } from "vs/workbench/electron-browser/actions";
5+
6+
// Intercept appending menu items so we can skip items that won't work.
7+
const originalAppend = actions.MenuRegistry.appendMenuItem.bind(actions.MenuRegistry);
8+
actions.MenuRegistry.appendMenuItem = (id: actions.MenuId, item: actions.IMenuItem | actions.ISubmenuItem): IDisposable => {
9+
if (actions.isIMenuItem(item)) {
10+
switch (item.command.id) {
11+
case ToggleDevToolsAction.ID: // There appears to be no way to toggle this programmatically.
12+
logger.debug(`Skipping unsupported menu item ${item.command.id}`);
13+
14+
return {
15+
dispose: (): void => undefined,
16+
};
17+
}
18+
}
19+
20+
return originalAppend(id, item);
21+
};

packages/vscode/src/fill/windowsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class WindowsService implements IWindowsService {
8787
}
8888

8989
public toggleDevTools(_windowId: number): Promise<void> {
90-
throw new Error("not implemented");
90+
throw new Error("Toggling developer tools from JavaScript is not supported.");
9191
}
9292

9393
public closeWorkspace(_windowId: number): Promise<void> {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { logger } from "@coder/logger";
2+
import { IDisposable } from "vs/base/common/lifecycle";
3+
import { Registry } from "vs/platform/registry/common/platform";
4+
import { IWorkbenchActionRegistry, Extensions } from "vs/workbench/common/actions";
5+
import { SyncActionDescriptor } from "vs/platform/actions/common/actions";
6+
import { ContextKeyExpr } from "vs/platform/contextkey/common/contextkey";
7+
import { ToggleDevToolsAction } from "vs/workbench/electron-browser/actions";
8+
9+
// Intercept adding workbench actions so we can skip actions that won't work.
10+
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
11+
const originalRegister = registry.registerWorkbenchAction.bind(registry);
12+
registry.registerWorkbenchAction = (descriptor: SyncActionDescriptor, alias: string, category?: string, when?: ContextKeyExpr): IDisposable => {
13+
switch (descriptor.id) {
14+
case ToggleDevToolsAction.ID: // There appears to be no way to toggle this programmatically.
15+
logger.debug(`Skipping unsupported workbench action ${descriptor.id}`);
16+
17+
return {
18+
dispose: (): void => undefined,
19+
};
20+
}
21+
22+
return originalRegister(descriptor, alias, category, when);
23+
};

0 commit comments

Comments
 (0)