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,14 @@ 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 ) =>
687
+ setTimeout ( ( ) => resolve ( undefined ) , 2_000 )
688
+ ) ,
689
+ ] ) ;
663
690
}
664
691
if ( storedLatestBoardsConfig ) {
665
692
this . latestBoardsConfig = storedLatestBoardsConfig ;
@@ -682,6 +709,22 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
682
709
key
683
710
) ;
684
711
}
712
+
713
+ tasks ( ) : StartupTask [ ] {
714
+ return [
715
+ {
716
+ command : InheritedBoardsConfig . USE_CONFIG . id ,
717
+ args : [ this . boardsConfig ] ,
718
+ } ,
719
+ ] ;
720
+ }
721
+ }
722
+
723
+ // Should not be visible from outside and called explicitly.
724
+ namespace InheritedBoardsConfig {
725
+ export const USE_CONFIG : Command = {
726
+ id : 'arduino-use-inherited-boards-config' ,
727
+ } ;
685
728
}
686
729
687
730
/**
0 commit comments