Skip to content

Commit 4ac7672

Browse files
committed
shared process - register channels when IPC ready
1 parent 89b9cd7 commit 4ac7672

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ import { KeytarCredentialsService } from 'vs/platform/credentials/node/credentia
6161
import { UserDataAutoSyncService } from 'vs/platform/userDataSync/electron-browser/userDataAutoSyncService';
6262
import { SettingsSynchroniser } from 'vs/platform/userDataSync/common/settingsSync';
6363
import { UserDataAuthTokenService } from 'vs/platform/userDataSync/common/userDataAuthTokenService';
64+
import { NativeStorageService } from 'vs/platform/storage/node/storageService';
65+
import { GlobalStorageDatabaseChannelClient } from 'vs/platform/storage/node/storageIpc';
66+
import { IStorageService } from 'vs/platform/storage/common/storage';
6467

6568
export interface ISharedProcessConfiguration {
6669
readonly machineId: string;
@@ -119,6 +122,11 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
119122
disposables.add(configurationService);
120123
await configurationService.initialize();
121124

125+
const storageService = new NativeStorageService(new GlobalStorageDatabaseChannelClient(mainProcessService.getChannel('storage')), logService, environmentService);
126+
await storageService.initialize();
127+
services.set(IStorageService, storageService);
128+
disposables.add(toDisposable(() => storageService.flush()));
129+
122130
services.set(IEnvironmentService, environmentService);
123131
services.set(IProductService, { _serviceBrand: undefined, ...product });
124132
services.set(ILogService, logService);

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,14 @@ export class CodeApplication extends Disposable {
364364

365365
// Spawn shared process after the first window has opened and 3s have passed
366366
const sharedProcess = this.instantiationService.createInstance(SharedProcess, machineId, this.userEnv);
367-
const sharedProcessClient = sharedProcess.whenIpcReady().then(() => connect(this.environmentService.sharedIPCHandle, 'main'));
368-
const sharedProcessReady = sharedProcess.whenReady().then(() => sharedProcessClient);
367+
const sharedProcessClient = sharedProcess.whenIpcReady().then(() => {
368+
this.logService.trace('Shared process: IPC ready');
369+
return connect(this.environmentService.sharedIPCHandle, 'main');
370+
});
371+
const sharedProcessReady = sharedProcess.whenReady().then(() => {
372+
this.logService.trace('Shared process: init ready');
373+
return sharedProcessClient;
374+
});
369375
this.lifecycleMainService.when(LifecycleMainPhase.AfterWindowOpen).then(() => {
370376
this._register(new RunOnceScheduler(async () => {
371377
const userEnv = await getShellEnvironment(this.logService, this.environmentService);
@@ -389,7 +395,7 @@ export class CodeApplication extends Disposable {
389395
this._register(new ProxyAuthHandler());
390396

391397
// Open Windows
392-
const windows = appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, electronIpcServer, sharedProcessReady));
398+
const windows = appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, electronIpcServer, sharedProcessClient));
393399

394400
// Post Open Windows Tasks
395401
this.afterWindowOpen();
@@ -425,7 +431,7 @@ export class CodeApplication extends Disposable {
425431
return { machineId, trueMachineId };
426432
}
427433

428-
private async createServices(machineId: string, trueMachineId: string | undefined, sharedProcess: SharedProcess, sharedProcessClient: Promise<Client<string>>): Promise<IInstantiationService> {
434+
private async createServices(machineId: string, trueMachineId: string | undefined, sharedProcess: SharedProcess, sharedProcessReady: Promise<Client<string>>): Promise<IInstantiationService> {
429435
const services = new ServiceCollection();
430436

431437
const fileService = this._register(new FileService(this.logService));
@@ -457,7 +463,7 @@ export class CodeApplication extends Disposable {
457463
services.set(ISharedProcessMainService, new SyncDescriptor(SharedProcessMainService, [sharedProcess]));
458464
services.set(ILaunchMainService, new SyncDescriptor(LaunchMainService));
459465

460-
const diagnosticsChannel = getDelayedChannel(sharedProcessClient.then(client => client.getChannel('diagnostics')));
466+
const diagnosticsChannel = getDelayedChannel(sharedProcessReady.then(client => client.getChannel('diagnostics')));
461467
services.set(IDiagnosticsService, new SyncDescriptor(DiagnosticsService, [diagnosticsChannel]));
462468

463469
services.set(IIssueService, new SyncDescriptor(IssueMainService, [machineId, this.userEnv]));
@@ -478,7 +484,7 @@ export class CodeApplication extends Disposable {
478484

479485
// Telemetry
480486
if (!this.environmentService.isExtensionDevelopment && !this.environmentService.args['disable-telemetry'] && !!product.enableTelemetry) {
481-
const channel = getDelayedChannel(sharedProcessClient.then(client => client.getChannel('telemetryAppender')));
487+
const channel = getDelayedChannel(sharedProcessReady.then(client => client.getChannel('telemetryAppender')));
482488
const appender = combinedAppender(new TelemetryAppenderClient(channel), new LogAppender(this.logService));
483489
const commonProperties = resolveCommonProperties(product.commit, product.version, machineId, product.msftInternalDomains, this.environmentService.installSourcePath);
484490
const piiPaths = this.environmentService.extensionsPath ? [this.environmentService.appRoot, this.environmentService.extensionsPath] : [this.environmentService.appRoot];
@@ -572,6 +578,7 @@ export class CodeApplication extends Disposable {
572578
const storageMainService = accessor.get(IStorageMainService);
573579
const storageChannel = this._register(new GlobalStorageDatabaseChannel(this.logService, storageMainService));
574580
electronIpcServer.registerChannel('storage', storageChannel);
581+
sharedProcessClient.then(client => client.registerChannel('storage', storageChannel));
575582

576583
const loggerChannel = new LoggerChannel(accessor.get(ILogService));
577584
electronIpcServer.registerChannel('logger', loggerChannel);

0 commit comments

Comments
 (0)