1
1
import * as electron from 'electron' ;
2
- import { injectable } from "inversify" ;
2
+ import { injectable , inject } from "inversify" ;
3
3
import { ElectronMenuContribution } from "@theia/core/lib/electron-browser/menu/electron-menu-contribution" ;
4
4
import { FrontendApplication } from "@theia/core/lib/browser" ;
5
5
import { isOSX } from '@theia/core' ;
6
+ import { WorkspaceService } from '@theia/workspace/lib/browser' ;
6
7
7
8
@injectable ( )
8
9
export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
9
- onStart ( app : FrontendApplication ) : void {
10
- const currentWindow = electron . remote . getCurrentWindow ( ) ;
11
- const createdMenuBar = this . factory . createMenuBar ( ) ;
12
10
13
- if ( isOSX ) {
14
- electron . remote . Menu . setApplicationMenu ( createdMenuBar ) ;
15
- currentWindow . on ( 'focus' , ( ) =>
16
- // OSX: Recreate the menus when changing windows.
17
- // OSX only has one menu bar for all windows, so we need to swap
18
- // between them as the user switch windows.
19
- electron . remote . Menu . setApplicationMenu ( this . factory . createMenuBar ( ) )
20
- ) ;
11
+ @inject ( WorkspaceService ) protected readonly workspaceService : WorkspaceService ;
21
12
22
- } else {
23
- // Unix/Windows: Set the per-window menus
24
- currentWindow . setMenu ( createdMenuBar ) ;
25
- }
13
+ onStart ( app : FrontendApplication ) : void {
14
+ this . workspaceService . onWorkspaceChanged ( ( ) => {
15
+ const createdMenuBar = this . factory . createMenuBar ( ) ;
16
+ const currentWindow = electron . remote . getCurrentWindow ( ) ;
17
+ if ( isOSX ) {
18
+ electron . remote . Menu . setApplicationMenu ( createdMenuBar ) ;
19
+ currentWindow . on ( 'focus' , ( ) =>
20
+ // OSX: Recreate the menus when changing windows.
21
+ // OSX only has one menu bar for all windows, so we need to swap
22
+ // between them as the user switch windows.
23
+ electron . remote . Menu . setApplicationMenu ( this . factory . createMenuBar ( ) )
24
+ ) ;
25
+ } else {
26
+ // Unix/Windows: Set the per-window menus
27
+ currentWindow . setMenu ( createdMenuBar ) ;
28
+ }
29
+ } ) ;
26
30
}
27
31
}
0 commit comments