diff --git a/src/app/c9-pipe-handler.ts b/src/app/c9-pipe-handler.ts index 795a85c08..f9cae41e9 100644 --- a/src/app/c9-pipe-handler.ts +++ b/src/app/c9-pipe-handler.ts @@ -1,7 +1,13 @@ -import { WebContents } from 'electron'; +import { app, WebContents } from 'electron'; import { createConnection, Socket } from 'net'; import { logger } from '../common/c9-logger'; +let isAppQuitting = false; + +app.on('before-quit', () => { + isAppQuitting = true; +}); + class C9PipeHandler { private _socket: Socket | undefined; @@ -89,6 +95,12 @@ let c9PipeHandler: C9PipeHandler | undefined; * @param pipe pipe identifier */ export const connectC9Pipe = (sender: WebContents, pipe: string) => { + if (isAppQuitting) { + logger.info( + 'c9-pipe-handler: App is quitting, preventing c9 pipe connect.', + ); + return; + } if (!c9PipeHandler) { c9PipeHandler = new C9PipeHandler(); } else { @@ -104,6 +116,9 @@ export const connectC9Pipe = (sender: WebContents, pipe: string) => { * @param data the data to be written */ export const writeC9Pipe = (data: Uint8Array) => { + if (isAppQuitting) { + return; + } c9PipeHandler?.write(data); }; diff --git a/src/app/c9-shell-handler.ts b/src/app/c9-shell-handler.ts index ea31251b1..4e6879234 100644 --- a/src/app/c9-shell-handler.ts +++ b/src/app/c9-shell-handler.ts @@ -17,6 +17,12 @@ export interface IShellStatus { type StatusCallback = (status: IShellStatus) => void; +let isAppQuitting = false; + +app.on('before-quit', () => { + isAppQuitting = true; +}); + class C9ShellHandler { private _c9shell: ChildProcess | undefined; private _curStatus: IShellStatus | undefined; @@ -43,6 +49,12 @@ class C9ShellHandler { * Starts the c9shell process */ public async startShell() { + if (isAppQuitting) { + logger.info( + 'c9-shell-handler: App is quitting, preventing c9 shell start.', + ); + return; + } if (this._attachExistingC9Shell()) { logger.info('c9-shell-handler: _attachExistingC9Shell, skip start'); return;