1
1
import { injectable , inject } from '@theia/core/shared/inversify' ;
2
2
import { Emitter } from '@theia/core/lib/common/event' ;
3
3
import { ILogger } from '@theia/core/lib/common/logger' ;
4
- import { CommandService } from '@theia/core/lib/common/command' ;
4
+ import {
5
+ Command ,
6
+ CommandContribution ,
7
+ CommandRegistry ,
8
+ CommandService ,
9
+ } from '@theia/core/lib/common/command' ;
5
10
import { MessageService } from '@theia/core/lib/common/message-service' ;
6
11
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
7
12
import { RecursiveRequired } from '../../common/types' ;
@@ -23,9 +28,18 @@ import { nls } from '@theia/core/lib/common';
23
28
import { Deferred } from '@theia/core/lib/common/promise-util' ;
24
29
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state' ;
25
30
import { Unknown } from '../../common/nls' ;
31
+ import {
32
+ StartupTask ,
33
+ StartupTaskProvider ,
34
+ } from '../../electron-common/startup-task' ;
26
35
27
36
@injectable ( )
28
- export class BoardsServiceProvider implements FrontendApplicationContribution {
37
+ export class BoardsServiceProvider
38
+ implements
39
+ FrontendApplicationContribution ,
40
+ StartupTaskProvider ,
41
+ CommandContribution
42
+ {
29
43
@inject ( ILogger )
30
44
protected logger : ILogger ;
31
45
@@ -115,6 +129,16 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
115
129
} ) ;
116
130
}
117
131
132
+ // instead of gathering the boards config from the URL,
133
+ // it is set from the electron-main process, or not set at all.
134
+ private readonly inheritedConfig = new Deferred < BoardsConfig . Config > ( ) ;
135
+ registerCommands ( registry : CommandRegistry ) : void {
136
+ registry . registerCommand ( InheritedBoardsConfig . USE_CONFIG , {
137
+ execute : ( inheritedConfig : BoardsConfig . Config ) =>
138
+ this . inheritedConfig . resolve ( inheritedConfig ) ,
139
+ } ) ;
140
+ }
141
+
118
142
get reconciled ( ) : Promise < void > {
119
143
return this . _reconciled . promise ;
120
144
}
@@ -655,11 +679,12 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
655
679
let storedLatestBoardsConfig = await this . getData <
656
680
BoardsConfig . Config | undefined
657
681
> ( 'latest-boards-config' ) ;
658
- // Try to get from the URL if it was not persisted .
682
+ // Try to get from the startup task. Wait for it, then timeout. Maybe it never arrives .
659
683
if ( ! storedLatestBoardsConfig ) {
660
- storedLatestBoardsConfig = BoardsConfig . Config . getConfig (
661
- new URL ( window . location . href )
662
- ) ;
684
+ storedLatestBoardsConfig = await Promise . race ( [
685
+ this . inheritedConfig . promise ,
686
+ new Promise < undefined > ( ( resolve ) => setTimeout ( resolve , 2_000 ) ) ,
687
+ ] ) ;
663
688
}
664
689
if ( storedLatestBoardsConfig ) {
665
690
this . latestBoardsConfig = storedLatestBoardsConfig ;
@@ -682,6 +707,22 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
682
707
key
683
708
) ;
684
709
}
710
+
711
+ tasks ( ) : StartupTask [ ] {
712
+ return [
713
+ {
714
+ command : InheritedBoardsConfig . USE_CONFIG . id ,
715
+ args : [ this . boardsConfig ] ,
716
+ } ,
717
+ ] ;
718
+ }
719
+ }
720
+
721
+ // Should not be visible from outside and called explicitly.
722
+ namespace InheritedBoardsConfig {
723
+ export const USE_CONFIG : Command = {
724
+ id : 'arduino-use-inherited-boards-config' ,
725
+ } ;
685
726
}
686
727
687
728
/**
0 commit comments