SDA-4751 - Prevent starting new c9 shell if application is terminated (#2251)

* SDA-4751 - Prevent starting new c9 shell if application is terminated

* SDA-4751 - Prevent c9 connect
This commit is contained in:
Kiran Niranjan 2025-01-10 17:14:15 +05:30 committed by GitHub
parent 5669963ec4
commit beb9f53a3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -1,7 +1,13 @@
import { WebContents } from 'electron'; import { app, WebContents } from 'electron';
import { createConnection, Socket } from 'net'; import { createConnection, Socket } from 'net';
import { logger } from '../common/c9-logger'; import { logger } from '../common/c9-logger';
let isAppQuitting = false;
app.on('before-quit', () => {
isAppQuitting = true;
});
class C9PipeHandler { class C9PipeHandler {
private _socket: Socket | undefined; private _socket: Socket | undefined;
@ -89,6 +95,12 @@ let c9PipeHandler: C9PipeHandler | undefined;
* @param pipe pipe identifier * @param pipe pipe identifier
*/ */
export const connectC9Pipe = (sender: WebContents, pipe: string) => { export const connectC9Pipe = (sender: WebContents, pipe: string) => {
if (isAppQuitting) {
logger.info(
'c9-pipe-handler: App is quitting, preventing c9 pipe connect.',
);
return;
}
if (!c9PipeHandler) { if (!c9PipeHandler) {
c9PipeHandler = new C9PipeHandler(); c9PipeHandler = new C9PipeHandler();
} else { } else {
@ -104,6 +116,9 @@ export const connectC9Pipe = (sender: WebContents, pipe: string) => {
* @param data the data to be written * @param data the data to be written
*/ */
export const writeC9Pipe = (data: Uint8Array) => { export const writeC9Pipe = (data: Uint8Array) => {
if (isAppQuitting) {
return;
}
c9PipeHandler?.write(data); c9PipeHandler?.write(data);
}; };

View File

@ -17,6 +17,12 @@ export interface IShellStatus {
type StatusCallback = (status: IShellStatus) => void; type StatusCallback = (status: IShellStatus) => void;
let isAppQuitting = false;
app.on('before-quit', () => {
isAppQuitting = true;
});
class C9ShellHandler { class C9ShellHandler {
private _c9shell: ChildProcess | undefined; private _c9shell: ChildProcess | undefined;
private _curStatus: IShellStatus | undefined; private _curStatus: IShellStatus | undefined;
@ -43,6 +49,12 @@ class C9ShellHandler {
* Starts the c9shell process * Starts the c9shell process
*/ */
public async startShell() { public async startShell() {
if (isAppQuitting) {
logger.info(
'c9-shell-handler: App is quitting, preventing c9 shell start.',
);
return;
}
if (this._attachExistingC9Shell()) { if (this._attachExistingC9Shell()) {
logger.info('c9-shell-handler: _attachExistingC9Shell, skip start'); logger.info('c9-shell-handler: _attachExistingC9Shell, skip start');
return; return;