1- import PQueue from 'p-queue' ;
2- import { inject , injectable } from '@theia/core/shared/inversify' ;
3- import { CommandRegistry } from '@theia/core/lib/common/command' ;
4- import { MenuModelRegistry } from '@theia/core/lib/common/menu' ;
51import {
62 Disposable ,
73 DisposableCollection ,
84} from '@theia/core/lib/common/disposable' ;
9- import { BoardsServiceProvider } from './boards-service-provider' ;
5+ import { nls } from '@theia/core/lib/common/nls' ;
6+ import { inject , injectable } from '@theia/core/shared/inversify' ;
7+ import PQueue from 'p-queue' ;
108import {
119 BoardIdentifier ,
1210 ConfigOption ,
1311 isBoardIdentifierChangeEvent ,
1412 Programmer ,
1513} from '../../common/protocol' ;
16- import { FrontendApplicationContribution } from '@theia/core/lib/browser' ;
17- import { BoardsDataStore } from './boards-data-store' ;
18- import { MainMenuManager } from '../../common/main-menu-manager' ;
14+ import { BoardsDataStore } from '../boards/boards-data-store' ;
15+ import { BoardsServiceProvider } from '../boards/boards-service-provider' ;
1916import { ArduinoMenus , unregisterSubmenu } from '../menu/arduino-menus' ;
20- import { nls } from '@theia/core/lib/common' ;
21- import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state' ;
17+ import {
18+ CommandRegistry ,
19+ Contribution ,
20+ MenuModelRegistry ,
21+ } from './contribution' ;
2222
2323@injectable ( )
24- export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
24+ export class BoardsDataMenuUpdater extends Contribution {
2525 @inject ( CommandRegistry )
26- protected readonly commandRegistry : CommandRegistry ;
27-
26+ private readonly commandRegistry : CommandRegistry ;
2827 @inject ( MenuModelRegistry )
29- protected readonly menuRegistry : MenuModelRegistry ;
30-
31- @inject ( MainMenuManager )
32- protected readonly mainMenuManager : MainMenuManager ;
33-
28+ private readonly menuRegistry : MenuModelRegistry ;
3429 @inject ( BoardsDataStore )
35- protected readonly boardsDataStore : BoardsDataStore ;
36-
30+ private readonly boardsDataStore : BoardsDataStore ;
3731 @inject ( BoardsServiceProvider )
38- protected readonly boardsServiceProvider : BoardsServiceProvider ;
39-
40- @inject ( FrontendApplicationStateService )
41- private readonly appStateService : FrontendApplicationStateService ;
32+ private readonly boardsServiceProvider : BoardsServiceProvider ;
4233
43- protected readonly queue = new PQueue ( { autoStart : true , concurrency : 1 } ) ;
44- protected readonly toDisposeOnBoardChange = new DisposableCollection ( ) ;
34+ private readonly queue = new PQueue ( { autoStart : true , concurrency : 1 } ) ;
35+ private readonly toDisposeOnBoardChange = new DisposableCollection ( ) ;
4536
46- async onStart ( ) : Promise < void > {
47- this . appStateService
48- . reachedState ( 'ready' )
49- . then ( ( ) =>
50- this . updateMenuActions (
51- this . boardsServiceProvider . boardsConfig . selectedBoard
52- )
53- ) ;
37+ override onStart ( ) : void {
5438 this . boardsDataStore . onChanged ( ( ) =>
55- this . updateMenuActions ( this . boardsServiceProvider . boardsConfig . selectedBoard )
39+ this . updateMenuActions (
40+ this . boardsServiceProvider . boardsConfig . selectedBoard
41+ )
5642 ) ;
5743 this . boardsServiceProvider . onBoardsConfigDidChange ( ( event ) => {
5844 if ( isBoardIdentifierChangeEvent ( event ) ) {
@@ -61,12 +47,20 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
6147 } ) ;
6248 }
6349
64- protected async updateMenuActions (
50+ override onReady ( ) : void {
51+ this . boardsServiceProvider . ready . then ( ( ) =>
52+ this . updateMenuActions (
53+ this . boardsServiceProvider . boardsConfig . selectedBoard
54+ )
55+ ) ;
56+ }
57+
58+ private async updateMenuActions (
6559 selectedBoard : BoardIdentifier | undefined
6660 ) : Promise < void > {
6761 return this . queue . add ( async ( ) => {
6862 this . toDisposeOnBoardChange . dispose ( ) ;
69- this . mainMenuManager . update ( ) ;
63+ this . menuManager . update ( ) ;
7064 if ( selectedBoard ) {
7165 const { fqbn } = selectedBoard ;
7266 if ( fqbn ) {
@@ -177,7 +171,7 @@ export class BoardsDataMenuUpdater implements FrontendApplicationContribution {
177171 ] ) ;
178172 }
179173 }
180- this . mainMenuManager . update ( ) ;
174+ this . menuManager . update ( ) ;
181175 }
182176 }
183177 } ) ;
0 commit comments