-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathstartup-task.ts
42 lines (38 loc) · 1.21 KB
/
startup-task.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { injectable } from '@theia/core/shared/inversify';
import { WorkspaceInput as TheiaWorkspaceInput } from '@theia/workspace/lib/browser';
import { Contribution } from '../../contributions/contribution';
export interface Task {
command: string;
/**
* This must be JSON serializable.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args?: any[];
}
@injectable()
export class StartupTask extends Contribution {
override onReady(): void {
const params = new URLSearchParams(window.location.search);
const encoded = params.get(StartupTask.QUERY_STRING);
if (!encoded) return;
const commands = JSON.parse(decodeURIComponent(encoded));
if (Array.isArray(commands)) {
commands.forEach(({ command, args }) => {
this.commandService.executeCommand(command, ...args);
});
}
}
}
export namespace StartupTask {
export const QUERY_STRING = 'startupTasks';
export interface WorkspaceInput extends TheiaWorkspaceInput {
tasks: Task[];
}
export namespace WorkspaceInput {
export function is(
input: (TheiaWorkspaceInput & Partial<WorkspaceInput>) | undefined
): input is WorkspaceInput {
return !!input && !!input.tasks;
}
}
}