Skip to content

Commit

Permalink
SDA-4751 - Prevent starting new c9 shell if application is terminated (
Browse files Browse the repository at this point in the history
…finos#2251)

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

* SDA-4751 - Prevent c9 connect
  • Loading branch information
KiranNiranjan authored Jan 10, 2025
1 parent 5669963 commit beb9f53
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/app/c9-pipe-handler.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
};

Expand Down
12 changes: 12 additions & 0 deletions src/app/c9-shell-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit beb9f53

Please sign in to comment.