Get shared process socket path to the environment service

This commit is contained in:
Asher 2019-01-22 12:27:59 -06:00 committed by Kyle Carberry
parent 4eb9f87217
commit 36a2d26148
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
6 changed files with 51 additions and 35 deletions

View File

@ -42,12 +42,17 @@ export abstract class Client {
private tasks: string[] = []; private tasks: string[] = [];
private finishedTaskCount = 0; private finishedTaskCount = 0;
private readonly loadTime: Time; private readonly loadTime: Time;
private sharedProcessDataPromise: Promise<ISharedProcessData>;
public constructor() { public constructor() {
logger.info("Loading IDE"); logger.info("Loading IDE");
this.loadTime = time(2500); this.loadTime = time(2500);
this.sharedProcessDataPromise = new Promise((resolve): void => {
client.onSharedProcessActive(resolve);
});
const overlay = document.getElementById("overlay"); const overlay = document.getElementById("overlay");
const logo = document.getElementById("logo"); const logo = document.getElementById("logo");
const msgElement = overlay const msgElement = overlay
@ -168,10 +173,20 @@ export abstract class Client {
return client.initData; return client.initData;
} }
/**
* An event that fires every time the shared process (re-)starts.
*/
public get onSharedProcessActive(): Event<ISharedProcessData> { public get onSharedProcessActive(): Event<ISharedProcessData> {
return client.onSharedProcessActive; return client.onSharedProcessActive;
} }
/**
* A promise that resolves with *initial* shared process data.
*/
public get sharedProcessData(): Promise<ISharedProcessData> {
return this.sharedProcessDataPromise;
}
/** /**
* Initialize the IDE. * Initialize the IDE.
*/ */

View File

@ -7,7 +7,7 @@ import * as path from "path";
import * as WebSocket from "ws"; import * as WebSocket from "ws";
import { createApp } from "./server"; import { createApp } from "./server";
import { requireModule } from "./vscode/bootstrapFork"; import { requireModule } from "./vscode/bootstrapFork";
import { SharedProcess, SharedProcessState } from './vscode/sharedProcess'; import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
export class Entry extends Command { export class Entry extends Command {
@ -91,7 +91,7 @@ export class Entry extends Command {
const app = createApp((app) => { const app = createApp((app) => {
app.use((req, res, next) => { app.use((req, res, next) => {
res.on("finish", () => { 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(); next();

View File

@ -1,11 +1,11 @@
import "./fill/require"; import "./fill/require";
import * as paths from "./fill/paths";
import "./fill/storageDatabase"; import "./fill/storageDatabase";
import "./fill/windowsService"; import "./fill/windowsService";
import * as paths from "./fill/paths"; import "./fill/environmentService";
import "./fill/dom"; import "./fill/dom";
import "./vscode.scss"; import "./vscode.scss";
import { createConnection } from "net";
import { Client as IDEClient, IURI, IURIFactory } from "@coder/ide"; import { Client as IDEClient, IURI, IURIFactory } from "@coder/ide";
import { registerContextMenuListener } from "vs/base/parts/contextmenu/electron-main/contextmenu"; 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.protocolPromise = new Promise((resolve): void => {
this.protoResolve = resolve; 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<void> { protected initialize(): Promise<void> {
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(); registerContextMenuListener();
return this.task("Start workbench", 1000, async (initData) => { return this.task("Start workbench", 1000, async (data) => {
paths.paths.appData = initData.dataDirectory;
paths.paths.defaultUserData = initData.dataDirectory;
const { startup } = require("./startup"); const { startup } = require("./startup");
await startup({ await startup({
machineId: "1", machineId: "1",
windowId: this.windowId, windowId: this.windowId,
logLevel: LogLevel.Info, logLevel: LogLevel.Info,
mainPid: 1, mainPid: 1,
appRoot: initData.dataDirectory, appRoot: data.dataDirectory,
execPath: initData.tmpDirectory, execPath: data.tmpDirectory,
userEnv: {}, userEnv: {},
nodeCachedDataDir: initData.tmpDirectory, nodeCachedDataDir: data.tmpDirectory,
perfEntries: [], perfEntries: [],
_: [], _: [],
folderUri: URI.file(initData.dataDirectory), folderUri: URI.file(data.dataDirectory),
}); });
// TODO: Set notification service for retrying. // TODO: Set notification service for retrying.

View File

@ -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;

View File

@ -1,7 +1,8 @@
export const paths = { export const _paths = {
appData: "/tmp", appData: "/tmp",
defaultUserData: "/tmp", defaultUserData: "/tmp",
socketPath: "/tmp/vscode-online.sock",
}; };
export let getAppDataPath = (): string => paths.appData; export const getAppDataPath = (): string => _paths.appData;
export let getDefaultUserDataPath = (): string => paths.defaultUserData; export const getDefaultUserDataPath = (): string => _paths.defaultUserData;

View File

@ -7,10 +7,7 @@ import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, ISingleFolderWorksp
import { URI } from "vs/base/common/uri"; import { URI } from "vs/base/common/uri";
import { IRecentlyOpened } from "vs/platform/history/common/history"; import { IRecentlyOpened } from "vs/platform/history/common/history";
import { ISerializableCommandAction } from "vs/platform/actions/common/actions"; import { ISerializableCommandAction } from "vs/platform/actions/common/actions";
import { client } from "../client";
// 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";
/** /**
* Instead of going to the shared process, we'll directly run these methods on * Instead of going to the shared process, we'll directly run these methods on
@ -199,9 +196,8 @@ class WindowsService implements IWindowsService {
} }
// Shared process // Shared process
public whenSharedProcessReady(): Promise<void> { public async whenSharedProcessReady(): Promise<void> {
// TODO: Update once shared process is tied in. await client.sharedProcessData;
return Promise.resolve();
} }
public toggleSharedProcess(): Promise<void> { public toggleSharedProcess(): Promise<void> {