提交 f22dcae3 编写于 作者: B Benjamin Pasero

ipc - have an explicit method to mark a window ready

上级 bc9c87a8
......@@ -91,15 +91,18 @@ export class CodeWindow extends Disposable implements ICodeWindow {
private static readonly MAX_URL_LENGTH = 2 * 1024 * 1024; // https://cs.chromium.org/chromium/src/url/url_constants.cc?l=32
private readonly _onLoad = this._register(new Emitter<void>());
readonly onLoad = this._onLoad.event;
private readonly _onReady = this._register(new Emitter<void>());
readonly onReady = this._onReady.event;
private readonly _onClose = this._register(new Emitter<void>());
readonly onClose = this._onClose.event;
private readonly _onDestroy = this._register(new Emitter<void>());
readonly onDestroy = this._onDestroy.event;
private readonly _onLoad = this._register(new Emitter<void>());
readonly onLoad = this._onLoad.event;
private hiddenTitleBarStyle: boolean | undefined;
private showTimeoutHandle: NodeJS.Timeout | undefined;
private _lastFocusTime: number;
......@@ -346,6 +349,9 @@ export class CodeWindow extends Disposable implements ICodeWindow {
while (this.whenReadyCallbacks.length) {
this.whenReadyCallbacks.pop()!(this);
}
// Events
this._onReady.fire();
}
ready(): Promise<ICodeWindow> {
......
......@@ -82,6 +82,7 @@ export interface ICommonElectronService {
toggleWindowTabsBar(): Promise<void>;
// Lifecycle
notifyReady(): Promise<void>
relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): Promise<void>;
reload(options?: { disableExtensions?: boolean }): Promise<void>;
closeWindow(): Promise<void>;
......
......@@ -370,6 +370,13 @@ export class ElectronMainService implements IElectronMainService {
//#region Lifecycle
async notifyReady(windowId: number | undefined): Promise<void> {
const window = this.windowById(windowId);
if (window) {
window.setReady();
}
}
async relaunch(windowId: number | undefined, options?: { addArgs?: string[], removeArgs?: string[] }): Promise<void> {
return this.lifecycleMainService.relaunch(options);
}
......
......@@ -33,9 +33,6 @@ export const enum WindowMode {
export interface ICodeWindow extends IDisposable {
readonly onClose: Event<void>;
readonly onDestroy: Event<void>;
readonly whenClosedOrLoaded: Promise<void>;
readonly id: number;
......
......@@ -15,7 +15,7 @@ import { ParsedArgs } from 'vs/platform/environment/node/argv';
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IStateService } from 'vs/platform/state/node/state';
import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window';
import { ipcMain as ipc, screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
import { screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
import { ILifecycleMainService, UnloadReason, LifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/platform/log/common/log';
......@@ -212,19 +212,6 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
private registerListeners(): void {
// React to workbench ready events from windows
ipc.on('vscode:workbenchReady', (event: Event, windowId: number) => {
this.logService.trace('IPC#vscode-workbenchReady');
const win = this.getWindowById(windowId);
if (win) {
win.setReady();
// Event
this._onWindowReady.fire(win);
}
});
// React to HC color scheme changes (Windows)
if (isWindows) {
nativeTheme.on('updated', () => {
......@@ -1434,24 +1421,25 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
if (options.forceNewTabbedWindow) {
const activeWindow = this.getLastActiveWindow();
if (activeWindow) {
activeWindow.addTabbedWindow(window);
activeWindow.addTabbedWindow(createdWindow);
}
}
// Add to our list of windows
WindowsMainService.WINDOWS.push(window);
WindowsMainService.WINDOWS.push(createdWindow);
// Indicate number change via event
this._onWindowsCountChanged.fire({ oldCount: WindowsMainService.WINDOWS.length - 1, newCount: WindowsMainService.WINDOWS.length });
// Window Events
once(window.onClose)(() => this.onWindowClosed(createdWindow));
once(window.onDestroy)(() => this.onBeforeWindowClose(createdWindow)); // try to save state before destroy because close will not fire
window.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
window.win.webContents.on('devtools-reload-page', () => this.lifecycleMainService.reload(createdWindow));
once(createdWindow.onReady)(() => this._onWindowReady.fire(createdWindow));
once(createdWindow.onClose)(() => this.onWindowClosed(createdWindow));
once(createdWindow.onDestroy)(() => this.onBeforeWindowClose(createdWindow)); // try to save state before destroy because close will not fire
createdWindow.win.webContents.removeAllListeners('devtools-reload-page'); // remove built in listener so we can handle this on our own
createdWindow.win.webContents.on('devtools-reload-page', () => this.lifecycleMainService.reload(createdWindow));
// Lifecycle
(this.lifecycleMainService as LifecycleMainService).registerWindow(window);
(this.lifecycleMainService as LifecycleMainService).registerWindow(createdWindow);
}
// Existing window
......
......@@ -397,8 +397,8 @@ export class NativeWindow extends Disposable {
// Handle open calls
this.setupOpenHandlers();
// Emit event when vscode is ready
this.lifecycleService.when(LifecyclePhase.Ready).then(() => ipcRenderer.send('vscode:workbenchReady', this.electronService.windowId));
// Notify main side when window ready
this.lifecycleService.when(LifecyclePhase.Ready).then(() => this.electronService.notifyReady());
// Integrity warning
this.integrityService.isPure().then(res => this.titleService.updateProperties({ isPure: res.isPure }));
......
......@@ -213,6 +213,7 @@ export class TestElectronService implements IElectronService {
async moveWindowTabToNewWindow(): Promise<void> { }
async mergeAllWindowTabs(): Promise<void> { }
async toggleWindowTabsBar(): Promise<void> { }
async notifyReady(): Promise<void> { }
async relaunch(options?: { addArgs?: string[] | undefined; removeArgs?: string[] | undefined; } | undefined): Promise<void> { }
async reload(): Promise<void> { }
async closeWindow(): Promise<void> { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册