Skip to content

Commit 36a2d26

Browse files
code-asherkylecarbs
authored andcommitted
Get shared process socket path to the environment service
1 parent 4eb9f87 commit 36a2d26

6 files changed

Lines changed: 51 additions & 35 deletions

File tree

packages/ide/src/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export abstract class Client {
4242
private tasks: string[] = [];
4343
private finishedTaskCount = 0;
4444
private readonly loadTime: Time;
45+
private sharedProcessDataPromise: Promise<ISharedProcessData>;
4546

4647
public constructor() {
4748
logger.info("Loading IDE");
4849

4950
this.loadTime = time(2500);
5051

52+
this.sharedProcessDataPromise = new Promise((resolve): void => {
53+
client.onSharedProcessActive(resolve);
54+
});
55+
5156
const overlay = document.getElementById("overlay");
5257
const logo = document.getElementById("logo");
5358
const msgElement = overlay
@@ -168,10 +173,20 @@ export abstract class Client {
168173
return client.initData;
169174
}
170175

176+
/**
177+
* An event that fires every time the shared process (re-)starts.
178+
*/
171179
public get onSharedProcessActive(): Event<ISharedProcessData> {
172180
return client.onSharedProcessActive;
173181
}
174182

183+
/**
184+
* A promise that resolves with *initial* shared process data.
185+
*/
186+
public get sharedProcessData(): Promise<ISharedProcessData> {
187+
return this.sharedProcessDataPromise;
188+
}
189+
175190
/**
176191
* Initialize the IDE.
177192
*/

packages/server/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from "path";
77
import * as WebSocket from "ws";
88
import { createApp } from "./server";
99
import { requireModule } from "./vscode/bootstrapFork";
10-
import { SharedProcess, SharedProcessState } from './vscode/sharedProcess';
10+
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
1111

1212
export class Entry extends Command {
1313

@@ -91,7 +91,7 @@ export class Entry extends Command {
9191
const app = createApp((app) => {
9292
app.use((req, res, next) => {
9393
res.on("finish", () => {
94-
logger.info(`\u001B[1m${req.method} ${res.statusCode} \u001B[0m${req.url}`, field("host", req.hostname), field("ip", req.ip));
94+
logger.debug(`\u001B[1m${req.method} ${res.statusCode} \u001B[0m${req.url}`, field("host", req.hostname), field("ip", req.ip));
9595
});
9696

9797
next();

packages/vscode/src/client.ts

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import "./fill/require";
2+
import * as paths from "./fill/paths";
23
import "./fill/storageDatabase";
34
import "./fill/windowsService";
4-
import * as paths from "./fill/paths";
5+
import "./fill/environmentService";
56
import "./fill/dom";
67
import "./vscode.scss";
78

8-
import { createConnection } from "net";
99
import { Client as IDEClient, IURI, IURIFactory } from "@coder/ide";
1010

1111
import { registerContextMenuListener } from "vs/base/parts/contextmenu/electron-main/contextmenu";
@@ -28,41 +28,32 @@ export class Client extends IDEClient {
2828
this.protocolPromise = new Promise((resolve): void => {
2929
this.protoResolve = resolve;
3030
});
31+
this.sharedProcessData.then((data) => {
32+
paths._paths.socketPath = data.socketPath;
33+
});
34+
this.initData.then((data) => {
35+
paths._paths.appData = data.dataDirectory;
36+
paths._paths.defaultUserData = data.dataDirectory;
37+
});
3138
}
3239

3340
protected initialize(): Promise<void> {
34-
this.task("Connect to shared process", 5, async () => {
35-
await new Promise((resolve, reject): void => {
36-
const listener = this.onSharedProcessActive((data) => {
37-
listener.dispose();
38-
const socket = createConnection(data.socketPath, resolve);
39-
socket.once("error", () => {
40-
reject();
41-
});
42-
this.protoResolve!(new Protocol(socket));
43-
});
44-
});
45-
}).catch(() => undefined);
46-
4741
registerContextMenuListener();
4842

49-
return this.task("Start workbench", 1000, async (initData) => {
50-
paths.paths.appData = initData.dataDirectory;
51-
paths.paths.defaultUserData = initData.dataDirectory;
52-
43+
return this.task("Start workbench", 1000, async (data) => {
5344
const { startup } = require("./startup");
5445
await startup({
5546
machineId: "1",
5647
windowId: this.windowId,
5748
logLevel: LogLevel.Info,
5849
mainPid: 1,
59-
appRoot: initData.dataDirectory,
60-
execPath: initData.tmpDirectory,
50+
appRoot: data.dataDirectory,
51+
execPath: data.tmpDirectory,
6152
userEnv: {},
62-
nodeCachedDataDir: initData.tmpDirectory,
53+
nodeCachedDataDir: data.tmpDirectory,
6354
perfEntries: [],
6455
_: [],
65-
folderUri: URI.file(initData.dataDirectory),
56+
folderUri: URI.file(data.dataDirectory),
6657
});
6758

6859
// TODO: Set notification service for retrying.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as paths from "./paths";
2+
import * as environment from "vs/platform/environment/node/environmentService";
3+
4+
export class EnvironmentService extends environment.EnvironmentService {
5+
6+
public get sharedIPCHandle(): string {
7+
return paths._paths.socketPath || super.sharedIPCHandle;
8+
}
9+
10+
}
11+
12+
// @ts-ignore
13+
environment.EnvironmentService = EnvironmentService;

packages/vscode/src/fill/paths.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
export const paths = {
1+
export const _paths = {
22
appData: "/tmp",
33
defaultUserData: "/tmp",
4+
socketPath: "/tmp/vscode-online.sock",
45
};
56

6-
export let getAppDataPath = (): string => paths.appData;
7-
export let getDefaultUserDataPath = (): string => paths.defaultUserData;
7+
export const getAppDataPath = (): string => _paths.appData;
8+
export const getDefaultUserDataPath = (): string => _paths.defaultUserData;

packages/vscode/src/fill/windowsService.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorksp
77
import { URI } from "vs/base/common/uri";
88
import { IRecentlyOpened } from "vs/platform/history/common/history";
99
import { ISerializableCommandAction } from "vs/platform/actions/common/actions";
10-
11-
// TODO: Might make sense to hook these straight in if we can.
12-
// import { WindowsService as VSWindowsService } from "vs/platform/windows/electron-main/windowsService";
13-
// import { WindowsManager } from "vs/code/electron-main/windows";
10+
import { client } from "../client";
1411

1512
/**
1613
* Instead of going to the shared process, we'll directly run these methods on
@@ -199,9 +196,8 @@ class WindowsService implements IWindowsService {
199196
}
200197

201198
// Shared process
202-
public whenSharedProcessReady(): Promise<void> {
203-
// TODO: Update once shared process is tied in.
204-
return Promise.resolve();
199+
public async whenSharedProcessReady(): Promise<void> {
200+
await client.sharedProcessData;
205201
}
206202

207203
public toggleSharedProcess(): Promise<void> {

0 commit comments

Comments
 (0)