11import "./fill/require" ;
22import "./fill/storageDatabase" ;
33import "./fill/windowsService" ;
4+ import * as paths from "./fill/paths" ;
5+ import "./fill/dom" ;
6+ import "./vscode.scss" ;
47
5- import { fork } from "child_process " ;
8+ import { createConnection } from "net " ;
69import { Client as IDEClient , IURI , IURIFactory } from "@coder/ide" ;
7- import { logger } from "@coder/logger" ;
810
911import { registerContextMenuListener } from "vs/base/parts/contextmenu/electron-main/contextmenu" ;
1012import { LogLevel } from "vs/platform/log/common/log" ;
1113import { toLocalISOString } from "vs/base/common/date" ;
1214// import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey";
1315import { URI } from "vs/base/common/uri" ;
1416
15- import { Protocol , ISharedProcessInitData } from "./protocol" ;
16- import * as paths from "./fill/paths" ;
17- import "./firefox" ;
17+ import { Protocol } from "vs/base/parts/ipc/node/ipc.net" ;
1818
1919export class Client extends IDEClient {
2020
21- private readonly sharedProcessLogger = logger . named ( "shr proc" ) ;
2221 private readonly windowId = parseInt ( toLocalISOString ( new Date ( ) ) . replace ( / [ - : . T Z ] / g, "" ) , 10 ) ;
23- private readonly version = "hello" ; // TODO: pull from package.json probably
24- private readonly bootstrapForkLocation = "/bootstrap" ; // TODO: location.
22+
2523 public readonly protocolPromise : Promise < Protocol > ;
26- private protoResolve : ( ( protocol : Protocol ) => void ) | undefined ;
24+ public protoResolve : ( ( protocol : Protocol ) => void ) | undefined ;
2725
2826 public constructor ( ) {
2927 super ( ) ;
30- process . env . VSCODE_LOGS = "/tmp/vscode-online/logs" ; // TODO: use tmpdir or get log directory from init data.
3128 this . protocolPromise = new Promise ( ( resolve ) : void => {
3229 this . protoResolve = resolve ;
3330 } ) ;
3431 }
3532
3633 protected initialize ( ) : Promise < void > {
37- this . task ( "Start shared process" , 5 , async ( ) => {
38- const protocol = await this . forkSharedProcess ( ) ;
39- this . protoResolve ! ( protocol ) ;
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+ } ) ;
4045 } ) . catch ( ( ) => undefined ) ;
4146
4247 registerContextMenuListener ( ) ;
4348
4449 return this . task ( "Start workbench" , 1000 , async ( initData ) => {
50+ paths . paths . appData = initData . dataDirectory ;
51+ paths . paths . defaultUserData = initData . dataDirectory ;
52+
4553 const { startup } = require ( "./startup" ) ;
4654 await startup ( {
4755 machineId : "1" ,
@@ -57,6 +65,33 @@ export class Client extends IDEClient {
5765 folderUri : URI . file ( initData . dataDirectory ) ,
5866 } ) ;
5967
68+ // TODO: Set notification service for retrying.
69+ // this.retry.setNotificationService({
70+ // prompt: (severity, message, buttons, onCancel) => {
71+ // const handle = getNotificationService().prompt(severity, message, buttons, onCancel);
72+ // return {
73+ // close: () => handle.close(),
74+ // updateMessage: (message) => handle.updateMessage(message),
75+ // updateButtons: (buttons) => handle.updateActions({
76+ // primary: buttons.map((button) => ({
77+ // id: undefined,
78+ // label: button.label,
79+ // tooltip: undefined,
80+ // class: undefined,
81+ // enabled: true,
82+ // checked: false,
83+ // radio: false,
84+ // dispose: () => undefined,
85+ // run: () => {
86+ // button.run();
87+ // return Promise.resolve();
88+ // },
89+ // })),
90+ // }),
91+ // };
92+ // }
93+ // });
94+
6095 // TODO: Set up clipboard context.
6196 // const workbench = workbenchShell.workbench;
6297 // const contextKeys = workbench.workbenchParams.serviceCollection.get(IContextKeyService) as IContextKeyService;
@@ -69,50 +104,6 @@ export class Client extends IDEClient {
69104 } , this . initData ) ;
70105 }
71106
72- public async forkSharedProcess ( ) : Promise < Protocol > {
73- const childProcess = fork ( this . bootstrapForkLocation , [ "--shared" ] , {
74- env : {
75- "VSCODE_ALLOW_IO" : "true" ,
76- "AMD_ENTRYPOINT" : "vs/code/electron-browser/sharedProcess/sharedProcessClient" ,
77- } ,
78- } ) ;
79-
80- childProcess . stderr . on ( "data" , ( data ) => {
81- this . sharedProcessLogger . error ( "stderr: " + data ) ;
82- } ) ;
83-
84- const protocol = Protocol . fromProcess ( childProcess ) ;
85- await new Promise ( ( resolve , reject ) : void => {
86- protocol . onClose ( ( ) => {
87- reject ( new Error ( "unable to establish connection to shared process" ) ) ;
88- } ) ;
89-
90- const listener = protocol . onMessage ( ( message ) => {
91- const messageStr = message . toString ( ) ;
92- this . sharedProcessLogger . debug ( messageStr ) ;
93- switch ( messageStr ) {
94- case "handshake:hello" :
95- protocol . send ( Buffer . from ( JSON . stringify ( {
96- // Using the version so if we get a new mount, it spins up a new
97- // shared process.
98- socketPath : `/tmp/vscode-online/shared-${ this . version } .sock` ,
99- serviceUrl : "" , // TODO
100- logsDir : process . env . VSCODE_LOGS ,
101- windowId : this . windowId ,
102- logLevel : LogLevel . Info ,
103- } as ISharedProcessInitData ) ) ) ;
104- break ;
105- case "handshake:ready" :
106- listener . dispose ( ) ;
107- resolve ( ) ;
108- break ;
109- }
110- } ) ;
111- } ) ;
112-
113- return protocol ;
114- }
115-
116107 protected createUriFactory ( ) : IURIFactory {
117108 return {
118109 // TODO: not sure why this is an error.
@@ -126,8 +117,3 @@ export class Client extends IDEClient {
126117}
127118
128119export const client = new Client ( ) ;
129-
130- client . initData . then ( ( initData ) => {
131- paths . appData = initData . dataDirectory ;
132- paths . defaultUserData = initData . dataDirectory ;
133- } ) ;
0 commit comments