Skip to content

Commit 783ed71

Browse files
committed
Tweaks
1 parent e99b83d commit 783ed71

5 files changed

Lines changed: 137 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
4343
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
4444
import { DownloadService } from 'vs/platform/download/node/downloadService';
4545
import { IDownloadService } from 'vs/platform/download/common/download';
46+
import { RemoteAuthorityResolverService } from 'vs/platform/remote/node/remoteAuthorityResolverService';
47+
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
48+
import { RemoteAuthorityResolverChannel } from 'vs/platform/remote/node/remoteAuthorityResolverChannel';
4649

4750
export interface ISharedProcessConfiguration {
4851
readonly machineId: string;
@@ -126,10 +129,16 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
126129
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
127130
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
128131
services.set(ILocalizationsService, new SyncDescriptor(LocalizationsService));
132+
services.set(IRemoteAuthorityResolverService, new SyncDescriptor(RemoteAuthorityResolverService));
129133

130134
const instantiationService2 = instantiationService.createChild(services);
131135

132136
instantiationService2.invokeFunction(accessor => {
137+
138+
const remoteAuthorityResolverService = accessor.get(IRemoteAuthorityResolverService);
139+
const remoteAuthorityResolverChannel = new RemoteAuthorityResolverChannel(remoteAuthorityResolverService);
140+
server.registerChannel('remoteAuthorityResolver', remoteAuthorityResolverChannel);
141+
133142
const extensionManagementService = accessor.get(IExtensionManagementService);
134143
const channel = new ExtensionManagementChannel(extensionManagementService);
135144
server.registerChannel('extensions', channel);
@@ -143,6 +152,7 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
143152

144153
createSharedProcessContributions(instantiationService2);
145154
disposables.push(extensionManagementService as ExtensionManagementService);
155+
disposables.push(remoteAuthorityResolverService as RemoteAuthorityResolverService);
146156
});
147157
});
148158
}

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing } from 'electron';
6+
import { app, ipcMain as ipc, systemPreferences, shell, Event, contentTracing, protocol } from 'electron';
77
import * as platform from 'vs/base/common/platform';
88
import { WindowsManager } from 'vs/code/electron-main/windows';
99
import { IWindowsService, OpenContext, ActiveWindowManager } from 'vs/platform/windows/common/windows';
@@ -57,6 +57,7 @@ import { LogLevelSetterChannel } from 'vs/platform/log/node/logIpc';
5757
import * as errors from 'vs/base/common/errors';
5858
import { ElectronURLListener } from 'vs/platform/url/electron-main/electronUrlListener';
5959
import { serve as serveDriver } from 'vs/platform/driver/electron-main/driver';
60+
import { connectRemoteAgentManagement } from 'vs/platform/remote/node/remoteAgentConnection';
6061
import { IMenubarService } from 'vs/platform/menubar/common/menubar';
6162
import { MenubarService } from 'vs/platform/menubar/electron-main/menubarService';
6263
import { MenubarChannel } from 'vs/platform/menubar/node/menubarIpc';
@@ -68,6 +69,10 @@ import { THEME_STORAGE_KEY, THEME_BG_STORAGE_KEY } from 'vs/code/electron-main/t
6869
import { nativeSep, join } from 'vs/base/common/paths';
6970
import { homedir } from 'os';
7071
import { localize } from 'vs/nls';
72+
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
73+
import { IRemoteAuthorityResolverChannel, RemoteAuthorityResolverChannelClient } from 'vs/platform/remote/node/remoteAuthorityResolverChannel';
74+
import { IRemoteAgentFileSystemChannel, REMOTE_FILE_SYSTEM_CHANNEL_NAME } from 'vs/platform/remote/node/remoteAgentFileSystemChannel';
75+
import { ResolvedAuthority } from 'vs/platform/remote/common/remoteAuthorityResolver';
7176
import { SnapUpdateService } from 'vs/platform/update/electron-main/updateService.snap';
7277

7378
export class CodeApplication {
@@ -165,6 +170,67 @@ export class CodeApplication {
165170
});
166171
});
167172

173+
const connectionPool: Map<string, ActiveConnection> = new Map<string, ActiveConnection>();
174+
175+
class ActiveConnection {
176+
private _authority: string;
177+
private _client: TPromise<Client>;
178+
private _disposeRunner: RunOnceScheduler;
179+
180+
constructor(authority: string, connectionInfo: TPromise<ResolvedAuthority>) {
181+
this._authority = authority;
182+
this._client = connectionInfo.then(({ host, port }) => {
183+
return connectRemoteAgentManagement(host, port, `main`);
184+
});
185+
this._disposeRunner = new RunOnceScheduler(() => this._dispose(), 5000);
186+
}
187+
188+
private _dispose(): void {
189+
this._disposeRunner.dispose();
190+
connectionPool.delete(this._authority);
191+
this._client.then((connection) => {
192+
connection.dispose();
193+
});
194+
}
195+
196+
public getClient(): TPromise<Client> {
197+
this._disposeRunner.schedule();
198+
return this._client;
199+
}
200+
}
201+
202+
protocol.registerBufferProtocol(REMOTE_HOST_SCHEME, async (request, callback) => {
203+
if (request.method !== 'GET') {
204+
return callback(null);
205+
}
206+
const uri = URI.parse(request.url);
207+
208+
let activeConnection: ActiveConnection = null;
209+
if (connectionPool.has(uri.authority)) {
210+
activeConnection = connectionPool.get(uri.authority);
211+
} else {
212+
if (this.sharedProcessClient) {
213+
const remoteAuthorityResolverChannel = getDelayedChannel<IRemoteAuthorityResolverChannel>(this.sharedProcessClient.then(c => c.getChannel('remoteAuthorityResolver')));
214+
const remoteAuthorityResolverChannelClient = new RemoteAuthorityResolverChannelClient(remoteAuthorityResolverChannel);
215+
activeConnection = new ActiveConnection(uri.authority, remoteAuthorityResolverChannelClient.resolveAuthority(uri.authority));
216+
connectionPool.set(uri.authority, activeConnection);
217+
}
218+
}
219+
try {
220+
const rawClient = await activeConnection.getClient();
221+
if (connectionPool.has(uri.authority)) { // not disposed in the meantime
222+
const channel = rawClient.getChannel<IRemoteAgentFileSystemChannel>(REMOTE_FILE_SYSTEM_CHANNEL_NAME);
223+
const fileContents = await channel.call('readFile', [uri.authority, uri]);
224+
callback(Buffer.from(fileContents));
225+
} else {
226+
callback(null);
227+
}
228+
} catch (err) {
229+
errors.onUnexpectedError(err);
230+
callback(null);
231+
}
232+
});
233+
168234
let macOpenFileURIs: URI[] = [];
169235
let runningTimeout: any = null;
170236
app.on('open-file', (event: Event, path: string) => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { TPromise } from 'vs/base/common/winjs.base';
7+
import { Client, Protocol } from 'vs/base/parts/ipc/node/ipc.net';
8+
import { IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
9+
10+
export function connectRemoteAgentManagement(host: string, port: number, clientId: string): TPromise<Client> {
11+
throw new Error(`Not implemented`);
12+
}
13+
14+
export interface IExtensionHostConnectionResult {
15+
protocol: Protocol;
16+
debugPort?: number;
17+
}
18+
19+
export function connectRemoteAgentExtensionHost(host: string, port: number, debugArguments: IExtensionHostDebugParams): TPromise<IExtensionHostConnectionResult> {
20+
throw new Error(`Not implemented`);
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IRemoteAuthorityResolverService, ResolvedAuthority, IResolvingProgressEvent } from 'vs/platform/remote/common/remoteAuthorityResolver';
7+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
8+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
9+
import { ILogService } from 'vs/platform/log/common/log';
10+
import { Disposable } from 'vs/base/common/lifecycle';
11+
import { Emitter, Event } from 'vs/base/common/event';
12+
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
13+
14+
export class RemoteAuthorityResolverService extends Disposable implements IRemoteAuthorityResolverService {
15+
16+
_serviceBrand: any;
17+
18+
private _onResolvingProgress: Emitter<IResolvingProgressEvent> = this._register(new Emitter<IResolvingProgressEvent>());
19+
readonly onResolvingProgress: Event<IResolvingProgressEvent> = this._onResolvingProgress.event;
20+
21+
constructor(
22+
@IEnvironmentService environmentService: IEnvironmentService,
23+
@IConfigurationService configurationService: IConfigurationService,
24+
@ILogService logService: ILogService,
25+
@IExtensionManagementService extensionManagementService: IExtensionManagementService
26+
) {
27+
super();
28+
}
29+
30+
async resolveAuthority(authority: string): Promise<ResolvedAuthority> {
31+
throw new Error(`Not implemented`);
32+
}
33+
34+
async getLabel(authority: string): Promise<string | null> {
35+
throw new Error(`Not implemented`);
36+
}
37+
}

src/vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IChannel, getDelayedChannel } from 'vs/base/parts/ipc/node/ipc';
1010
import { Client } from 'vs/base/parts/ipc/node/ipc.net';
1111
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1212
import { INotificationService } from 'vs/platform/notification/common/notification';
13+
import { connectRemoteAgentManagement } from 'vs/platform/remote/node/remoteAgentConnection';
1314
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
1415
import { RemoteExtensionEnvironmentChannelClient } from 'vs/workbench/services/remote/node/remoteAgentEnvironmentChannel';
1516
import { IRemoteAgentConnection, IRemoteAgentEnvironment, IRemoteAgentService } from 'vs/workbench/services/remote/node/remoteAgentService';
@@ -77,7 +78,7 @@ class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection
7778
private _getOrCreateConnection(): TPromise<Client> {
7879
if (!this._connection) {
7980
this._connection = this._remoteAuthorityResolverService.resolveAuthority(this.remoteAuthority).then((resolvedAuthority) => {
80-
throw new Error(`Not implemented`);
81+
return connectRemoteAgentManagement(resolvedAuthority.host, resolvedAuthority.port, `renderer`);
8182
});
8283
}
8384
return this._connection;

0 commit comments

Comments
 (0)