Skip to content

Commit c500d0e

Browse files
authored
Make sure we can reopen secondary windows (#13509)
- Refactored to close widget upon browser-case window close - Seems 'close' event is no longer fired in browser case. Using 'unload' Fixes #13214 Contributred on behalf of STMicroelectronics. Signed-off-by: Thomas Mäder <[email protected]>
1 parent cf63b20 commit c500d0e

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

packages/core/src/browser/window/default-secondary-window-service.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,14 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
8282
}
8383

8484
createSecondaryWindow(widget: ExtractableWidget, shell: ApplicationShell): Window | undefined {
85-
const win = this.doCreateSecondaryWindow(widget, shell);
86-
if (win) {
87-
this.secondaryWindows.push(win);
88-
win.addEventListener('close', () => {
89-
const extIndex = this.secondaryWindows.indexOf(win);
90-
if (extIndex > -1) {
91-
this.secondaryWindows.splice(extIndex, 1);
92-
};
93-
});
94-
}
95-
return win;
96-
}
97-
98-
protected findWindow<T>(windowName: string): Window | undefined {
99-
for (const w of this.secondaryWindows) {
100-
if (w.name === windowName) {
101-
return w;
102-
}
103-
}
104-
return undefined;
105-
}
106-
107-
protected doCreateSecondaryWindow(widget: ExtractableWidget, shell: ApplicationShell): Window | undefined {
108-
let options;
10985
const [height, width, left, top] = this.findSecondaryWindowCoordinates(widget);
110-
options = `popup=1,width=${width},height=${height},left=${left},top=${top}`;
86+
let options = `popup=1,width=${width},height=${height},left=${left},top=${top}`;
11187
if (this.preferenceService.get('window.secondaryWindowAlwaysOnTop')) {
11288
options += ',alwaysOnTop=true';
11389
}
11490
const newWindow = window.open(DefaultSecondaryWindowService.SECONDARY_WINDOW_URL, this.nextWindowId(), options) ?? undefined;
11591
if (newWindow) {
92+
this.secondaryWindows.push(newWindow);
11693
newWindow.addEventListener('DOMContentLoaded', () => {
11794
newWindow.addEventListener('beforeunload', evt => {
11895
const saveable = Saveable.get(widget);
@@ -124,17 +101,38 @@ export class DefaultSecondaryWindowService implements SecondaryWindowService {
124101
}
125102
}, { capture: true });
126103

127-
newWindow.addEventListener('close', () => {
104+
newWindow.addEventListener('unload', () => {
128105
const saveable = Saveable.get(widget);
129106
shell.closeWidget(widget.id, {
130107
save: !!saveable && saveable.dirty && saveable.autoSave !== 'off'
131108
});
109+
110+
const extIndex = this.secondaryWindows.indexOf(newWindow);
111+
if (extIndex > -1) {
112+
this.secondaryWindows.splice(extIndex, 1);
113+
};
132114
});
115+
this.windowCreated(newWindow, widget, shell);
133116
});
134117
}
135118
return newWindow;
136119
}
137120

121+
protected windowCreated(newWindow: Window, widget: ExtractableWidget, shell: ApplicationShell): void {
122+
newWindow.addEventListener('unload', () => {
123+
shell.closeWidget(widget.id);
124+
});
125+
}
126+
127+
protected findWindow<T>(windowName: string): Window | undefined {
128+
for (const w of this.secondaryWindows) {
129+
if (w.name === windowName) {
130+
return w;
131+
}
132+
}
133+
return undefined;
134+
}
135+
138136
protected findSecondaryWindowCoordinates(widget: ExtractableWidget): (number | undefined)[] {
139137
const clientBounds = widget.node.getBoundingClientRect();
140138
const preference = this.preferenceService.get('window.secondaryWindowPlacement');

packages/core/src/electron-browser/window/electron-secondary-window-service.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ export class ElectronSecondaryWindowService extends DefaultSecondaryWindowServic
2424
window.electronTheiaCore.focusWindow(win.name);
2525
}
2626

27-
protected override doCreateSecondaryWindow(widget: ExtractableWidget, shell: ApplicationShell): Window | undefined {
28-
const w = super.doCreateSecondaryWindow(widget, shell);
29-
if (w) {
30-
window.electronTheiaCore.setMenuBarVisible(false, w.name);
31-
window.electronTheiaCore.setSecondaryWindowCloseRequestHandler(w.name, () => this.canClose(widget, shell));
32-
}
33-
return w;
27+
protected override windowCreated(newWindow: Window, widget: ExtractableWidget, shell: ApplicationShell): void {
28+
window.electronTheiaCore.setMenuBarVisible(false, newWindow.name);
29+
window.electronTheiaCore.setSecondaryWindowCloseRequestHandler(newWindow.name, () => this.canClose(widget, shell));
3430
}
3531
private async canClose(widget: ExtractableWidget, shell: ApplicationShell): Promise<boolean> {
36-
await shell.closeWidget(widget.id, undefined);
32+
await shell.closeWidget(widget.id);
3733
return widget.isDisposed;
3834
}
3935
}

0 commit comments

Comments
 (0)