Skip to content

Commit 9630eb2

Browse files
author
Alberto Iannaccone
committed
add encoded commands contribution
1 parent 1b06314 commit 9630eb2

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ import { CoreErrorHandler } from './contributions/core-error-handler';
302302
import { CompilerErrors } from './contributions/compiler-errors';
303303
import { WidgetManager } from './theia/core/widget-manager';
304304
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
305+
import { EncodedCommandsContribution } from './widgets/sketchbook/encoded-commands-contribution';
305306

306307
MonacoThemingService.register({
307308
id: 'arduino-theme',
@@ -698,6 +699,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
698699
Contribution.configure(bind, PlotterFrontendContribution);
699700
Contribution.configure(bind, Format);
700701
Contribution.configure(bind, CompilerErrors);
702+
Contribution.configure(bind, EncodedCommandsContribution);
701703

702704
// Disabled the quick-pick customization from Theia when multiple formatters are available.
703705
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Command, CommandRegistry, MaybePromise } from '@theia/core';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { Contribution } from '../../contributions/contribution';
4+
5+
@injectable()
6+
export class EncodedCommandsContribution extends Contribution {
7+
@inject(CommandRegistry)
8+
protected readonly commandRegistry: CommandRegistry;
9+
10+
override onReady(): MaybePromise<void> {
11+
const params = new URLSearchParams(window.location.search);
12+
const encoded = params.get('commands');
13+
if (!encoded) return;
14+
15+
const commands = JSON.parse(decodeURIComponent(encoded));
16+
17+
if (Array.isArray(commands)) {
18+
commands.forEach((c: Command) => {
19+
this.commandRegistry.executeCommand(c.id);
20+
});
21+
}
22+
}
23+
}

arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as remote from '@theia/core/electron-shared/@electron/remote';
22
import { inject, injectable } from '@theia/core/shared/inversify';
3-
import { Command, CommandRegistry } from '@theia/core/lib/common/command';
3+
import { CommandRegistry } from '@theia/core/lib/common/command';
44
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
55
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
66
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
@@ -29,7 +29,6 @@ import {
2929
} from '../../../common/protocol/sketches-service-client-impl';
3030
import { FileService } from '@theia/filesystem/lib/browser/file-service';
3131
import { URI } from '../../contributions/contribution';
32-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
3332
import { EditorManager } from '@theia/editor/lib/browser';
3433
import { SketchControl } from '../../contributions/sketch-control';
3534
import { CloudSketchbookCommands } from '../cloud-sketchbook/cloud-sketchbook-contributions';
@@ -71,12 +70,6 @@ export class SketchbookWidgetContribution
7170
@inject(FileService)
7271
protected readonly fileService: FileService;
7372

74-
@inject(CommandRegistry)
75-
protected readonly commandRegistry: CommandRegistry;
76-
77-
@inject(FrontendApplicationStateService)
78-
private readonly app: FrontendApplicationStateService;
79-
8073
@inject(EditorManager)
8174
protected readonly editorManager: EditorManager;
8275

@@ -108,12 +101,6 @@ export class SketchbookWidgetContribution
108101
this.mainMenuManager.update();
109102
}
110103
});
111-
112-
this.app.reachedState('ready').then(() => this.onReady());
113-
}
114-
115-
onReady(): void {
116-
this.runEncodedCommands();
117104
}
118105

119106
async initializeLayout(): Promise<void> {
@@ -272,18 +259,4 @@ export class SketchbookWidgetContribution
272259
}
273260
});
274261
}
275-
276-
protected runEncodedCommands(): void {
277-
const params = new URLSearchParams(window.location.search);
278-
const encoded = params.get('commands');
279-
if (!encoded) return;
280-
281-
const commands = JSON.parse(decodeURIComponent(encoded));
282-
283-
if (Array.isArray(commands)) {
284-
commands.forEach((c: Command) => {
285-
this.commandRegistry.executeCommand(c.id);
286-
});
287-
}
288-
}
289262
}

0 commit comments

Comments
 (0)