@theia/core 1.37.0-next.9 → 1.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +7 -9
  2. package/i18n/nls.cs.json +6 -1
  3. package/i18n/nls.de.json +6 -1
  4. package/i18n/nls.es.json +6 -1
  5. package/i18n/nls.fr.json +6 -1
  6. package/i18n/nls.hu.json +6 -1
  7. package/i18n/nls.it.json +6 -1
  8. package/i18n/nls.ja.json +6 -1
  9. package/i18n/nls.json +6 -1
  10. package/i18n/nls.pl.json +6 -1
  11. package/i18n/nls.pt-br.json +6 -1
  12. package/i18n/nls.pt-pt.json +6 -1
  13. package/i18n/nls.ru.json +6 -1
  14. package/i18n/nls.zh-cn.json +6 -1
  15. package/lib/browser/core-preferences.d.ts +4 -0
  16. package/lib/browser/core-preferences.d.ts.map +1 -1
  17. package/lib/browser/core-preferences.js +22 -0
  18. package/lib/browser/core-preferences.js.map +1 -1
  19. package/lib/browser/hover-service.d.ts +5 -0
  20. package/lib/browser/hover-service.d.ts.map +1 -1
  21. package/lib/browser/hover-service.js +7 -1
  22. package/lib/browser/hover-service.js.map +1 -1
  23. package/lib/browser/icon-theme-service.js +1 -1
  24. package/lib/browser/icon-theme-service.js.map +1 -1
  25. package/lib/browser/shell/application-shell.d.ts +2 -1
  26. package/lib/browser/shell/application-shell.d.ts.map +1 -1
  27. package/lib/browser/shell/application-shell.js +30 -3
  28. package/lib/browser/shell/application-shell.js.map +1 -1
  29. package/lib/browser/shell/tab-bars.d.ts +21 -5
  30. package/lib/browser/shell/tab-bars.d.ts.map +1 -1
  31. package/lib/browser/shell/tab-bars.js +94 -17
  32. package/lib/browser/shell/tab-bars.js.map +1 -1
  33. package/lib/browser/test/jsdom.js +1 -1
  34. package/lib/browser/test/jsdom.js.map +1 -1
  35. package/lib/browser/tree/tree-iterator.js +4 -4
  36. package/lib/browser/tree/tree-iterator.js.map +1 -1
  37. package/lib/browser/tree/tree-selection-state.spec.js +26 -2
  38. package/lib/browser/tree/tree-selection-state.spec.js.map +1 -1
  39. package/lib/common/i18n/localization.d.ts +1 -0
  40. package/lib/common/i18n/localization.d.ts.map +1 -1
  41. package/lib/common/i18n/localization.js +2 -16
  42. package/lib/common/i18n/localization.js.map +1 -1
  43. package/lib/common/nls.d.ts +1 -0
  44. package/lib/common/nls.d.ts.map +1 -1
  45. package/lib/common/nls.js +2 -1
  46. package/lib/common/nls.js.map +1 -1
  47. package/lib/common/quick-pick-service.d.ts +2 -1
  48. package/lib/common/quick-pick-service.d.ts.map +1 -1
  49. package/lib/common/quick-pick-service.js.map +1 -1
  50. package/lib/electron-browser/electron-clipboard-service.d.ts.map +1 -1
  51. package/lib/electron-browser/electron-clipboard-service.js +2 -3
  52. package/lib/electron-browser/electron-clipboard-service.js.map +1 -1
  53. package/lib/electron-browser/keyboard/electron-keyboard-layout-change-notifier.d.ts.map +1 -1
  54. package/lib/electron-browser/keyboard/electron-keyboard-layout-change-notifier.js +1 -2
  55. package/lib/electron-browser/keyboard/electron-keyboard-layout-change-notifier.js.map +1 -1
  56. package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts +2 -3
  57. package/lib/electron-browser/menu/electron-context-menu-renderer.d.ts.map +1 -1
  58. package/lib/electron-browser/menu/electron-context-menu-renderer.js +10 -18
  59. package/lib/electron-browser/menu/electron-context-menu-renderer.js.map +1 -1
  60. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts +10 -8
  61. package/lib/electron-browser/menu/electron-main-menu-factory.d.ts.map +1 -1
  62. package/lib/electron-browser/menu/electron-main-menu-factory.js +33 -32
  63. package/lib/electron-browser/menu/electron-main-menu-factory.js.map +1 -1
  64. package/lib/electron-browser/menu/electron-menu-contribution.d.ts +6 -6
  65. package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
  66. package/lib/electron-browser/menu/electron-menu-contribution.js +39 -54
  67. package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
  68. package/lib/electron-browser/messaging/electron-ipc-connection-provider.d.ts.map +1 -1
  69. package/lib/electron-browser/messaging/electron-ipc-connection-provider.js +2 -6
  70. package/lib/electron-browser/messaging/electron-ipc-connection-provider.js.map +1 -1
  71. package/lib/electron-browser/preload.d.ts +2 -0
  72. package/lib/electron-browser/preload.d.ts.map +1 -0
  73. package/lib/electron-browser/preload.js +183 -0
  74. package/lib/electron-browser/preload.js.map +1 -0
  75. package/lib/electron-browser/token/electron-token-frontend-module.d.ts.map +1 -1
  76. package/lib/electron-browser/token/electron-token-frontend-module.js +1 -2
  77. package/lib/electron-browser/token/electron-token-frontend-module.js.map +1 -1
  78. package/lib/electron-browser/window/electron-frontend-application-state.d.ts.map +1 -1
  79. package/lib/electron-browser/window/electron-frontend-application-state.js +1 -3
  80. package/lib/electron-browser/window/electron-frontend-application-state.js.map +1 -1
  81. package/lib/electron-browser/window/electron-secondary-window-service.d.ts +1 -3
  82. package/lib/electron-browser/window/electron-secondary-window-service.d.ts.map +1 -1
  83. package/lib/electron-browser/window/electron-secondary-window-service.js +6 -34
  84. package/lib/electron-browser/window/electron-secondary-window-service.js.map +1 -1
  85. package/lib/electron-browser/window/electron-window-service.d.ts +1 -8
  86. package/lib/electron-browser/window/electron-window-service.d.ts.map +1 -1
  87. package/lib/electron-browser/window/electron-window-service.js +8 -25
  88. package/lib/electron-browser/window/electron-window-service.js.map +1 -1
  89. package/lib/electron-common/electron-api.d.ts +94 -0
  90. package/lib/electron-common/electron-api.d.ts.map +1 -0
  91. package/lib/electron-common/electron-api.js +53 -0
  92. package/lib/electron-common/electron-api.js.map +1 -0
  93. package/lib/electron-common/messaging/electron-connection-handler.d.ts +0 -7
  94. package/lib/electron-common/messaging/electron-connection-handler.d.ts.map +1 -1
  95. package/lib/electron-common/messaging/electron-connection-handler.js +1 -5
  96. package/lib/electron-common/messaging/electron-connection-handler.js.map +1 -1
  97. package/lib/electron-main/electron-api-main.d.ts +21 -0
  98. package/lib/electron-main/electron-api-main.d.ts.map +1 -0
  99. package/lib/electron-main/electron-api-main.js +261 -0
  100. package/lib/electron-main/electron-api-main.js.map +1 -0
  101. package/lib/electron-main/electron-main-application-module.d.ts.map +1 -1
  102. package/lib/electron-main/electron-main-application-module.js +3 -3
  103. package/lib/electron-main/electron-main-application-module.js.map +1 -1
  104. package/lib/electron-main/electron-main-application.d.ts +8 -2
  105. package/lib/electron-main/electron-main-application.d.ts.map +1 -1
  106. package/lib/electron-main/electron-main-application.js +32 -29
  107. package/lib/electron-main/electron-main-application.js.map +1 -1
  108. package/lib/electron-main/electron-security-token-service.d.ts.map +1 -1
  109. package/lib/electron-main/electron-security-token-service.js +2 -1
  110. package/lib/electron-main/electron-security-token-service.js.map +1 -1
  111. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts +4 -5
  112. package/lib/electron-main/messaging/electron-messaging-contribution.d.ts.map +1 -1
  113. package/lib/electron-main/messaging/electron-messaging-contribution.js +4 -7
  114. package/lib/electron-main/messaging/electron-messaging-contribution.js.map +1 -1
  115. package/lib/electron-main/theia-electron-window.d.ts +2 -4
  116. package/lib/electron-main/theia-electron-window.d.ts.map +1 -1
  117. package/lib/electron-main/theia-electron-window.js +11 -34
  118. package/lib/electron-main/theia-electron-window.js.map +1 -1
  119. package/lib/node/i18n/localization-backend-contribution.d.ts.map +1 -1
  120. package/lib/node/i18n/localization-backend-contribution.js +2 -1
  121. package/lib/node/i18n/localization-backend-contribution.js.map +1 -1
  122. package/lib/node/i18n/localization-provider.d.ts.map +1 -1
  123. package/lib/node/i18n/localization-provider.js +2 -1
  124. package/lib/node/i18n/localization-provider.js.map +1 -1
  125. package/package.json +9 -6
  126. package/src/browser/core-preferences.ts +26 -0
  127. package/src/browser/hover-service.ts +12 -1
  128. package/src/browser/icon-theme-service.ts +1 -1
  129. package/src/browser/shell/application-shell.ts +29 -1
  130. package/src/browser/shell/tab-bars.ts +111 -17
  131. package/src/browser/style/hover-service.css +4 -0
  132. package/src/browser/style/tabs.css +25 -0
  133. package/src/browser/style/tree.css +1 -0
  134. package/src/browser/test/jsdom.ts +1 -1
  135. package/src/browser/tree/tree-iterator.ts +4 -4
  136. package/src/browser/tree/tree-selection-state.spec.ts +29 -2
  137. package/src/common/i18n/localization.ts +6 -16
  138. package/src/common/nls.ts +3 -1
  139. package/src/common/quick-pick-service.ts +2 -1
  140. package/src/electron-browser/electron-clipboard-service.ts +2 -3
  141. package/src/electron-browser/keyboard/electron-keyboard-layout-change-notifier.ts +1 -2
  142. package/src/electron-browser/menu/electron-context-menu-renderer.ts +10 -17
  143. package/src/electron-browser/menu/electron-main-menu-factory.ts +51 -44
  144. package/src/electron-browser/menu/electron-menu-contribution.ts +46 -57
  145. package/src/electron-browser/messaging/electron-ipc-connection-provider.ts +4 -9
  146. package/src/electron-browser/preload.ts +208 -0
  147. package/src/electron-browser/token/electron-token-frontend-module.ts +1 -2
  148. package/src/electron-browser/window/electron-frontend-application-state.ts +1 -3
  149. package/src/electron-browser/window/electron-secondary-window-service.ts +7 -31
  150. package/src/electron-browser/window/electron-window-service.ts +8 -25
  151. package/src/electron-common/electron-api.ts +134 -0
  152. package/src/electron-common/messaging/electron-connection-handler.ts +0 -9
  153. package/src/electron-main/electron-api-main.ts +291 -0
  154. package/src/electron-main/electron-main-application-module.ts +3 -4
  155. package/src/electron-main/electron-main-application.ts +33 -37
  156. package/src/electron-main/electron-security-token-service.ts +2 -1
  157. package/src/electron-main/messaging/electron-messaging-contribution.ts +8 -10
  158. package/src/electron-main/theia-electron-window.ts +8 -33
  159. package/src/node/i18n/localization-backend-contribution.ts +2 -1
  160. package/src/node/i18n/localization-provider.ts +2 -1
  161. package/LICENSE +0 -642
  162. package/electron-shared/@electron/remote/index.d.ts +0 -1
  163. package/electron-shared/@electron/remote/index.js +0 -1
  164. package/electron-shared/@electron/remote/main/index.d.ts +0 -1
  165. package/electron-shared/@electron/remote/main/index.js +0 -1
  166. package/lib/electron-common/messaging/electron-messages.d.ts +0 -25
  167. package/lib/electron-common/messaging/electron-messages.d.ts.map +0 -1
  168. package/lib/electron-common/messaging/electron-messages.js +0 -37
  169. package/lib/electron-common/messaging/electron-messages.js.map +0 -1
  170. package/lib/electron-main/electron-native-keymap.d.ts +0 -8
  171. package/lib/electron-main/electron-native-keymap.d.ts.map +0 -1
  172. package/lib/electron-main/electron-native-keymap.js +0 -48
  173. package/lib/electron-main/electron-native-keymap.js.map +0 -1
  174. package/src/electron-common/messaging/electron-messages.ts +0 -42
  175. package/src/electron-main/electron-native-keymap.ts +0 -40
@@ -16,7 +16,6 @@
16
16
 
17
17
  /* eslint-disable @typescript-eslint/no-explicit-any */
18
18
 
19
- import * as electronRemote from '../../../electron-shared/@electron/remote';
20
19
  import { inject, injectable, postConstruct } from 'inversify';
21
20
  import { isOSX, MAIN_MENU_BAR, MenuPath, MenuNode, CommandMenuNode, CompoundMenuNode, CompoundMenuNodeRole } from '../../common';
22
21
  import { Keybinding } from '../../common/keybinding';
@@ -24,7 +23,8 @@ import { PreferenceService, CommonCommands } from '../../browser';
24
23
  import debounce = require('lodash.debounce');
25
24
  import { MAXIMIZED_CLASS } from '../../browser/shell/theia-dock-panel';
26
25
  import { BrowserMainMenuFactory } from '../../browser/menu/browser-menu-plugin';
27
- import { ContextMatcher } from 'src/browser/context-key-service';
26
+ import { ContextMatcher } from '../../browser/context-key-service';
27
+ import { MenuDto, MenuRole } from '../../electron-common/electron-api';
28
28
 
29
29
  /**
30
30
  * Representation of possible electron menu options.
@@ -68,7 +68,7 @@ export type ElectronMenuItemRole = ('undo' | 'redo' | 'cut' | 'copy' | 'paste' |
68
68
  @injectable()
69
69
  export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
70
70
 
71
- protected _menu?: Electron.Menu;
71
+ protected _menu?: MenuDto[];
72
72
  protected _toggledCommands: Set<string> = new Set();
73
73
 
74
74
  @inject(PreferenceService)
@@ -82,13 +82,13 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
82
82
  this.setMenuBar();
83
83
  }
84
84
  if (this._menu) {
85
- for (const item of this._toggledCommands) {
86
- const menuItem = this._menu.getMenuItemById(item);
85
+ for (const cmd of this._toggledCommands) {
86
+ const menuItem = this.findMenuById(this._menu, cmd);
87
87
  if (menuItem) {
88
- menuItem.checked = this.commandRegistry.isToggled(item);
88
+ menuItem.checked = this.commandRegistry.isToggled(cmd);
89
89
  }
90
90
  }
91
- electronRemote.getCurrentWindow().setMenu(this._menu);
91
+ window.electronTheiaCore.setMenu(this._menu);
92
92
  }
93
93
  }, 10)
94
94
  );
@@ -99,56 +99,49 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
99
99
 
100
100
  async setMenuBar(): Promise<void> {
101
101
  await this.preferencesService.ready;
102
- if (isOSX) {
103
- const createdMenuBar = this.createElectronMenuBar();
104
- electronRemote.Menu.setApplicationMenu(createdMenuBar);
105
- } else if (this.preferencesService.get('window.titleBarStyle') === 'native') {
106
- const createdMenuBar = this.createElectronMenuBar();
107
- electronRemote.getCurrentWindow().setMenu(createdMenuBar);
108
- }
102
+ const createdMenuBar = this.createElectronMenuBar();
103
+ window.electronTheiaCore.setMenu(createdMenuBar);
109
104
  }
110
105
 
111
- createElectronMenuBar(): Electron.Menu | null {
106
+ createElectronMenuBar(): MenuDto[] | undefined {
112
107
  const preference = this.preferencesService.get<string>('window.menuBarVisibility') || 'classic';
113
108
  const maxWidget = document.getElementsByClassName(MAXIMIZED_CLASS);
114
109
  if (preference === 'visible' || (preference === 'classic' && maxWidget.length === 0)) {
115
110
  const menuModel = this.menuProvider.getMenu(MAIN_MENU_BAR);
116
- const template = this.fillMenuTemplate([], menuModel, [], { rootMenuPath: MAIN_MENU_BAR });
111
+ this._menu = this.fillMenuTemplate([], menuModel, [], { rootMenuPath: MAIN_MENU_BAR });
117
112
  if (isOSX) {
118
- template.unshift(this.createOSXMenu());
119
- }
120
- const menu = electronRemote.Menu.buildFromTemplate(template);
121
- if (!menu) {
122
- throw new Error('menu is null');
113
+ this._menu.unshift(this.createOSXMenu());
123
114
  }
124
- this._menu = menu;
125
115
  return this._menu;
126
116
  }
127
117
  this._menu = undefined;
128
118
  // eslint-disable-next-line no-null/no-null
129
- return null;
119
+ return undefined;
130
120
  }
131
121
 
132
- createElectronContextMenu(menuPath: MenuPath, args?: any[], context?: HTMLElement, contextKeyService?: ContextMatcher): Electron.Menu {
122
+ createElectronContextMenu(menuPath: MenuPath, args?: any[], context?: HTMLElement, contextKeyService?: ContextMatcher): MenuDto[] {
133
123
  const menuModel = this.menuProvider.getMenu(menuPath);
134
- const template = this.fillMenuTemplate([], menuModel, args, { showDisabled: false, context, rootMenuPath: menuPath, contextKeyService });
135
- return electronRemote.Menu.buildFromTemplate(template);
124
+ return this.fillMenuTemplate([], menuModel, args, { showDisabled: false, context, rootMenuPath: menuPath, contextKeyService });
136
125
  }
137
126
 
138
- protected fillMenuTemplate(parentItems: Electron.MenuItemConstructorOptions[],
127
+ protected fillMenuTemplate(parentItems: MenuDto[],
139
128
  menu: MenuNode,
140
129
  args: unknown[] = [],
141
130
  options: ElectronMenuOptions
142
- ): Electron.MenuItemConstructorOptions[] {
131
+ ): MenuDto[] {
143
132
  const showDisabled = options?.showDisabled !== false;
144
133
 
145
134
  if (CompoundMenuNode.is(menu) && menu.children.length && this.undefinedOrMatch(options.contextKeyService ?? this.contextKeyService, menu.when, options.context)) {
146
135
  const role = CompoundMenuNode.getRole(menu);
147
- if (role === CompoundMenuNodeRole.Group && menu.id === 'inline') { return parentItems; }
136
+ if (role === CompoundMenuNodeRole.Group && menu.id === 'inline') {
137
+ return parentItems;
138
+ }
148
139
  const children = CompoundMenuNode.getFlatChildren(menu.children);
149
- const myItems: Electron.MenuItemConstructorOptions[] = [];
140
+ const myItems: MenuDto[] = [];
150
141
  children.forEach(child => this.fillMenuTemplate(myItems, child, args, options));
151
- if (myItems.length === 0) { return parentItems; }
142
+ if (myItems.length === 0) {
143
+ return parentItems;
144
+ }
152
145
  if (role === CompoundMenuNodeRole.Submenu) {
153
146
  parentItems.push({ label: menu.label, submenu: myItems });
154
147
  } else if (role === CompoundMenuNodeRole.Group && menu.id !== 'inline') {
@@ -183,7 +176,7 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
183
176
 
184
177
  const accelerator = bindings[0] && this.acceleratorFor(bindings[0]);
185
178
 
186
- const menuItem: Electron.MenuItemConstructorOptions = {
179
+ const menuItem: MenuDto = {
187
180
  id: node.id,
188
181
  label: node.label,
189
182
  type: this.commandRegistry.getToggledHandler(commandId, ...args) ? 'checkbox' : 'normal',
@@ -191,14 +184,14 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
191
184
  enabled: true, // https://github.com/eclipse-theia/theia/issues/446
192
185
  visible: true,
193
186
  accelerator,
194
- click: () => this.execute(commandId, args, options.rootMenuPath)
187
+ execute: () => this.execute(commandId, args, options.rootMenuPath)
195
188
  };
196
189
 
197
190
  if (isOSX) {
198
191
  const role = this.roleFor(node.id);
199
192
  if (role) {
200
193
  menuItem.role = role;
201
- delete menuItem.click;
194
+ delete menuItem.execute;
202
195
  }
203
196
  }
204
197
  parentItems.push(menuItem);
@@ -235,8 +228,8 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
235
228
  return this.keybindingRegistry.acceleratorForKeyCode(keyCode, '+', true);
236
229
  }
237
230
 
238
- protected roleFor(id: string): ElectronMenuItemRole | undefined {
239
- let role: ElectronMenuItemRole | undefined;
231
+ protected roleFor(id: string): MenuRole | undefined {
232
+ let role: MenuRole | undefined;
240
233
  switch (id) {
241
234
  case CommonCommands.UNDO.id:
242
235
  role = 'undo';
@@ -262,18 +255,18 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
262
255
  return role;
263
256
  }
264
257
 
265
- protected async execute(command: string, args: any[], menuPath: MenuPath): Promise<void> {
258
+ protected async execute(cmd: string, args: any[], menuPath: MenuPath): Promise<void> {
266
259
  try {
267
260
  // This is workaround for https://github.com/eclipse-theia/theia/issues/446.
268
261
  // Electron menus do not update based on the `isEnabled`, `isVisible` property of the command.
269
262
  // We need to check if we can execute it.
270
- if (this.menuCommandExecutor.isEnabled(menuPath, command, ...args)) {
271
- await this.menuCommandExecutor.executeCommand(menuPath, command, ...args);
272
- if (this._menu && this.menuCommandExecutor.isVisible(menuPath, command, ...args)) {
273
- const item = this._menu.getMenuItemById(command);
263
+ if (this.menuCommandExecutor.isEnabled(menuPath, cmd, ...args)) {
264
+ await this.menuCommandExecutor.executeCommand(menuPath, cmd, ...args);
265
+ if (this._menu && this.menuCommandExecutor.isVisible(menuPath, cmd, ...args)) {
266
+ const item = this.findMenuById(this._menu, cmd);
274
267
  if (item) {
275
- item.checked = this.menuCommandExecutor.isToggled(menuPath, command, ...args);
276
- electronRemote.getCurrentWindow().setMenu(this._menu);
268
+ item.checked = this.menuCommandExecutor.isToggled(menuPath, cmd, ...args);
269
+ window.electronTheiaCore.setMenu(this._menu);
277
270
  }
278
271
  }
279
272
  }
@@ -281,8 +274,22 @@ export class ElectronMainMenuFactory extends BrowserMainMenuFactory {
281
274
  // no-op
282
275
  }
283
276
  }
277
+ findMenuById(items: MenuDto[], id: string): MenuDto | undefined {
278
+ for (const item of items) {
279
+ if (item.id === id) {
280
+ return item;
281
+ }
282
+ if (item.submenu) {
283
+ const found = this.findMenuById(item.submenu, id);
284
+ if (found) {
285
+ return found;
286
+ }
287
+ }
288
+ }
289
+ return undefined;
290
+ }
284
291
 
285
- protected createOSXMenu(): Electron.MenuItemConstructorOptions {
292
+ protected createOSXMenu(): MenuDto {
286
293
  return {
287
294
  label: 'Theia',
288
295
  submenu: [
@@ -14,8 +14,6 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import * as electron from '../../../electron-shared/electron';
18
- import * as electronRemote from '../../../electron-shared/@electron/remote';
19
17
  import { inject, injectable, postConstruct } from 'inversify';
20
18
  import { Command, CommandContribution, CommandRegistry, isOSX, isWindows, MenuModelRegistry, MenuContribution, Disposable, nls } from '../../common';
21
19
  import {
@@ -25,13 +23,13 @@ import {
25
23
  import { ElectronMainMenuFactory } from './electron-main-menu-factory';
26
24
  import { FrontendApplicationStateService, FrontendApplicationState } from '../../browser/frontend-application-state';
27
25
  import { FrontendApplicationConfigProvider } from '../../browser/frontend-application-config-provider';
28
- import { RequestTitleBarStyle, Restart, TitleBarStyleAtStartup, TitleBarStyleChanged } from '../../electron-common/messaging/electron-messages';
29
26
  import { ZoomLevel } from '../window/electron-window-preferences';
30
27
  import { BrowserMenuBarContribution } from '../../browser/menu/browser-menu-plugin';
31
28
  import { WindowService } from '../../browser/window/window-service';
32
29
  import { WindowTitleService } from '../../browser/window/window-title-service';
33
30
 
34
31
  import '../../../src/electron-browser/menu/electron-menu-style.css';
32
+ import { MenuDto } from '../../electron-common/electron-api';
35
33
 
36
34
  export namespace ElectronCommands {
37
35
  export const TOGGLE_DEVELOPER_TOOLS = Command.toDefaultLocalizedCommand({
@@ -131,38 +129,38 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
131
129
  // OSX: Recreate the menus when changing windows.
132
130
  // OSX only has one menu bar for all windows, so we need to swap
133
131
  // between them as the user switches windows.
134
- const targetWindow = electronRemote.getCurrentWindow();
135
- const callback = () => this.setMenu(app);
136
- targetWindow.on('focus', callback);
137
- window.addEventListener('unload', () => targetWindow.off('focus', callback));
132
+ const disposeHandler = window.electronTheiaCore.onWindowEvent('focus', () => {
133
+ this.setMenu(app);
134
+ });
135
+ window.addEventListener('unload', () => disposeHandler.dispose());
138
136
  }
139
137
 
140
138
  protected attachMenuBarVisibilityListener(): void {
141
139
  this.preferenceService.onPreferenceChanged(e => {
142
140
  if (e.preferenceName === 'window.menuBarVisibility') {
143
- const targetWindow = electronRemote.getCurrentWindow();
144
- this.handleFullScreen(targetWindow, e.newValue);
141
+ this.handleFullScreen(e.newValue);
145
142
  }
146
143
  });
147
144
  }
148
145
 
149
146
  handleTitleBarStyling(app: FrontendApplication): void {
150
147
  this.hideTopPanel(app);
151
- electron.ipcRenderer.on(TitleBarStyleAtStartup, (_event, style: string) => {
148
+ window.electronTheiaCore.getTitleBarStyleAtStartup().then(style => {
152
149
  this.titleBarStyle = style;
153
150
  this.setMenu(app);
154
151
  this.preferenceService.ready.then(() => {
155
152
  this.preferenceService.set('window.titleBarStyle', this.titleBarStyle, PreferenceScope.User);
156
153
  });
157
154
  });
158
- electron.ipcRenderer.send(RequestTitleBarStyle);
155
+
159
156
  this.preferenceService.ready.then(() => {
160
- electronRemote.getCurrentWindow().setMenuBarVisibility(['classic', 'visible'].includes(this.preferenceService.get('window.menuBarVisibility', 'classic')));
157
+ window.electronTheiaCore.setMenuBarVisible(['classic', 'visible'].includes(this.preferenceService.get('window.menuBarVisibility', 'classic')));
161
158
  });
159
+
162
160
  this.preferenceService.onPreferenceChanged(change => {
163
161
  if (change.preferenceName === 'window.titleBarStyle') {
164
- if (this.titleBarStyleChangeFlag && this.titleBarStyle !== change.newValue && electronRemote.getCurrentWindow().isFocused()) {
165
- electron.ipcRenderer.send(TitleBarStyleChanged, change.newValue);
162
+ if (this.titleBarStyleChangeFlag && this.titleBarStyle !== change.newValue) {
163
+ window.electronTheiaCore.setTitleBarStyle(change.newValue);
166
164
  this.handleRequiredRestart();
167
165
  }
168
166
  this.titleBarStyleChangeFlag = true;
@@ -197,21 +195,18 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
197
195
  }
198
196
  }
199
197
 
200
- protected setMenu(app: FrontendApplication, electronMenu: electron.Menu | null = this.factory.createElectronMenuBar(),
201
- electronWindow: electron.BrowserWindow = electronRemote.getCurrentWindow()): void {
202
- if (isOSX) {
203
- electronRemote.Menu.setApplicationMenu(electronMenu);
204
- } else {
198
+ protected setMenu(app: FrontendApplication, electronMenu: MenuDto[] | undefined = this.factory.createElectronMenuBar()): void {
199
+ if (!isOSX) {
205
200
  this.hideTopPanel(app);
206
201
  if (this.titleBarStyle === 'custom' && !this.menuBar) {
207
- this.createCustomTitleBar(app, electronWindow);
202
+ this.createCustomTitleBar(app);
203
+ return;
208
204
  }
209
- // Unix/Windows: Set the per-window menus
210
- electronWindow.setMenu(electronMenu);
211
205
  }
206
+ window.electronTheiaCore.setMenu(electronMenu);
212
207
  }
213
208
 
214
- protected createCustomTitleBar(app: FrontendApplication, electronWindow: electron.BrowserWindow): void {
209
+ protected createCustomTitleBar(app: FrontendApplication): void {
215
210
  const dragPanel = new Widget();
216
211
  dragPanel.id = 'theia-drag-panel';
217
212
  app.shell.addWidget(dragPanel, { area: 'top' });
@@ -220,13 +215,13 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
220
215
  const controls = document.createElement('div');
221
216
  controls.id = 'window-controls';
222
217
  controls.append(
223
- this.createControlButton('minimize', () => electronWindow.minimize()),
224
- this.createControlButton('maximize', () => electronWindow.maximize()),
225
- this.createControlButton('restore', () => electronWindow.unmaximize()),
226
- this.createControlButton('close', () => electronWindow.close())
218
+ this.createControlButton('minimize', () => window.electronTheiaCore.minimize()),
219
+ this.createControlButton('maximize', () => window.electronTheiaCore.maximize()),
220
+ this.createControlButton('restore', () => window.electronTheiaCore.unMaximize()),
221
+ this.createControlButton('close', () => window.electronTheiaCore.close())
227
222
  );
228
223
  app.shell.topPanel.node.append(controls);
229
- this.handleWindowControls(electronWindow);
224
+ this.handleWindowControls();
230
225
  }
231
226
 
232
227
  protected createCustomTitleWidget(app: FrontendApplication): void {
@@ -236,13 +231,13 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
236
231
  }
237
232
  }
238
233
 
239
- protected handleWindowControls(electronWindow: electron.BrowserWindow): void {
234
+ protected handleWindowControls(): void {
240
235
  toggleControlButtons();
241
- electronWindow.on('maximize', toggleControlButtons);
242
- electronWindow.on('unmaximize', toggleControlButtons);
236
+ window.electronTheiaCore.onWindowEvent('maximize', toggleControlButtons);
237
+ window.electronTheiaCore.onWindowEvent('unmaximize', toggleControlButtons);
243
238
 
244
239
  function toggleControlButtons(): void {
245
- if (electronWindow.isMaximized()) {
240
+ if (window.electronTheiaCore.isMaximized()) {
246
241
  document.body.classList.add('maximized');
247
242
  } else {
248
243
  document.body.classList.remove('maximized');
@@ -275,22 +270,15 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
275
270
  });
276
271
  if (await dialog.open()) {
277
272
  this.windowService.setSafeToShutDown();
278
- electron.ipcRenderer.send(Restart);
273
+ window.electronTheiaCore.restart();
279
274
  }
280
275
  }
281
276
 
282
277
  registerCommands(registry: CommandRegistry): void {
283
278
 
284
- const currentWindow = electronRemote.getCurrentWindow();
285
-
286
279
  registry.registerCommand(ElectronCommands.TOGGLE_DEVELOPER_TOOLS, {
287
280
  execute: () => {
288
- const webContent = electronRemote.getCurrentWebContents();
289
- if (!webContent.isDevToolsOpened()) {
290
- webContent.openDevTools();
291
- } else {
292
- webContent.closeDevTools();
293
- }
281
+ window.electronTheiaCore.toggleDevTools();
294
282
  }
295
283
  });
296
284
 
@@ -298,14 +286,14 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
298
286
  execute: () => this.windowService.reload()
299
287
  });
300
288
  registry.registerCommand(ElectronCommands.CLOSE_WINDOW, {
301
- execute: () => currentWindow.close()
289
+ execute: () => window.electronTheiaCore.close()
302
290
  });
303
291
 
304
292
  registry.registerCommand(ElectronCommands.ZOOM_IN, {
305
- execute: () => {
306
- const webContents = currentWindow.webContents;
293
+ execute: async () => {
294
+ const currentLevel = await window.electronTheiaCore.getZoomLevel();
307
295
  // When starting at a level that is not a multiple of 0.5, increment by at most 0.5 to reach the next highest multiple of 0.5.
308
- let zoomLevel = (Math.floor(webContents.zoomLevel / ZoomLevel.VARIATION) * ZoomLevel.VARIATION) + ZoomLevel.VARIATION;
296
+ let zoomLevel = (Math.floor(currentLevel / ZoomLevel.VARIATION) * ZoomLevel.VARIATION) + ZoomLevel.VARIATION;
309
297
  if (zoomLevel > ZoomLevel.MAX) {
310
298
  zoomLevel = ZoomLevel.MAX;
311
299
  return;
@@ -314,10 +302,10 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
314
302
  }
315
303
  });
316
304
  registry.registerCommand(ElectronCommands.ZOOM_OUT, {
317
- execute: () => {
318
- const webContents = currentWindow.webContents;
305
+ execute: async () => {
306
+ const currentLevel = await window.electronTheiaCore.getZoomLevel();
319
307
  // When starting at a level that is not a multiple of 0.5, decrement by at most 0.5 to reach the next lowest multiple of 0.5.
320
- let zoomLevel = (Math.ceil(webContents.zoomLevel / ZoomLevel.VARIATION) * ZoomLevel.VARIATION) - ZoomLevel.VARIATION;
308
+ let zoomLevel = (Math.ceil(currentLevel / ZoomLevel.VARIATION) * ZoomLevel.VARIATION) - ZoomLevel.VARIATION;
321
309
  if (zoomLevel < ZoomLevel.MIN) {
322
310
  zoomLevel = ZoomLevel.MIN;
323
311
  return;
@@ -328,10 +316,11 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
328
316
  registry.registerCommand(ElectronCommands.RESET_ZOOM, {
329
317
  execute: () => this.preferenceService.set('window.zoomLevel', ZoomLevel.DEFAULT, PreferenceScope.User)
330
318
  });
319
+
331
320
  registry.registerCommand(ElectronCommands.TOGGLE_FULL_SCREEN, {
332
- isEnabled: () => currentWindow.isFullScreenable(),
333
- isVisible: () => currentWindow.isFullScreenable(),
334
- execute: () => this.toggleFullScreen(currentWindow)
321
+ isEnabled: () => window.electronTheiaCore.isFullScreenable(),
322
+ isVisible: () => window.electronTheiaCore.isFullScreenable(),
323
+ execute: () => this.toggleFullScreen()
335
324
  });
336
325
  }
337
326
 
@@ -408,16 +397,16 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
408
397
  });
409
398
  }
410
399
 
411
- protected toggleFullScreen(currentWindow: electron.BrowserWindow): void {
412
- currentWindow.setFullScreen(!currentWindow.isFullScreen());
400
+ protected toggleFullScreen(): void {
401
+ window.electronTheiaCore.toggleFullScreen();
413
402
  const menuBarVisibility = this.preferenceService.get('window.menuBarVisibility', 'classic');
414
- this.handleFullScreen(currentWindow, menuBarVisibility);
403
+ this.handleFullScreen(menuBarVisibility);
415
404
  }
416
405
 
417
- protected handleFullScreen(currentWindow: electron.BrowserWindow, menuBarVisibility: string): void {
418
- const shouldShowTop = !currentWindow.isFullScreen() || menuBarVisibility === 'visible';
406
+ protected handleFullScreen(menuBarVisibility: string): void {
407
+ const shouldShowTop = !window.electronTheiaCore.isFullScreen() || menuBarVisibility === 'visible';
419
408
  if (this.titleBarStyle === 'native') {
420
- currentWindow.menuBarVisible = shouldShowTop;
409
+ window.electronTheiaCore.setMenuBarVisible(shouldShowTop);
421
410
  } else if (shouldShowTop) {
422
411
  this.shell.topPanel.show();
423
412
  } else {
@@ -14,12 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { Event as ElectronEvent, ipcRenderer } from '@theia/electron/shared/electron';
18
17
  import { injectable, interfaces } from 'inversify';
19
18
  import { JsonRpcProxy } from '../../common/messaging';
20
19
  import { AbstractConnectionProvider } from '../../common/messaging/abstract-connection-provider';
21
- import { THEIA_ELECTRON_IPC_CHANNEL_NAME } from '../../electron-common/messaging/electron-connection-handler';
22
- import { AbstractChannel, Channel, Disposable, WriteBuffer } from '../../common';
20
+ import { AbstractChannel, Channel, WriteBuffer } from '../../common';
23
21
  import { Uint8ArrayReadBuffer, Uint8ArrayWriteBuffer } from '../../common/message-rpc/uint8-array-message-buffer';
24
22
 
25
23
  export interface ElectronIpcOptions {
@@ -50,16 +48,13 @@ export class ElectronIpcRendererChannel extends AbstractChannel {
50
48
 
51
49
  constructor() {
52
50
  super();
53
- const ipcMessageHandler = (_event: ElectronEvent, data: Uint8Array) => this.onMessageEmitter.fire(() => new Uint8ArrayReadBuffer(data));
54
- ipcRenderer.on(THEIA_ELECTRON_IPC_CHANNEL_NAME, ipcMessageHandler);
55
- this.toDispose.push(Disposable.create(() => ipcRenderer.removeListener(THEIA_ELECTRON_IPC_CHANNEL_NAME, ipcMessageHandler)));
51
+ this.toDispose.push(window.electronTheiaCore.onData(data => this.onMessageEmitter.fire(() => new Uint8ArrayReadBuffer(data))));
52
+
56
53
  }
57
54
 
58
55
  getWriteBuffer(): WriteBuffer {
59
56
  const writer = new Uint8ArrayWriteBuffer();
60
- writer.onCommit(buffer =>
61
- ipcRenderer.send(THEIA_ELECTRON_IPC_CHANNEL_NAME, buffer)
62
- );
57
+ writer.onCommit(buffer => window.electronTheiaCore.sendData(buffer));
63
58
  return writer;
64
59
  }
65
60