mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-30 21:41:46 +01:00
shared process - add separate whenIpcReady
This commit is contained in:
@@ -364,7 +364,8 @@ export class CodeApplication extends Disposable {
|
||||
|
||||
// Spawn shared process after the first window has opened and 3s have passed
|
||||
const sharedProcess = this.instantiationService.createInstance(SharedProcess, machineId, this.userEnv);
|
||||
const sharedProcessClient = sharedProcess.whenReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
|
||||
const sharedProcessClient = sharedProcess.whenIpcReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
|
||||
const sharedProcessReady = sharedProcess.whenReady().then(() => sharedProcessClient);
|
||||
this.lifecycleMainService.when(LifecycleMainPhase.AfterWindowOpen).then(() => {
|
||||
this._register(new RunOnceScheduler(async () => {
|
||||
const userEnv = await getShellEnvironment(this.logService, this.environmentService);
|
||||
@@ -374,7 +375,7 @@ export class CodeApplication extends Disposable {
|
||||
});
|
||||
|
||||
// Services
|
||||
const appInstantiationService = await this.createServices(machineId, trueMachineId, sharedProcess, sharedProcessClient);
|
||||
const appInstantiationService = await this.createServices(machineId, trueMachineId, sharedProcess, sharedProcessReady);
|
||||
|
||||
// Create driver
|
||||
if (this.environmentService.driverHandle) {
|
||||
@@ -388,7 +389,7 @@ export class CodeApplication extends Disposable {
|
||||
this._register(new ProxyAuthHandler());
|
||||
|
||||
// Open Windows
|
||||
const windows = appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, electronIpcServer, sharedProcessClient));
|
||||
const windows = appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, electronIpcServer, sharedProcessReady));
|
||||
|
||||
// Post Open Windows Tasks
|
||||
this.afterWindowOpen();
|
||||
|
||||
@@ -21,6 +21,8 @@ export class SharedProcess implements ISharedProcess {
|
||||
|
||||
private window: BrowserWindow | null = null;
|
||||
|
||||
private readonly _whenReady: Promise<void>;
|
||||
|
||||
constructor(
|
||||
private readonly machineId: string,
|
||||
private userEnv: NodeJS.ProcessEnv,
|
||||
@@ -28,10 +30,12 @@ export class SharedProcess implements ISharedProcess {
|
||||
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
|
||||
@ILogService private readonly logService: ILogService,
|
||||
@IThemeMainService private readonly themeMainService: IThemeMainService
|
||||
) { }
|
||||
) {
|
||||
this._whenReady = new Promise<void>(c => ipcMain.once('handshake:sharedprocess-init-ready', () => c(undefined)));
|
||||
}
|
||||
|
||||
@memoize
|
||||
private get _whenReady(): Promise<void> {
|
||||
private get _whenIpcReady(): Promise<void> {
|
||||
this.window = new BrowserWindow({
|
||||
show: false,
|
||||
backgroundColor: this.themeMainService.getBackgroundColor(),
|
||||
@@ -98,16 +102,16 @@ export class SharedProcess implements ISharedProcess {
|
||||
});
|
||||
|
||||
return new Promise<void>(c => {
|
||||
const onHello = Event.once(Event.fromNodeEventEmitter(ipcMain, 'handshake:hello', ({ sender }: { sender: WebContents }) => sender));
|
||||
const onHello = Event.once(Event.fromNodeEventEmitter(ipcMain, 'handshake:sharedprocess-hello', ({ sender }: { sender: WebContents }) => sender));
|
||||
disposables.add(onHello(sender => {
|
||||
sender.send('handshake:hey there', {
|
||||
sender.send('handshake:main-payload', {
|
||||
sharedIPCHandle: this.environmentService.sharedIPCHandle,
|
||||
args: this.environmentService.args,
|
||||
logLevel: this.logService.getLevel()
|
||||
});
|
||||
|
||||
disposables.add(toDisposable(() => sender.send('handshake:goodbye')));
|
||||
ipcMain.once('handshake:im ready', () => c(undefined));
|
||||
disposables.add(toDisposable(() => sender.send('handshake:mainprocess-goodbye')));
|
||||
ipcMain.once('handshake:sharedprocess-ipc-ready', () => c(undefined));
|
||||
}));
|
||||
});
|
||||
}
|
||||
@@ -122,6 +126,11 @@ export class SharedProcess implements ISharedProcess {
|
||||
await this._whenReady;
|
||||
}
|
||||
|
||||
async whenIpcReady(): Promise<void> {
|
||||
await this.barrier.wait();
|
||||
await this._whenIpcReady;
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
if (!this.window || this.window.isVisible()) {
|
||||
this.hide();
|
||||
|
||||
Reference in New Issue
Block a user