@theia/core 1.37.0-next.9 → 1.38.0-next.0

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
@@ -0,0 +1,208 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ //
16
+ import { Disposable } from '../common/disposable';
17
+ import { StopReason } from '../common/frontend-application-state';
18
+ import { NativeKeyboardLayout } from '../common/keyboard/keyboard-layout-provider';
19
+ import {
20
+ CHANNEL_ATTACH_SECURITY_TOKEN,
21
+ CHANNEL_FOCUS_WINDOW, CHANNEL_GET_SECURITY_TOKEN, CHANNEL_INVOKE_MENU, CHANNEL_SET_MENU, CHANNEL_OPEN_POPUP, CHANNEL_CLOSE_POPUP,
22
+ MenuDto, TheiaCoreAPI, CHANNEL_ON_CLOSE_POPUP, CHANNEL_GET_TITLE_STYLE_AT_STARTUP, WindowEvent,
23
+ CHANNEL_MINIMIZE, CHANNEL_IS_MAXIMIZED, CHANNEL_MAXIMIZE, CHANNEL_UNMAXIMIZE, CHANNEL_CLOSE, CHANNEL_TOGGLE_DEVTOOLS,
24
+ CHANNEL_ON_WINDOW_EVENT, CHANNEL_GET_ZOOM_LEVEL, CHANNEL_SET_ZOOM_LEVEL, CHANNEL_IS_FULL_SCREENABLE, CHANNEL_TOGGLE_FULL_SCREEN,
25
+ CHANNEL_IS_FULL_SCREEN, CHANNEL_SET_MENU_BAR_VISIBLE, CHANNEL_REQUEST_CLOSE, CHANNEL_SET_TITLE_STYLE, CHANNEL_RESTART,
26
+ CHANNEL_REQUEST_RELOAD, CHANNEL_APP_STATE_CHANGED, CHANNEL_SHOW_ITEM_IN_FOLDER, CHANNEL_READ_CLIPBOARD, CHANNEL_WRITE_CLIPBOARD,
27
+ CHANNEL_KEYBOARD_LAYOUT_CHANGED, CHANNEL_IPC_CONNECTION, InternalMenuDto
28
+ } from '../electron-common/electron-api';
29
+
30
+ // eslint-disable-next-line import/no-extraneous-dependencies
31
+ const { ipcRenderer, contextBridge } = require('electron');
32
+
33
+ // a map of menuId => map<handler id => handler>
34
+ const commandHandlers = new Map<number, Map<number, () => void>>();
35
+ let nextHandlerId = 0;
36
+ const mainMenuId = 0;
37
+ let nextMenuId = mainMenuId + 1;
38
+
39
+ function convertMenu(menu: MenuDto[] | undefined, handlerMap: Map<number, () => void>): InternalMenuDto[] | undefined {
40
+ if (!menu) {
41
+ return undefined;
42
+ }
43
+
44
+ return menu.map(item => {
45
+ let handlerId = undefined;
46
+ if (item.execute) {
47
+ handlerId = nextHandlerId++;
48
+ handlerMap.set(handlerId, item.execute);
49
+ }
50
+
51
+ return {
52
+ id: item.id,
53
+ submenu: convertMenu(item.submenu, handlerMap),
54
+ accelerator: item.accelerator,
55
+ label: item.label,
56
+ handlerId: handlerId,
57
+ checked: item.checked,
58
+ enabled: item.enabled,
59
+ role: item.role,
60
+ type: item.type,
61
+ visible: item.visible
62
+ };
63
+ });
64
+ }
65
+
66
+ const api: TheiaCoreAPI = {
67
+ setMenuBarVisible: (visible: boolean, windowName?: string) => ipcRenderer.send(CHANNEL_SET_MENU_BAR_VISIBLE, visible, windowName),
68
+ setMenu: (menu: MenuDto[] | undefined) => {
69
+ commandHandlers.delete(mainMenuId);
70
+ const handlers = new Map<number, () => void>();
71
+ commandHandlers.set(mainMenuId, handlers);
72
+ ipcRenderer.send(CHANNEL_SET_MENU, mainMenuId, convertMenu(menu, handlers));
73
+ },
74
+ getSecurityToken: () => ipcRenderer.invoke(CHANNEL_GET_SECURITY_TOKEN),
75
+ focusWindow: (name: string) => ipcRenderer.send(CHANNEL_FOCUS_WINDOW, name),
76
+ showItemInFolder: fsPath => {
77
+ ipcRenderer.send(CHANNEL_SHOW_ITEM_IN_FOLDER, fsPath);
78
+ },
79
+ attachSecurityToken: (endpoint: string) => ipcRenderer.invoke(CHANNEL_ATTACH_SECURITY_TOKEN, endpoint),
80
+
81
+ popup: async function (menu: MenuDto[], x: number, y: number, onClosed: () => void): Promise<number> {
82
+ const menuId = nextMenuId++;
83
+ const handlers = new Map<number, () => void>();
84
+ commandHandlers.set(menuId, handlers);
85
+ const handle = await ipcRenderer.invoke(CHANNEL_OPEN_POPUP, menuId, convertMenu(menu, handlers), x, y);
86
+ const closeListener = () => {
87
+ ipcRenderer.removeListener(CHANNEL_ON_CLOSE_POPUP, closeListener);
88
+ commandHandlers.delete(menuId);
89
+ onClosed();
90
+ };
91
+ ipcRenderer.on(CHANNEL_ON_CLOSE_POPUP, closeListener);
92
+ return handle;
93
+ },
94
+ closePopup: function (handle: number): void {
95
+ ipcRenderer.send(CHANNEL_CLOSE_POPUP, handle);
96
+ },
97
+ getTitleBarStyleAtStartup: function (): Promise<string> {
98
+ return ipcRenderer.invoke(CHANNEL_GET_TITLE_STYLE_AT_STARTUP);
99
+ },
100
+ setTitleBarStyle: function (style): void {
101
+ ipcRenderer.send(CHANNEL_SET_TITLE_STYLE, style);
102
+ },
103
+ minimize: function (): void {
104
+ ipcRenderer.send(CHANNEL_MINIMIZE);
105
+ },
106
+ isMaximized: function (): boolean {
107
+ return ipcRenderer.sendSync(CHANNEL_IS_MAXIMIZED);
108
+ },
109
+ maximize: function (): void {
110
+ ipcRenderer.send(CHANNEL_MAXIMIZE);
111
+ },
112
+ unMaximize: function (): void {
113
+ ipcRenderer.send(CHANNEL_UNMAXIMIZE);
114
+ },
115
+ close: function (): void {
116
+ ipcRenderer.send(CHANNEL_CLOSE);
117
+ },
118
+ onWindowEvent: function (event: WindowEvent, handler: () => void): Disposable {
119
+ const h = (_event: unknown, evt: WindowEvent) => {
120
+ if (event === evt) {
121
+ handler();
122
+ }
123
+ };
124
+ ipcRenderer.on(CHANNEL_ON_WINDOW_EVENT, h);
125
+ return Disposable.create(() => ipcRenderer.off(CHANNEL_ON_WINDOW_EVENT, h));
126
+ },
127
+ setCloseRequestHandler: function (handler: (stopReason: StopReason) => Promise<boolean>): void {
128
+ ipcRenderer.on(CHANNEL_REQUEST_CLOSE, async (event, stopReason, confirmChannel, cancelChannel) => {
129
+ try {
130
+ if (await handler(stopReason)) {
131
+ event.sender.send(confirmChannel);
132
+ return;
133
+ };
134
+ } catch (e) {
135
+ console.warn('exception in close handler ', e);
136
+ }
137
+ event.sender.send(cancelChannel);
138
+ });
139
+ },
140
+
141
+ toggleDevTools: function (): void {
142
+ ipcRenderer.send(CHANNEL_TOGGLE_DEVTOOLS);
143
+ },
144
+ getZoomLevel: function (): Promise<number> {
145
+ return ipcRenderer.invoke(CHANNEL_GET_ZOOM_LEVEL);
146
+ },
147
+
148
+ setZoomLevel: function (desired: number): void {
149
+ ipcRenderer.send(CHANNEL_SET_ZOOM_LEVEL, desired);
150
+ },
151
+ isFullScreenable: function (): boolean {
152
+ return ipcRenderer.sendSync(CHANNEL_IS_FULL_SCREENABLE);
153
+ },
154
+
155
+ isFullScreen: function (): boolean {
156
+ return ipcRenderer.sendSync(CHANNEL_IS_FULL_SCREEN);
157
+
158
+ },
159
+ toggleFullScreen: function (): void {
160
+ ipcRenderer.send(CHANNEL_TOGGLE_FULL_SCREEN);
161
+ },
162
+
163
+ requestReload: () => ipcRenderer.send(CHANNEL_REQUEST_RELOAD),
164
+ restart: () => ipcRenderer.send(CHANNEL_RESTART),
165
+
166
+ applicationStateChanged: state => {
167
+ ipcRenderer.send(CHANNEL_APP_STATE_CHANGED, state);
168
+ },
169
+
170
+ readClipboard(): string {
171
+ return ipcRenderer.sendSync(CHANNEL_READ_CLIPBOARD);
172
+ },
173
+
174
+ writeClipboard(text): void {
175
+ ipcRenderer.send(CHANNEL_WRITE_CLIPBOARD, text);
176
+ },
177
+
178
+ onKeyboardLayoutChanged(handler): Disposable {
179
+ return createDisposableListener(CHANNEL_KEYBOARD_LAYOUT_CHANGED, (event, layout) => { handler(layout as NativeKeyboardLayout); });
180
+ },
181
+
182
+ onData: handler => createDisposableListener(CHANNEL_IPC_CONNECTION, (event, data) => { handler(data as Uint8Array); }),
183
+
184
+ sendData: data => {
185
+ ipcRenderer.send(CHANNEL_IPC_CONNECTION, data);
186
+ },
187
+ };
188
+
189
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
+ function createDisposableListener(channel: string, handler: (event: any, ...args: unknown[]) => any): Disposable {
191
+ ipcRenderer.on(channel, handler);
192
+ return Disposable.create(() => ipcRenderer.off(channel, handler));
193
+ }
194
+
195
+ export function preload(): void {
196
+ console.log('exposing theia core electron api');
197
+ ipcRenderer.on(CHANNEL_INVOKE_MENU, (_, menuId: number, handlerId: number) => {
198
+ const map = commandHandlers.get(menuId);
199
+ if (map) {
200
+ const handler = map.get(handlerId);
201
+ if (handler) {
202
+ handler();
203
+ }
204
+ }
205
+ });
206
+
207
+ contextBridge.exposeInMainWorld('electronTheiaCore', api);
208
+ }
@@ -14,10 +14,9 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import * as electronRemote from '../../../electron-shared/@electron/remote';
18
17
  import { ContainerModule } from 'inversify';
19
18
  import { ElectronSecurityToken } from '../../electron-common/electron-token';
20
19
 
21
20
  export default new ContainerModule(bind => {
22
- bind(ElectronSecurityToken).toConstantValue(electronRemote.getGlobal(ElectronSecurityToken));
21
+ bind(ElectronSecurityToken).toConstantValue(window.electronTheiaCore.getSecurityToken());
23
22
  });
@@ -14,15 +14,13 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { ipcRenderer } from '../../../electron-shared/electron';
18
17
  import { injectable } from 'inversify';
19
- import { APPLICATION_STATE_CHANGE_SIGNAL } from '../../electron-common/messaging/electron-messages';
20
18
  import { FrontendApplicationState, FrontendApplicationStateService } from '../../browser/frontend-application-state';
21
19
 
22
20
  @injectable()
23
21
  export class ElectronFrontendApplicationStateService extends FrontendApplicationStateService {
24
22
  protected override doSetState(state: FrontendApplicationState): void {
25
23
  super.doSetState(state);
26
- ipcRenderer.send(APPLICATION_STATE_CHANGE_SIGNAL, state);
24
+ window.electronTheiaCore.applicationStateChanged(state);
27
25
  }
28
26
  }
@@ -14,44 +14,20 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { BrowserWindow } from '../../../electron-shared/electron';
18
- import * as electronRemote from '../../../electron-shared/@electron/remote';
19
17
  import { injectable } from 'inversify';
20
18
  import { DefaultSecondaryWindowService } from '../../browser/window/default-secondary-window-service';
21
19
 
22
20
  @injectable()
23
21
  export class ElectronSecondaryWindowService extends DefaultSecondaryWindowService {
24
- protected electronWindows: Map<string, BrowserWindow> = new Map();
25
-
26
- protected override doCreateSecondaryWindow(onClose?: (closedWin: Window) => void): Window | undefined {
27
- const id = this.nextWindowId();
28
- electronRemote.getCurrentWindow().webContents.once('did-create-window', newElectronWindow => {
29
- newElectronWindow.setMenuBarVisibility(false);
30
- this.electronWindows.set(id, newElectronWindow);
31
- newElectronWindow.on('closed', () => {
32
- this.electronWindows.delete(id);
33
- const browserWin = this.secondaryWindows.find(w => w.name === id);
34
- if (browserWin) {
35
- this.handleWindowClosed(browserWin, onClose);
36
- } else {
37
- console.warn(`Could not execute proper close handling for secondary window '${id}' because its frontend window could not be found.`);
38
- };
39
- });
40
- });
41
- const win = window.open(DefaultSecondaryWindowService.SECONDARY_WINDOW_URL, id);
42
- return win ?? undefined;
22
+ override focus(win: Window): void {
23
+ window.electronTheiaCore.focusWindow(win.name);
43
24
  }
44
25
 
45
- override focus(win: Window): void {
46
- // window.name is the target name given to the window.open call as the second parameter.
47
- const electronWindow = this.electronWindows.get(win.name);
48
- if (electronWindow) {
49
- if (electronWindow.isMinimized()) {
50
- electronWindow.restore();
51
- }
52
- electronWindow.focus();
53
- } else {
54
- console.warn(`There is no known secondary window '${win.name}'. Thus, the window could not be focussed.`);
26
+ protected override doCreateSecondaryWindow(onClose?: (closedWin: Window) => void): Window | undefined {
27
+ const w = super.doCreateSecondaryWindow(onClose);
28
+ if (w) {
29
+ window.electronTheiaCore.setMenuBarVisible(false, w.name);
55
30
  }
31
+ return w;
56
32
  }
57
33
  }
@@ -14,14 +14,11 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import * as electronRemote from '../../../electron-shared/@electron/remote';
18
17
  import { injectable, inject, postConstruct } from 'inversify';
19
- import * as electron from '../../../electron-shared/electron';
20
18
  import { NewWindowOptions } from '../../common/window';
21
19
  import { DefaultWindowService } from '../../browser/window/default-window-service';
22
20
  import { ElectronMainWindowService } from '../../electron-common/electron-main-window-service';
23
21
  import { ElectronWindowPreferences } from './electron-window-preferences';
24
- import { CloseRequestArguments, CLOSE_REQUESTED_SIGNAL, RELOAD_REQUESTED_SIGNAL, StopReason } from '../../electron-common/messaging/electron-messages';
25
22
 
26
23
  @injectable()
27
24
  export class ElectronWindowService extends DefaultWindowService {
@@ -62,37 +59,23 @@ export class ElectronWindowService extends DefaultWindowService {
62
59
  }
63
60
 
64
61
  protected override registerUnloadListeners(): void {
65
- electron.ipcRenderer.on(CLOSE_REQUESTED_SIGNAL, (_event, closeRequestEvent: CloseRequestArguments) => this.handleCloseRequestedEvent(closeRequestEvent));
66
- window.addEventListener('unload', () => this.onUnloadEmitter.fire());
67
- }
68
-
69
- /**
70
- * Run when ElectronMain detects a `close` event and emits a `close-requested` event.
71
- * Should send an event to `electron.ipcRenderer` on the event's `confirmChannel` if it is safe to exit
72
- * after running FrontendApplication `onWillStop` handlers or on the `cancelChannel` if it is not safe to exit.
73
- */
74
- protected async handleCloseRequestedEvent(event: CloseRequestArguments): Promise<void> {
75
- const safeToClose = await this.isSafeToShutDown(event.reason);
76
- if (safeToClose) {
77
- console.debug(`Shutting down because of ${StopReason[event.reason]} request.`);
78
- electron.ipcRenderer.send(event.confirmChannel);
79
- } else {
80
- electron.ipcRenderer.send(event.cancelChannel);
81
- }
62
+ window.electronTheiaCore.setCloseRequestHandler(reason => this.isSafeToShutDown(reason));
63
+ window.addEventListener('unload', () => {
64
+ this.onUnloadEmitter.fire();
65
+ });
82
66
  }
83
67
 
84
68
  /**
85
69
  * Updates the window zoom level based on the preference value.
86
70
  */
87
- protected updateWindowZoomLevel(): void {
71
+ protected async updateWindowZoomLevel(): Promise<void> {
88
72
  const preferredZoomLevel = this.electronWindowPreferences['window.zoomLevel'];
89
- const webContents = electronRemote.getCurrentWindow().webContents;
90
- if (webContents.getZoomLevel() !== preferredZoomLevel) {
91
- webContents.setZoomLevel(preferredZoomLevel);
73
+ if (await window.electronTheiaCore.getZoomLevel() !== preferredZoomLevel) {
74
+ window.electronTheiaCore.setZoomLevel(preferredZoomLevel);
92
75
  }
93
76
  }
94
77
 
95
78
  override reload(): void {
96
- electron.ipcRenderer.send(RELOAD_REQUESTED_SIGNAL);
79
+ window.electronTheiaCore.requestReload();
97
80
  }
98
81
  }
@@ -0,0 +1,134 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { NativeKeyboardLayout } from '../common/keyboard/keyboard-layout-provider';
18
+ import { Disposable } from '../common';
19
+ import { FrontendApplicationState, StopReason } from '../common/frontend-application-state';
20
+
21
+ export type MenuRole = ('undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'selectAll' | 'about' | 'services' | 'hide' | 'hideOthers' | 'unhide' | 'quit');
22
+
23
+ export interface MenuDto {
24
+ id?: string,
25
+ label?: string,
26
+ submenu?: MenuDto[],
27
+ type?: ('normal' | 'separator' | 'submenu' | 'checkbox' | 'radio');
28
+ checked?: boolean,
29
+ enabled?: boolean,
30
+ visible?: boolean;
31
+ role?: MenuRole;
32
+ accelerator?: string,
33
+ execute?: () => void
34
+ }
35
+
36
+ export type InternalMenuDto = Omit<MenuDto, 'execute' | 'submenu'> & {
37
+ submenu?: InternalMenuDto[],
38
+ handlerId?: number
39
+ };
40
+
41
+ export type WindowEvent = 'maximize' | 'unmaximize' | 'focus';
42
+
43
+ export interface TheiaCoreAPI {
44
+ getSecurityToken: () => Promise<string>;
45
+ attachSecurityToken: (endpoint: string) => Promise<void>;
46
+
47
+ setMenuBarVisible(visible: boolean, windowName?: string): void;
48
+ setMenu(menu: MenuDto[] | undefined): void;
49
+
50
+ popup(menu: MenuDto[], x: number, y: number, onClosed: () => void): Promise<number>;
51
+ closePopup(handle: number): void;
52
+
53
+ focusWindow(name: string): void;
54
+
55
+ showItemInFolder(fsPath: string): void;
56
+
57
+ getTitleBarStyleAtStartup(): Promise<string>;
58
+ setTitleBarStyle(style: string): void;
59
+ minimize(): void;
60
+ isMaximized(): boolean; // TODO: this should really be async, since it blocks the renderer process
61
+ maximize(): void;
62
+ unMaximize(): void;
63
+ close(): void;
64
+ onWindowEvent(event: WindowEvent, handler: () => void): Disposable;
65
+ setCloseRequestHandler(handler: (reason: StopReason) => Promise<boolean>): void;
66
+
67
+ toggleDevTools(): void;
68
+ getZoomLevel(): Promise<number>;
69
+ setZoomLevel(desired: number): void;
70
+
71
+ isFullScreenable(): boolean; // TODO: this should really be async, since it blocks the renderer process
72
+ isFullScreen(): boolean; // TODO: this should really be async, since it blocks the renderer process
73
+ toggleFullScreen(): void;
74
+
75
+ requestReload(): void;
76
+ restart(): void;
77
+
78
+ applicationStateChanged(state: FrontendApplicationState): void;
79
+
80
+ readClipboard(): string;
81
+ writeClipboard(text: string): void;
82
+
83
+ onKeyboardLayoutChanged(handler: (newLayout: NativeKeyboardLayout) => void): Disposable;
84
+
85
+ sendData(data: Uint8Array): void;
86
+ onData(handler: (data: Uint8Array) => void): Disposable;
87
+ }
88
+
89
+ declare global {
90
+ interface Window {
91
+ electronTheiaCore: TheiaCoreAPI
92
+ }
93
+ }
94
+
95
+ export const CHANNEL_SET_MENU = 'SetMenu';
96
+ export const CHANNEL_SET_MENU_BAR_VISIBLE = 'SetMenuBarVisible';
97
+ export const CHANNEL_INVOKE_MENU = 'InvokeMenu';
98
+ export const CHANNEL_OPEN_POPUP = 'OpenPopup';
99
+ export const CHANNEL_ON_CLOSE_POPUP = 'OnClosePopup';
100
+ export const CHANNEL_CLOSE_POPUP = 'ClosePopup';
101
+ export const CHANNEL_GET_SECURITY_TOKEN = 'GetSecurityToken';
102
+ export const CHANNEL_FOCUS_WINDOW = 'FocusWindow';
103
+ export const CHANNEL_SHOW_OPEN = 'ShowOpenDialog';
104
+ export const CHANNEL_SHOW_SAVE = 'ShowSaveDialog';
105
+ export const CHANNEL_SHOW_ITEM_IN_FOLDER = 'ShowItemInFolder';
106
+ export const CHANNEL_ATTACH_SECURITY_TOKEN = 'AttachSecurityToken';
107
+
108
+ export const CHANNEL_GET_TITLE_STYLE_AT_STARTUP = 'GetTitleStyleAtStartup';
109
+ export const CHANNEL_SET_TITLE_STYLE = 'SetTitleStyle';
110
+ export const CHANNEL_CLOSE = 'Close';
111
+ export const CHANNEL_MINIMIZE = 'Minimize';
112
+ export const CHANNEL_MAXIMIZE = 'Maximize';
113
+ export const CHANNEL_IS_MAXIMIZED = 'IsMaximized';
114
+
115
+ export const CHANNEL_UNMAXIMIZE = 'UnMaximize';
116
+ export const CHANNEL_ON_WINDOW_EVENT = 'OnWindowEvent';
117
+ export const CHANNEL_TOGGLE_DEVTOOLS = 'ToggleDevtools';
118
+ export const CHANNEL_GET_ZOOM_LEVEL = 'GetZoomLevel';
119
+ export const CHANNEL_SET_ZOOM_LEVEL = 'SetZoomLevel';
120
+ export const CHANNEL_IS_FULL_SCREENABLE = 'IsFullScreenable';
121
+ export const CHANNEL_IS_FULL_SCREEN = 'IsFullScreen';
122
+ export const CHANNEL_TOGGLE_FULL_SCREEN = 'ToggleFullScreen';
123
+
124
+ export const CHANNEL_REQUEST_CLOSE = 'RequestClose';
125
+ export const CHANNEL_REQUEST_RELOAD = 'RequestReload';
126
+ export const CHANNEL_RESTART = 'Restart';
127
+
128
+ export const CHANNEL_APP_STATE_CHANGED = 'ApplicationStateChanged';
129
+
130
+ export const CHANNEL_READ_CLIPBOARD = 'ReadClipboard';
131
+ export const CHANNEL_WRITE_CLIPBOARD = 'WriteClipboard';
132
+
133
+ export const CHANNEL_KEYBOARD_LAYOUT_CHANGED = 'KeyboardLayoutChanged';
134
+ export const CHANNEL_IPC_CONNECTION = 'IpcConnection';
@@ -14,17 +14,8 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { ConnectionHandler } from '../../common/messaging/handler';
18
-
19
- /**
20
- * Name of the channel used with `ipcMain.on/emit`.
21
- */
22
- export const THEIA_ELECTRON_IPC_CHANNEL_NAME = 'theia-electron-ipc';
23
-
24
17
  /**
25
18
  * Electron-IPC-specific connection handler.
26
19
  * Use this if you want to establish communication between the frontend and the electron-main process.
27
20
  */
28
21
  export const ElectronConnectionHandler = Symbol('ElectronConnectionHandler');
29
- export interface ElectronConnectionHandler extends ConnectionHandler {
30
- }