Skip to content

Commit f22dcae

Browse files
author
Benjamin Pasero
committed
ipc - have an explicit method to mark a window ready
1 parent bc9c87a commit f22dcae

7 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/vs/code/electron-main/window.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,18 @@ export class CodeWindow extends Disposable implements ICodeWindow {
9191

9292
private static readonly MAX_URL_LENGTH = 2 * 1024 * 1024; // https://cs.chromium.org/chromium/src/url/url_constants.cc?l=32
9393

94+
private readonly _onLoad = this._register(new Emitter<void>());
95+
readonly onLoad = this._onLoad.event;
96+
97+
private readonly _onReady = this._register(new Emitter<void>());
98+
readonly onReady = this._onReady.event;
99+
94100
private readonly _onClose = this._register(new Emitter<void>());
95101
readonly onClose = this._onClose.event;
96102

97103
private readonly _onDestroy = this._register(new Emitter<void>());
98104
readonly onDestroy = this._onDestroy.event;
99105

100-
private readonly _onLoad = this._register(new Emitter<void>());
101-
readonly onLoad = this._onLoad.event;
102-
103106
private hiddenTitleBarStyle: boolean | undefined;
104107
private showTimeoutHandle: NodeJS.Timeout | undefined;
105108
private _lastFocusTime: number;
@@ -346,6 +349,9 @@ export class CodeWindow extends Disposable implements ICodeWindow {
346349
while (this.whenReadyCallbacks.length) {
347350
this.whenReadyCallbacks.pop()!(this);
348351
}
352+
353+
// Events
354+
this._onReady.fire();
349355
}
350356

351357
ready(): Promise<ICodeWindow> {

src/vs/platform/electron/common/electron.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface ICommonElectronService {
8282
toggleWindowTabsBar(): Promise<void>;
8383

8484
// Lifecycle
85+
notifyReady(): Promise<void>
8586
relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): Promise<void>;
8687
reload(options?: { disableExtensions?: boolean }): Promise<void>;
8788
closeWindow(): Promise<void>;

src/vs/platform/electron/electron-main/electronMainService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ export class ElectronMainService implements IElectronMainService {
370370

371371
//#region Lifecycle
372372

373+
async notifyReady(windowId: number | undefined): Promise<void> {
374+
const window = this.windowById(windowId);
375+
if (window) {
376+
window.setReady();
377+
}
378+
}
379+
373380
async relaunch(windowId: number | undefined, options?: { addArgs?: string[], removeArgs?: string[] }): Promise<void> {
374381
return this.lifecycleMainService.relaunch(options);
375382
}

src/vs/platform/windows/electron-main/windows.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export const enum WindowMode {
3333

3434
export interface ICodeWindow extends IDisposable {
3535

36-
readonly onClose: Event<void>;
37-
readonly onDestroy: Event<void>;
38-
3936
readonly whenClosedOrLoaded: Promise<void>;
4037

4138
readonly id: number;

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ParsedArgs } from 'vs/platform/environment/node/argv';
1515
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
1616
import { IStateService } from 'vs/platform/state/node/state';
1717
import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window';
18-
import { ipcMain as ipc, screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
18+
import { screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
1919
import { ILifecycleMainService, UnloadReason, LifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
2020
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2121
import { ILogService } from 'vs/platform/log/common/log';
@@ -212,19 +212,6 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
212212

213213
private registerListeners(): void {
214214

215-
// React to workbench ready events from windows
216-
ipc.on('vscode:workbenchReady', (event: Event, windowId: number) => {
217-
this.logService.trace('IPC#vscode-workbenchReady');
218-
219-
const win = this.getWindowById(windowId);
220-
if (win) {
221-
win.setReady();
222-
223-
// Event
224-
this._onWindowReady.fire(win);
225-
}
226-
});
227-
228215
// React to HC color scheme changes (Windows)
229216
if (isWindows) {
230217
nativeTheme.on('updated', () => {
@@ -1434,24 +1421,25 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
14341421
if (options.forceNewTabbedWindow) {
14351422
const activeWindow = this.getLastActiveWindow();
14361423
if (activeWindow) {
1437-
activeWindow.addTabbedWindow(window);
1424+
activeWindow.addTabbedWindow(createdWindow);
14381425
}
14391426
}
14401427

14411428
// Add to our list of windows
1442-
WindowsMainService.WINDOWS.push(window);
1429+
WindowsMainService.WINDOWS.push(createdWindow);
14431430

14441431
// Indicate number change via event
14451432
this._onWindowsCountChanged.fire({ oldCount: WindowsMainService.WINDOWS.length - 1, newCount: WindowsMainService.WINDOWS.length });
14461433

14471434
// Window Events
1448-
once(window.onClose)(() => this.onWindowClosed(createdWindow));
1449-
once(window.onDestroy)(() => this.onBeforeWindowClose(createdWindow)); // try to save state before destroy because close will not fire
1450-
window.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
1451-
window.win.webContents.on('devtools-reload-page', () => this.lifecycleMainService.reload(createdWindow));
1435+
once(createdWindow.onReady)(() => this._onWindowReady.fire(createdWindow));
1436+
once(createdWindow.onClose)(() => this.onWindowClosed(createdWindow));
1437+
once(createdWindow.onDestroy)(() => this.onBeforeWindowClose(createdWindow)); // try to save state before destroy because close will not fire
1438+
createdWindow.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
1439+
createdWindow.win.webContents.on('devtools-reload-page', () => this.lifecycleMainService.reload(createdWindow));
14521440

14531441
// Lifecycle
1454-
(this.lifecycleMainService as LifecycleMainService).registerWindow(window);
1442+
(this.lifecycleMainService as LifecycleMainService).registerWindow(createdWindow);
14551443
}
14561444

14571445
// Existing window

src/vs/workbench/electron-browser/window.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ export class NativeWindow extends Disposable {
397397
// Handle open calls
398398
this.setupOpenHandlers();
399399

400-
// Emit event when vscode is ready
401-
this.lifecycleService.when(LifecyclePhase.Ready).then(() => ipcRenderer.send('vscode:workbenchReady', this.electronService.windowId));
400+
// Notify main side when window ready
401+
this.lifecycleService.when(LifecyclePhase.Ready).then(() => this.electronService.notifyReady());
402402

403403
// Integrity warning
404404
this.integrityService.isPure().then(res => this.titleService.updateProperties({ isPure: res.isPure }));

src/vs/workbench/test/electron-browser/workbenchTestServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export class TestElectronService implements IElectronService {
213213
async moveWindowTabToNewWindow(): Promise<void> { }
214214
async mergeAllWindowTabs(): Promise<void> { }
215215
async toggleWindowTabsBar(): Promise<void> { }
216+
async notifyReady(): Promise<void> { }
216217
async relaunch(options?: { addArgs?: string[] | undefined; removeArgs?: string[] | undefined; } | undefined): Promise<void> { }
217218
async reload(): Promise<void> { }
218219
async closeWindow(): Promise<void> { }

0 commit comments

Comments
 (0)