Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTC-13887 Add C9 shell logs #1739

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/app/c9-shell-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class C9ShellHandler {
this._sender = sender;

powerMonitor.on('suspend', () => {
logger.info('c9-shell-handler: suspend');
this.terminateShell();
});

powerMonitor.on('resume', () => {
logger.info('c9-shell-handler: resume');
this.startShell();
});
}
Expand All @@ -41,17 +43,22 @@ class C9ShellHandler {
*/
public async startShell() {
if (this._attachExistingC9Shell()) {
logger.info('c9-shell-handler: _attachExistingC9Shell, skip start');
return;
}

if (this._isStarting) {
logger.info('c9-shell-handler: _isStarting, skip start');
return;
}

this._isStarting = true;

if (!this._c9shell) {
logger.info('c9-shell-handler: start');
this._c9shell = await this._launchC9Shell(); // _c9shell won't be set until the promise is resolved/rejected
} else {
logger.info('c9-shell-handler: _c9shell, skip start');
}

this._isStarting = false;
Expand All @@ -72,13 +79,16 @@ class C9ShellHandler {
*/
public terminateShell() {
if (this._isTerminating) {
logger.info('c9-shell-handler: _isTerminating, skip terminate');
return;
}

if (!this._c9shell) {
logger.info('c9-shell-handler: no _c9shell, skip terminate');
return;
}

logger.info('c9-shell-handler: terminate');
this._isTerminating = true;
this._c9shell.kill();
}
Expand Down Expand Up @@ -162,6 +172,7 @@ class C9ShellHandler {
'--c9args=',
false,
);

const customC9ShellArgList = customC9ShellArgs
? customC9ShellArgs.substring(9).split(' ')
: [];
Expand All @@ -179,27 +190,29 @@ class C9ShellHandler {
c9ShellPath,
customC9ShellArgList,
);

this._updateStatus({ status: 'starting' });
const c9Shell = spawn(c9ShellPath, customC9ShellArgList, { stdio: 'pipe' });

const c9Shell = spawn(c9ShellPath, customC9ShellArgList, {
stdio: 'pipe',
});
c9Shell.on('close', (code) => {
logger.info('c9-shell: closed with code', code);
this._c9shell = undefined;
this._isTerminating = false;
this._updateStatus({ status: 'inactive' });
});

c9Shell.on('spawn', () => {
logger.info('c9-shell: shell process successfully spawned');
this._updateStatus({
status: 'active',
pipeName: 'symphony-c9-' + uniquePipeName,
});
});

c9Shell.stdout.on('data', (data) => {
logger.info(`c9-shell: ${data.toString().trim()}`);
});

c9Shell.stderr.on('data', (data) => {
logger.error(`c9-shell: ${data.toString().trim()}`);
});
Expand All @@ -225,6 +238,7 @@ export const loadC9Shell = async (sender: WebContents) => {
logger.info('c9-shell: sending status', status);
sender.send('c9-status-event', { status });
});

await c9ShellHandler.startShell();
};

Expand Down