@theia/core 1.71.0-next.49 → 1.71.0-next.57

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 (36) hide show
  1. package/lib/browser/catalog.json +26 -9
  2. package/lib/browser/common-frontend-contribution.js +2 -2
  3. package/lib/browser/common-frontend-contribution.js.map +1 -1
  4. package/lib/browser/connection-status-service.js +1 -1
  5. package/lib/browser/connection-status-service.js.map +1 -1
  6. package/lib/browser/menu/browser-menu-plugin.d.ts.map +1 -1
  7. package/lib/browser/menu/browser-menu-plugin.js +8 -1
  8. package/lib/browser/menu/browser-menu-plugin.js.map +1 -1
  9. package/lib/browser/saveable-service.d.ts +9 -2
  10. package/lib/browser/saveable-service.d.ts.map +1 -1
  11. package/lib/browser/saveable-service.js +34 -25
  12. package/lib/browser/saveable-service.js.map +1 -1
  13. package/lib/browser/window/browser-window-module.d.ts.map +1 -1
  14. package/lib/browser/window/browser-window-module.js +2 -0
  15. package/lib/browser/window/browser-window-module.js.map +1 -1
  16. package/lib/browser/window/default-secondary-window-service.d.ts +2 -0
  17. package/lib/browser/window/default-secondary-window-service.d.ts.map +1 -1
  18. package/lib/browser/window/default-secondary-window-service.js +7 -0
  19. package/lib/browser/window/default-secondary-window-service.js.map +1 -1
  20. package/lib/browser/window/window-focus-service.d.ts +71 -0
  21. package/lib/browser/window/window-focus-service.d.ts.map +1 -0
  22. package/lib/browser/window/window-focus-service.js +173 -0
  23. package/lib/browser/window/window-focus-service.js.map +1 -0
  24. package/lib/electron-browser/window/electron-window-module.d.ts.map +1 -1
  25. package/lib/electron-browser/window/electron-window-module.js +2 -0
  26. package/lib/electron-browser/window/electron-window-module.js.map +1 -1
  27. package/package.json +4 -4
  28. package/src/browser/common-frontend-contribution.ts +2 -2
  29. package/src/browser/connection-status-service.ts +1 -1
  30. package/src/browser/menu/browser-menu-plugin.ts +8 -1
  31. package/src/browser/saveable-service.ts +34 -27
  32. package/src/browser/window/browser-window-module.ts +2 -0
  33. package/src/browser/window/default-secondary-window-service.ts +6 -0
  34. package/src/browser/window/window-focus-service.ts +187 -0
  35. package/src/common/i18n/nls.metadata.json +4254 -1058
  36. package/src/electron-browser/window/electron-window-module.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/core",
3
- "version": "1.71.0-next.49+ff8893f59",
3
+ "version": "1.71.0-next.57+1fc9a8239",
4
4
  "description": "Theia is a cloud & desktop IDE framework implemented in TypeScript.",
5
5
  "main": "lib/common/index.js",
6
6
  "typings": "lib/common/index.d.ts",
@@ -17,8 +17,8 @@
17
17
  "@lumino/virtualdom": "^2.0.4",
18
18
  "@lumino/widgets": "2.7.5",
19
19
  "@parcel/watcher": "^2.5.6",
20
- "@theia/application-package": "1.71.0-next.49+ff8893f59",
21
- "@theia/request": "1.71.0-next.49+ff8893f59",
20
+ "@theia/application-package": "1.71.0-next.57+1fc9a8239",
21
+ "@theia/request": "1.71.0-next.57+1fc9a8239",
22
22
  "@types/body-parser": "^1.19.6",
23
23
  "@types/express": "^4.17.21",
24
24
  "@types/fs-extra": "^4.0.2",
@@ -221,5 +221,5 @@
221
221
  "nyc": {
222
222
  "extends": "../../configs/nyc.json"
223
223
  },
224
- "gitHead": "ff8893f5957f8e505176ecd8c3ef10d722d47172"
224
+ "gitHead": "1fc9a8239357c913ab79f1922b6e87aecd79cfdb"
225
225
  }
@@ -718,8 +718,8 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
718
718
  execute: title => title?.owner && this.shell.toggleMaximized(title?.owner),
719
719
  }));
720
720
  commandRegistry.registerCommand(CommonCommands.SHOW_MENU_BAR, {
721
- isEnabled: () => !isOSX,
722
- isVisible: () => !isOSX,
721
+ isEnabled: () => !this.isElectron() || !isOSX,
722
+ isVisible: () => !this.isElectron() || !isOSX,
723
723
  execute: () => {
724
724
  const menuBarVisibility = 'window.menuBarVisibility';
725
725
  const visibility = this.preferences[menuBarVisibility];
@@ -205,7 +205,7 @@ export class ApplicationConnectionStatusContribution extends DefaultFrontendAppl
205
205
  protected handleOffline(): void {
206
206
  this.statusBar.setElement(this.statusbarId, {
207
207
  alignment: StatusBarAlignment.LEFT,
208
- text: nls.localize('theia/core/offline', 'Offline'),
208
+ text: nls.localizeByDefault('Offline'),
209
209
  tooltip: nls.localize('theia/localize/offlineTooltip', 'Cannot connect to backend.'),
210
210
  priority: 5000
211
211
  });
@@ -143,7 +143,14 @@ export class DynamicMenuBarWidget extends MenuBarWidget {
143
143
  protected previousFocusedElement: HTMLElement | undefined;
144
144
 
145
145
  constructor() {
146
- super();
146
+ // Disable Lumino's overflow menu feature. The feature has a bug where
147
+ // `onUpdateRequest` consumes a stale `_overflowIndex` (only recomputed at the
148
+ // end of the method), which causes a RangeError when the menu bar is rendered
149
+ // at zero width. Additionally, Theia's CSS does not constrain the menu bar's
150
+ // offsetWidth to the available space, so the overflow detection never triggers.
151
+ // See https://github.com/eclipse-theia/theia/issues/17352
152
+ // See https://github.com/jupyterlab/lumino/issues/811
153
+ super({ overflowMenuOptions: { isVisible: false } });
147
154
  // HACK we need to hook in on private method _openChildMenu. Don't do this at home!
148
155
  DynamicMenuBarWidget.prototype['_openChildMenu'] = () => {
149
156
  if (this.activeMenu instanceof DynamicMenuWidget) {
@@ -22,6 +22,7 @@ import { AutoSaveMode, Saveable, SaveableSource, SaveableWidget, SaveOptions, Sa
22
22
  import { waitForClosed, Widget } from './widgets';
23
23
  import { FrontendApplicationContribution } from './frontend-application-contribution';
24
24
  import { FrontendApplication } from './frontend-application';
25
+ import { WindowFocusService } from './window/window-focus-service';
25
26
  import throttle = require('lodash.throttle');
26
27
 
27
28
  export const SaveErrorChecker = Symbol('SaveErrorChecker');
@@ -49,6 +50,9 @@ export class SaveableService implements FrontendApplicationContribution {
49
50
  @inject(ContributionProvider) @named(SaveErrorChecker)
50
51
  protected readonly errorCheckers: ContributionProvider<SaveErrorChecker>;
51
52
 
53
+ @inject(WindowFocusService)
54
+ protected readonly windowFocusService: WindowFocusService;
55
+
52
56
  protected saveThrottles = new Map<Widget, AutoSaveThrottle>();
53
57
  protected saveMode: AutoSaveMode = 'off';
54
58
  protected saveDelay = 1000;
@@ -131,6 +135,35 @@ export class SaveableService implements FrontendApplicationContribution {
131
135
  this.saveThrottles.get(e)?.dispose();
132
136
  this.saveThrottles.delete(e);
133
137
  });
138
+ // Save all dirty editors when any application window loses focus
139
+ this.windowFocusService.onDidWindowChangeFocus(({ hasFocus }) => {
140
+ if (!hasFocus) {
141
+ this.saveOnWindowBlur();
142
+ }
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Save all dirty saveables when the application window loses focus.
148
+ * Triggered for both `onFocusChange` and `onWindowChange` auto-save modes,
149
+ * matching VSCode's behavior where a window focus loss is a superset of
150
+ * editor focus loss.
151
+ */
152
+ protected saveOnWindowBlur(): void {
153
+ if (this.saveMode !== 'onWindowChange' && this.saveMode !== 'onFocusChange') {
154
+ return;
155
+ }
156
+ if (!this.shell) {
157
+ return;
158
+ }
159
+ for (const widget of this.shell.widgets) {
160
+ const saveable = Saveable.get(widget);
161
+ if (saveable && this.shouldAutoSave(widget, saveable)) {
162
+ saveable.save({
163
+ saveReason: SaveReason.FocusChange
164
+ });
165
+ }
166
+ }
134
167
  }
135
168
 
136
169
  protected updateAutoSaveMode(mode: AutoSaveMode): void {
@@ -169,39 +202,13 @@ export class SaveableService implements FrontendApplicationContribution {
169
202
  saveReason: SaveReason.AfterDelay
170
203
  });
171
204
  }
172
- },
173
- this.addBlurListener(widget, saveable)
205
+ }
174
206
  );
175
207
  this.saveThrottles.set(widget, saveThrottle);
176
208
  this.applySaveableWidget(widget, saveable);
177
209
  return saveThrottle;
178
210
  }
179
211
 
180
- protected addBlurListener(widget: Widget, saveable: Saveable): Disposable {
181
- const document = widget.node.ownerDocument;
182
- const listener = (() => {
183
- if (this.saveMode === 'onWindowChange' && !this.windowHasFocus(document) && this.shouldAutoSave(widget, saveable)) {
184
- saveable.save({
185
- saveReason: SaveReason.FocusChange
186
- });
187
- }
188
- }).bind(this);
189
- document.addEventListener('blur', listener);
190
- return Disposable.create(() => {
191
- document.removeEventListener('blur', listener);
192
- });
193
- }
194
-
195
- protected windowHasFocus(document: Document): boolean {
196
- if (document.visibilityState === 'hidden') {
197
- return false;
198
- } else if (document.hasFocus()) {
199
- return true;
200
- }
201
- // TODO: Add support for iframes
202
- return false;
203
- }
204
-
205
212
  protected shouldAutoSave(widget: Widget, saveable: Saveable): boolean {
206
213
  const uri = NavigatableWidget.getUri(widget);
207
214
  if (uri?.scheme === UNTITLED_SCHEME) {
@@ -24,6 +24,7 @@ import { SecondaryWindowService } from './secondary-window-service';
24
24
  import { DefaultSecondaryWindowService } from './default-secondary-window-service';
25
25
  import { bindRootContributionProvider } from '../../common';
26
26
  import { WindowTitleContribution } from './window-title-service';
27
+ import { WindowFocusService } from './window-focus-service';
27
28
 
28
29
  export default new ContainerModule(bind => {
29
30
  bind(DefaultWindowService).toSelf().inSingletonScope();
@@ -31,5 +32,6 @@ export default new ContainerModule(bind => {
31
32
  bind(FrontendApplicationContribution).toService(DefaultWindowService);
32
33
  bind(ClipboardService).to(BrowserClipboardService).inSingletonScope();
33
34
  bind(SecondaryWindowService).to(DefaultSecondaryWindowService).inSingletonScope();
35
+ bind(WindowFocusService).toSelf().inSingletonScope();
34
36
  bindRootContributionProvider(bind, WindowTitleContribution);
35
37
  });
@@ -22,6 +22,7 @@ import { Saveable } from '../saveable';
22
22
  import { Emitter, environment, Event, PreferenceService } from '../../common';
23
23
  import { SaveableService } from '../saveable-service';
24
24
  import { getAllWidgetsFromSecondaryWindow, getDefaultRestoreArea } from '../secondary-window-handler';
25
+ import { WindowFocusService } from './window-focus-service';
25
26
 
26
27
  @injectable()
27
28
  export class DefaultSecondaryWindowService implements SecondaryWindowService {
@@ -53,6 +54,9 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
53
54
  @inject(SaveableService)
54
55
  protected readonly saveResourceService: SaveableService;
55
56
 
57
+ @inject(WindowFocusService)
58
+ protected readonly windowFocusService: WindowFocusService;
59
+
56
60
  @postConstruct()
57
61
  init(): void {
58
62
  // Set up messaging with secondary windows
@@ -106,6 +110,7 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
106
110
  this.secondaryWindows.push(newWindow);
107
111
  this.onWindowOpenedEmitter.fire(newWindow);
108
112
  newWindow.addEventListener('DOMContentLoaded', () => {
113
+ const focusRegistration = this.windowFocusService.registerWindow(newWindow);
109
114
  newWindow.addEventListener('beforeunload', evt => {
110
115
  const widgets = getAllWidgetsFromSecondaryWindow(newWindow) ?? [widget];
111
116
  for (const w of widgets) {
@@ -120,6 +125,7 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
120
125
  }, { capture: true });
121
126
 
122
127
  newWindow.addEventListener('unload', () => {
128
+ focusRegistration.dispose();
123
129
  const extIndex = this.secondaryWindows.indexOf(newWindow);
124
130
  if (extIndex > -1) {
125
131
  this.onWindowClosedEmitter.fire(newWindow);
@@ -0,0 +1,187 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 EclipseSource 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-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ // based on https://github.com/microsoft/vscode/blob/ea6aac971b851ff8675f9ea04f8c0dfc36034a89/src/vs/workbench/services/host/browser/browserHostService.ts
18
+ // and https://github.com/microsoft/vscode/blob/ea6aac971b851ff8675f9ea04f8c0dfc36034a89/src/vs/base/browser/dom.ts#L1319 (FocusTracker)
19
+ /*---------------------------------------------------------------------------------------------
20
+ * Copyright (c) Microsoft Corporation. All rights reserved.
21
+ * Licensed under the MIT License. See License.txt in the project root for license information.
22
+ *--------------------------------------------------------------------------------------------*/
23
+
24
+ import { injectable, postConstruct } from 'inversify';
25
+ import { Disposable, DisposableCollection, Emitter, Event } from '../../common';
26
+
27
+ export interface WindowFocusEvent {
28
+ win: Window;
29
+ hasFocus: boolean;
30
+ }
31
+
32
+ /**
33
+ * Tracks focus state for each registered application window independently.
34
+ *
35
+ * The main window is registered automatically. Secondary windows should be
36
+ * registered via {@link registerWindow} — typically by the service responsible
37
+ * for creating them.
38
+ *
39
+ * Uses two complementary signals per window for robust detection:
40
+ * - `window` `focus`/`blur` events (OS-level window focus changes)
41
+ * - `document` `visibilitychange` events (browser tab switches)
42
+ *
43
+ * Blur events are debounced per window with `setTimeout(0)` so that focus
44
+ * moving between elements within the same window does not produce a false
45
+ * blur: the subsequent `focus` event cancels the pending blur before it fires.
46
+ *
47
+ * Each per-window event is latched — it only fires when that window's focus
48
+ * state actually changes.
49
+ */
50
+ @injectable()
51
+ export class WindowFocusService implements Disposable {
52
+
53
+ protected readonly onDidWindowChangeFocusEmitter = new Emitter<WindowFocusEvent>();
54
+
55
+ /**
56
+ * Fires when an individual window's focus state changes.
57
+ * The event payload identifies which window changed and whether it gained or lost focus.
58
+ *
59
+ * A window losing focus to another application window will fire separately
60
+ * for each window involved: one event with `hasFocus: false` for the window
61
+ * that lost focus, and one with `hasFocus: true` for the window that gained it.
62
+ */
63
+ readonly onDidWindowChangeFocus: Event<WindowFocusEvent> = this.onDidWindowChangeFocusEmitter.event;
64
+
65
+ protected readonly toDispose = new DisposableCollection(this.onDidWindowChangeFocusEmitter);
66
+
67
+ /** Per-window tracking state. */
68
+ protected readonly windowStates = new Map<Window, WindowTrackingState>();
69
+
70
+ @postConstruct()
71
+ protected init(): void {
72
+ this.registerWindow(window);
73
+ }
74
+
75
+ /**
76
+ * Register a window for focus tracking. The returned {@link Disposable}
77
+ * removes the window from tracking when disposed.
78
+ *
79
+ * The main window is registered automatically. Call this for secondary
80
+ * windows when they are created.
81
+ */
82
+ registerWindow(win: Window): Disposable {
83
+ if (this.windowStates.has(win)) {
84
+ return Disposable.NULL;
85
+ }
86
+
87
+ const state: WindowTrackingState = {
88
+ lastFocusState: this.windowHasFocus(win),
89
+ pendingBlurTimeout: undefined,
90
+ };
91
+ this.windowStates.set(win, state);
92
+
93
+ const onFocus = () => this.handleFocus(win, state);
94
+ const onBlur = () => this.scheduleBlur(win, state);
95
+ const onVisibilityChange = () => this.updateWindowFocusState(win, state);
96
+
97
+ win.addEventListener('focus', onFocus);
98
+ win.addEventListener('blur', onBlur);
99
+ win.document.addEventListener('visibilitychange', onVisibilityChange);
100
+
101
+ const cleanup = Disposable.create(() => {
102
+ this.cancelPendingBlur(state);
103
+ this.windowStates.delete(win);
104
+ win.removeEventListener('focus', onFocus);
105
+ win.removeEventListener('blur', onBlur);
106
+ try {
107
+ win.document.removeEventListener('visibilitychange', onVisibilityChange);
108
+ } catch {
109
+ // The window may already be closed
110
+ }
111
+ });
112
+
113
+ this.toDispose.push(cleanup);
114
+ return cleanup;
115
+ }
116
+
117
+ /**
118
+ * Whether any registered window currently has focus.
119
+ */
120
+ get hasFocus(): boolean {
121
+ for (const win of this.windowStates.keys()) {
122
+ if (this.windowHasFocus(win)) {
123
+ return true;
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+
129
+ protected windowHasFocus(win: Window): boolean {
130
+ try {
131
+ return win.document.hasFocus();
132
+ } catch {
133
+ // The window may have been closed
134
+ return false;
135
+ }
136
+ }
137
+
138
+ protected handleFocus(win: Window, state: WindowTrackingState): void {
139
+ // Cancel this window's pending blur — focus arrived before the timeout,
140
+ // meaning focus just moved between elements within this window.
141
+ this.cancelPendingBlur(state);
142
+ this.updateWindowFocusState(win, state);
143
+ }
144
+
145
+ /**
146
+ * Schedule a deferred blur check for this specific window.
147
+ * If no `focus` event arrives on this same window before the timeout fires,
148
+ * we treat it as a real focus loss for that window.
149
+ */
150
+ protected scheduleBlur(win: Window, state: WindowTrackingState): void {
151
+ this.cancelPendingBlur(state);
152
+ state.pendingBlurTimeout = setTimeout(() => {
153
+ state.pendingBlurTimeout = undefined;
154
+ this.updateWindowFocusState(win, state);
155
+ }, 0);
156
+ }
157
+
158
+ protected cancelPendingBlur(state: WindowTrackingState): void {
159
+ if (state.pendingBlurTimeout !== undefined) {
160
+ clearTimeout(state.pendingBlurTimeout);
161
+ state.pendingBlurTimeout = undefined;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Re-evaluate a single window's focus and fire if it changed (latching).
167
+ */
168
+ protected updateWindowFocusState(win: Window, state: WindowTrackingState): void {
169
+ const focused = this.windowHasFocus(win);
170
+ if (focused !== state.lastFocusState) {
171
+ state.lastFocusState = focused;
172
+ this.onDidWindowChangeFocusEmitter.fire({ win, hasFocus: focused });
173
+ }
174
+ }
175
+
176
+ dispose(): void {
177
+ for (const state of this.windowStates.values()) {
178
+ this.cancelPendingBlur(state);
179
+ }
180
+ this.toDispose.dispose();
181
+ }
182
+ }
183
+
184
+ interface WindowTrackingState {
185
+ lastFocusState: boolean;
186
+ pendingBlurTimeout: ReturnType<typeof setTimeout> | undefined;
187
+ }