11import * as electron from 'electron' ;
2- import { injectable } from "inversify" ;
2+ import { injectable , inject } from "inversify" ;
33import { ElectronMenuContribution } from "@theia/core/lib/electron-browser/menu/electron-menu-contribution" ;
44import { FrontendApplication } from "@theia/core/lib/browser" ;
55import { isOSX } from '@theia/core' ;
6+ import { WorkspaceService } from '@theia/workspace/lib/browser' ;
67
78@injectable ( )
89export class ElectronArduinoMenuContribution extends ElectronMenuContribution {
9- onStart ( app : FrontendApplication ) : void {
10- const currentWindow = electron . remote . getCurrentWindow ( ) ;
11- const createdMenuBar = this . factory . createMenuBar ( ) ;
1210
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 ;
2112
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+ } ) ;
2630 }
2731}
0 commit comments