From 36a2d2614871d82616b27ca9a369cfc5b5ad9113 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 22 Jan 2019 12:27:59 -0600 Subject: [PATCH] Get shared process socket path to the environment service --- packages/ide/src/client.ts | 15 ++++++++ packages/server/src/cli.ts | 4 +- packages/vscode/src/client.ts | 37 +++++++------------ .../vscode/src/fill/environmentService.ts | 13 +++++++ packages/vscode/src/fill/paths.ts | 7 ++-- packages/vscode/src/fill/windowsService.ts | 10 ++--- 6 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 packages/vscode/src/fill/environmentService.ts diff --git a/packages/ide/src/client.ts b/packages/ide/src/client.ts index 6961f739..29020787 100644 --- a/packages/ide/src/client.ts +++ b/packages/ide/src/client.ts @@ -42,12 +42,17 @@ export abstract class Client { private tasks: string[] = []; private finishedTaskCount = 0; private readonly loadTime: Time; + private sharedProcessDataPromise: Promise; public constructor() { logger.info("Loading IDE"); this.loadTime = time(2500); + this.sharedProcessDataPromise = new Promise((resolve): void => { + client.onSharedProcessActive(resolve); + }); + const overlay = document.getElementById("overlay"); const logo = document.getElementById("logo"); const msgElement = overlay @@ -168,10 +173,20 @@ export abstract class Client { return client.initData; } + /** + * An event that fires every time the shared process (re-)starts. + */ public get onSharedProcessActive(): Event { return client.onSharedProcessActive; } + /** + * A promise that resolves with *initial* shared process data. + */ + public get sharedProcessData(): Promise { + return this.sharedProcessDataPromise; + } + /** * Initialize the IDE. */ diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index bca6ee22..d6050092 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -7,7 +7,7 @@ import * as path from "path"; import * as WebSocket from "ws"; import { createApp } from "./server"; import { requireModule } from "./vscode/bootstrapFork"; -import { SharedProcess, SharedProcessState } from './vscode/sharedProcess'; +import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess"; export class Entry extends Command { @@ -91,7 +91,7 @@ export class Entry extends Command { const app = createApp((app) => { app.use((req, res, next) => { res.on("finish", () => { - logger.info(`\u001B[1m${req.method} ${res.statusCode} \u001B[0m${req.url}`, field("host", req.hostname), field("ip", req.ip)); + logger.debug(`\u001B[1m${req.method} ${res.statusCode} \u001B[0m${req.url}`, field("host", req.hostname), field("ip", req.ip)); }); next(); diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index 5b826f06..08b9d557 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -1,11 +1,11 @@ import "./fill/require"; +import * as paths from "./fill/paths"; import "./fill/storageDatabase"; import "./fill/windowsService"; -import * as paths from "./fill/paths"; +import "./fill/environmentService"; import "./fill/dom"; import "./vscode.scss"; -import { createConnection } from "net"; import { Client as IDEClient, IURI, IURIFactory } from "@coder/ide"; import { registerContextMenuListener } from "vs/base/parts/contextmenu/electron-main/contextmenu"; @@ -28,41 +28,32 @@ export class Client extends IDEClient { this.protocolPromise = new Promise((resolve): void => { this.protoResolve = resolve; }); + this.sharedProcessData.then((data) => { + paths._paths.socketPath = data.socketPath; + }); + this.initData.then((data) => { + paths._paths.appData = data.dataDirectory; + paths._paths.defaultUserData = data.dataDirectory; + }); } protected initialize(): Promise { - this.task("Connect to shared process", 5, async () => { - await new Promise((resolve, reject): void => { - const listener = this.onSharedProcessActive((data) => { - listener.dispose(); - const socket = createConnection(data.socketPath, resolve); - socket.once("error", () => { - reject(); - }); - this.protoResolve!(new Protocol(socket)); - }); - }); - }).catch(() => undefined); - registerContextMenuListener(); - return this.task("Start workbench", 1000, async (initData) => { - paths.paths.appData = initData.dataDirectory; - paths.paths.defaultUserData = initData.dataDirectory; - + return this.task("Start workbench", 1000, async (data) => { const { startup } = require("./startup"); await startup({ machineId: "1", windowId: this.windowId, logLevel: LogLevel.Info, mainPid: 1, - appRoot: initData.dataDirectory, - execPath: initData.tmpDirectory, + appRoot: data.dataDirectory, + execPath: data.tmpDirectory, userEnv: {}, - nodeCachedDataDir: initData.tmpDirectory, + nodeCachedDataDir: data.tmpDirectory, perfEntries: [], _: [], - folderUri: URI.file(initData.dataDirectory), + folderUri: URI.file(data.dataDirectory), }); // TODO: Set notification service for retrying. diff --git a/packages/vscode/src/fill/environmentService.ts b/packages/vscode/src/fill/environmentService.ts new file mode 100644 index 00000000..7e5fa0ad --- /dev/null +++ b/packages/vscode/src/fill/environmentService.ts @@ -0,0 +1,13 @@ +import * as paths from "./paths"; +import * as environment from "vs/platform/environment/node/environmentService"; + +export class EnvironmentService extends environment.EnvironmentService { + + public get sharedIPCHandle(): string { + return paths._paths.socketPath || super.sharedIPCHandle; + } + +} + +// @ts-ignore +environment.EnvironmentService = EnvironmentService; diff --git a/packages/vscode/src/fill/paths.ts b/packages/vscode/src/fill/paths.ts index 1a4a3f4c..ceba02de 100644 --- a/packages/vscode/src/fill/paths.ts +++ b/packages/vscode/src/fill/paths.ts @@ -1,7 +1,8 @@ -export const paths = { +export const _paths = { appData: "/tmp", defaultUserData: "/tmp", + socketPath: "/tmp/vscode-online.sock", }; -export let getAppDataPath = (): string => paths.appData; -export let getDefaultUserDataPath = (): string => paths.defaultUserData; +export const getAppDataPath = (): string => _paths.appData; +export const getDefaultUserDataPath = (): string => _paths.defaultUserData; diff --git a/packages/vscode/src/fill/windowsService.ts b/packages/vscode/src/fill/windowsService.ts index 8dd850f4..5f49cf9f 100644 --- a/packages/vscode/src/fill/windowsService.ts +++ b/packages/vscode/src/fill/windowsService.ts @@ -7,10 +7,7 @@ import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorksp import { URI } from "vs/base/common/uri"; import { IRecentlyOpened } from "vs/platform/history/common/history"; import { ISerializableCommandAction } from "vs/platform/actions/common/actions"; - -// TODO: Might make sense to hook these straight in if we can. -// import { WindowsService as VSWindowsService } from "vs/platform/windows/electron-main/windowsService"; -// import { WindowsManager } from "vs/code/electron-main/windows"; +import { client } from "../client"; /** * Instead of going to the shared process, we'll directly run these methods on @@ -199,9 +196,8 @@ class WindowsService implements IWindowsService { } // Shared process - public whenSharedProcessReady(): Promise { - // TODO: Update once shared process is tied in. - return Promise.resolve(); + public async whenSharedProcessReady(): Promise { + await client.sharedProcessData; } public toggleSharedProcess(): Promise {