Skip to content

Commit d55e069

Browse files
committed
Split child and parent wrappers
I think having them combined and relying on if statements was getting confusing especially if we want to add additional messages with different payloads (which will soon be the case).
1 parent 2a3608d commit d55e069

File tree

3 files changed

+145
-102
lines changed

3 files changed

+145
-102
lines changed

src/node/entry.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { coderCloudBind } from "./coder-cloud"
1919
import { commit, version } from "./constants"
2020
import { register } from "./routes"
2121
import { humanPath, isFile, open } from "./util"
22-
import { ipcMain, WrapperProcess } from "./wrapper"
22+
import { isChild, wrapper } from "./wrapper"
2323

2424
export const runVsCodeCli = (args: DefaultedArgs): void => {
2525
logger.debug("forking vs code cli...")
@@ -137,7 +137,7 @@ const main = async (args: DefaultedArgs): Promise<void> => {
137137
logger.info(" - Connected to cloud agent")
138138
} catch (err) {
139139
logger.error(err.message)
140-
ipcMain.exit(1)
140+
wrapper.exit(1)
141141
}
142142
}
143143

@@ -161,9 +161,9 @@ async function entry(): Promise<void> {
161161
// There's no need to check flags like --help or to spawn in an existing
162162
// instance for the child process because these would have already happened in
163163
// the parent and the child wouldn't have been spawned.
164-
if (ipcMain.isChild) {
165-
await ipcMain.handshake()
166-
ipcMain.preventExit()
164+
if (isChild(wrapper)) {
165+
await wrapper.handshake()
166+
wrapper.preventExit()
167167
return main(args)
168168
}
169169

@@ -201,11 +201,10 @@ async function entry(): Promise<void> {
201201
return openInExistingInstance(args, socketPath)
202202
}
203203

204-
const wrapper = new WrapperProcess(require("../../package.json").version)
205204
return wrapper.start()
206205
}
207206

208207
entry().catch((error) => {
209208
logger.error(error.message)
210-
ipcMain.exit(error)
209+
wrapper.exit(error)
211210
})

src/node/vscode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { rootPath } from "./constants"
88
import { settings } from "./settings"
99
import { SocketProxyProvider } from "./socket"
1010
import { isFile } from "./util"
11-
import { ipcMain } from "./wrapper"
11+
import { wrapper } from "./wrapper"
1212

1313
export class VscodeProvider {
1414
public readonly serverRootPath: string
@@ -20,7 +20,7 @@ export class VscodeProvider {
2020
public constructor() {
2121
this.vsRootPath = path.resolve(rootPath, "lib/vscode")
2222
this.serverRootPath = path.join(this.vsRootPath, "out/vs/server")
23-
ipcMain.onDispose(() => this.dispose())
23+
wrapper.onDispose(() => this.dispose())
2424
}
2525

2626
public async dispose(): Promise<void> {

0 commit comments

Comments
 (0)