Skip to content

Commit f2abadb

Browse files
author
Benjamin Pasero
committed
better shared process disposal
1 parent cef40ed commit f2abadb

2 files changed

Lines changed: 9 additions & 24 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ export class CodeApplication {
278278

279279
// Spawn shared process
280280
this.sharedProcess = new SharedProcess(this.environmentService, this.lifecycleService, this.logService, machineId, this.userEnv);
281-
this.toDispose.push(this.sharedProcess);
282281
this.sharedProcessClient = this.sharedProcess.whenReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
283282

284283
// Services

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import { assign } from 'vs/base/common/objects';
77
import { memoize } from 'vs/base/common/decorators';
8-
import { IDisposable, toDisposable, dispose } from 'vs/base/common/lifecycle';
98
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
109
import { TPromise } from 'vs/base/common/winjs.base';
1110
import { IProcessEnvironment } from 'vs/base/common/platform';
@@ -20,7 +19,6 @@ export class SharedProcess implements ISharedProcess {
2019
private barrier = new Barrier();
2120

2221
private window: Electron.BrowserWindow;
23-
private disposables: IDisposable[] = [];
2422

2523
constructor(
2624
private readonly environmentService: IEnvironmentService,
@@ -29,20 +27,6 @@ export class SharedProcess implements ISharedProcess {
2927
private readonly machineId: string,
3028
private readonly userEnv: IProcessEnvironment,
3129
) {
32-
this.registerListeners();
33-
}
34-
35-
private registerListeners(): void {
36-
37-
// Shut the shared process down when we are quitting
38-
//
39-
// Note: because we veto the window close, we must call our dispose() method,
40-
// which removes the veto. Otherwise the application would never quit because
41-
// the shared process window is refusing to close!
42-
//
43-
this.lifecycleService.onShutdown(() => {
44-
this.dispose();
45-
});
4630
}
4731

4832
@memoize
@@ -79,9 +63,15 @@ export class SharedProcess implements ISharedProcess {
7963
};
8064

8165
this.window.on('close', onClose);
82-
this.disposables.push(toDisposable(() => this.window.removeListener('close', onClose)));
8366

84-
this.disposables.push(toDisposable(() => {
67+
this.lifecycleService.onShutdown(() => {
68+
// Shut the shared process down when we are quitting
69+
//
70+
// Note: because we veto the window close, we must first remove our veto.
71+
// Otherwise the application would never quit because the shared process
72+
// window is refusing to close!
73+
//
74+
this.window.removeListener('close', onClose);
8575

8676
// Electron seems to crash on Windows without this setTimeout :|
8777
setTimeout(() => {
@@ -93,7 +83,7 @@ export class SharedProcess implements ISharedProcess {
9383

9484
this.window = null;
9585
}, 0);
96-
}));
86+
});
9787

9888
return new TPromise<void>((c, e) => {
9989
ipcMain.once('handshake:hello', ({ sender }: { sender: any }) => {
@@ -133,8 +123,4 @@ export class SharedProcess implements ISharedProcess {
133123
this.window.webContents.closeDevTools();
134124
this.window.hide();
135125
}
136-
137-
dispose(): void {
138-
this.disposables = dispose(this.disposables);
139-
}
140126
}

0 commit comments

Comments
 (0)