- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathstartup-tasks-executor.ts
65 lines (60 loc) · 1.73 KB
/
startup-tasks-executor.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import{DisposableCollection}from'@theia/core/lib/common/disposable';
import{
inject,
injectable,
postConstruct,
}from'@theia/core/shared/inversify';
import{
hasStartupTasks,
StartupTasks,
}from'../../electron-common/startup-task';
import{AppService}from'../app-service';
import{Contribution}from'./contribution';
@injectable()
exportclassStartupTasksExecutorextendsContribution{
@inject(AppService)
privatereadonlyappService: AppService;
privatereadonlytoDispose=newDisposableCollection();
@postConstruct()
protectedoverrideinit(): void{
super.init();
this.toDispose.push(
this.appService.registerStartupTasksHandler((tasks)=>
this.handleStartupTasks(tasks)
)
);
}
onStop(): void{
this.toDispose.dispose();
}
privateasynchandleStartupTasks(tasks: StartupTasks): Promise<void>{
console.debug(
`Received the startup tasks from the electron main process. Args: ${JSON.stringify(
tasks
)}`
);
if(!hasStartupTasks(tasks)){
console.warn(`Could not detect 'tasks' from the signal. Skipping.`);
return;
}
awaitthis.appStateService.reachedState('ready');
console.log(`Executing startup tasks:`);
tasks.tasks.forEach(({ command, args =[]})=>{
console.log(
` - '${command}' ${
args.length ? `, args: ${JSON.stringify(args)}` : ''
}`
);
this.commandService
.executeCommand(command, ...args)
.catch((err)=>
console.error(
`Error occurred when executing the startup task '${command}'${
args?.length ? ` with args: '${JSON.stringify(args)}` : ''
}.`,
err
)
);
});
}
}