wip: code driver

This commit is contained in:
Joao Moreno 2018-04-04 16:04:36 +02:00
parent 4c5157954b
commit b1f17c53d1
15 changed files with 155 additions and 16 deletions

View file

@ -12,6 +12,7 @@ import { IChannel } from 'vs/base/parts/ipc/common/ipc';
export const ID = 'driverService';
export const IDriver = createDecorator<IDriver>(ID);
//*START
export interface IWindow {
id: string;
}
@ -20,7 +21,7 @@ export interface IDriver {
_serviceBrand: any;
getWindows(): TPromise<IWindow[]>;
}
//*END
export interface IDriverChannel extends IChannel {
call(command: 'getWindows'): TPromise<IWindow[]>;

View file

@ -62,6 +62,7 @@ import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
import { join } from 'path';
import { copy } from 'vs/base/node/pfs';
import { ElectronURLListener } from 'vs/platform/url/electron-main/electronUrlListener';
import { serve, Driver } from './driver';
export class CodeApplication {
@ -291,6 +292,18 @@ export class CodeApplication {
// Services
const appInstantiationService = this.initServices(machineId);
// Create driver
if (this.environmentService.driverHandle) {
const driver = appInstantiationService.createInstance(Driver);
serve(this.environmentService.driverHandle, driver).then(server => {
this.logService.info('Driver started at:', this.environmentService.driverHandle);
this.toDispose.push(server);
}, err => {
this.logService.error('Failed to start driver running at:', this.environmentService.driverHandle);
});
}
// Setup Auth Handler
const authHandler = appInstantiationService.createInstance(ProxyAuthHandler);
this.toDispose.push(authHandler);

View file

@ -8,10 +8,9 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IDriver, IWindow, DriverChannel } from 'vs/code/common/driver';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { serve } from 'vs/base/parts/ipc/node/ipc.net';
import { serve as serveNet, Server } from 'vs/base/parts/ipc/node/ipc.net';
class Driver implements IDriver {
export class Driver implements IDriver {
_serviceBrand: any;
@ -24,9 +23,9 @@ class Driver implements IDriver {
}
}
export async function startDriver(handle: string, instantiationService: IInstantiationService): TPromise<void> {
const server = await serve(handle);
const driver = instantiationService.createInstance(Driver);
export async function serve(handle: string, driver: IDriver): TPromise<Server> {
const server = await serveNet(handle);
const channel = new DriverChannel(driver);
server.registerChannel('driver', channel);
return server;
}

View file

@ -7,10 +7,11 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IDriver, DriverChannelClient } from 'vs/code/common/driver';
import { connect as connectNet } from 'vs/base/parts/ipc/node/ipc.net';
import { connect as connectNet, Client } from 'vs/base/parts/ipc/node/ipc.net';
export async function connect(handle: string): TPromise<IDriver> {
export async function connect(handle: string): TPromise<{ client: Client, driver: IDriver }> {
const client = await connectNet(handle, 'driverClient');
const channel = client.getChannel('driver');
return new DriverChannelClient(channel);
const driver = new DriverChannelClient(channel);
return { client, driver };
}

View file

@ -57,7 +57,7 @@ export interface ParsedArgs {
'file-write'?: boolean;
'file-chmod'?: boolean;
'upload-logs'?: string;
'driver-handle'?: string;
'driver'?: string;
}
export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');

View file

@ -170,7 +170,7 @@ export class EnvironmentService implements IEnvironmentService {
get disableUpdates(): boolean { return !!this._args['disable-updates']; }
get disableCrashReporter(): boolean { return !!this._args['disable-crash-reporter']; }
get driverHandle(): string { return this._args['driver-handle']; }
get driverHandle(): string { return this._args['driver']; }
constructor(private _args: ParsedArgs, private _execPath: string) {
if (!process.env['VSCODE_LOGS']) {

16
test/smoke2/package.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "smoke2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"compile": "node tools/prebuild && tsc && node tools/postbuild",
"watch": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^2.8.1"
}
}

View file

@ -3,8 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const { bootstrap } = require('./bootstrap-amd');
export interface IWindow {
id: string;
}
bootstrap('vs/code/node/driver', ({ connect }) => {
console.log(connect);
});
export interface IDriver {
_serviceBrand: any;
getWindows(): Promise<IWindow[]>;
}
export interface IDisposable {
dispose(): void;
}
export function connect(outPath: string, handle: string): Promise<{ client: IDisposable, driver: IDriver }>;

12
test/smoke2/src/driver.js Normal file
View file

@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const path = require('path');
exports.connect = function (outPath, handle) {
const bootstrapPath = path.join(outPath, 'bootstrap-amd.js');
const { bootstrap } = require(bootstrapPath);
return new Promise((c, e) => bootstrap('vs/code/node/driver', ({ connect }) => connect(handle).then(c, e), e));
};

18
test/smoke2/src/main.ts Normal file
View file

@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as path from 'path';
import { connect } from './driver';
const rootPath = path.dirname(path.dirname(path.dirname(__dirname)));
const outPath = path.join(rootPath, 'out');
const handlePath = path.join(rootPath, 'foo.sock');
connect(outPath, handlePath).then(({ client, driver }) => {
return driver.getWindows().then(w => {
console.log(w);
client.dispose();
});
}, err => console.error('oh no', err));

View file

@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const fs = require('fs');
const path = require('path');
const root = path.dirname(__dirname);
const driverPath = path.join(root, 'src/driver.js');
const driver = fs.readFileSync(driverPath);
const outDriverPath = path.join(root, 'out/driver.js');
fs.writeFileSync(outDriverPath, driver);

View file

@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const fs = require('fs');
const path = require('path');
const root = path.dirname(path.dirname(path.dirname(__dirname)));
const driverPath = path.join(root, 'src/vs/code/common/driver.ts');
let contents = fs.readFileSync(driverPath, 'utf8');
contents = /\/\/\*START([\s\S]*)\/\/\*END/mi.exec(contents)[1].trim();
contents = contents.replace(/\bTPromise\b/g, 'Promise');
contents = `/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
${contents}
export interface IDisposable {
dispose(): void;
}
export function connect(outPath: string, handle: string): Promise<{ client: IDisposable, driver: IDriver }>;
`;
const srcPath = path.join(path.dirname(__dirname), 'src');
const outDriverPath = path.join(srcPath, 'driver.d.ts');
fs.writeFileSync(outDriverPath, contents);

View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "commonjs",
"outDir": "out"
},
"exclude": [
"node_modules"
]
}

7
test/smoke2/yarn.lock Normal file
View file

@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
typescript@^2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"

View file

@ -430,6 +430,13 @@
"*"
]
},
{
"target": "**/test/smoke2/**",
"restrictions": [
"**/test/smoke2/**",
"*"
]
},
{
"target": "{**/**.test.ts,**/test/**}",
"restrictions": "{**/vs/**,assert,sinon,crypto}"