mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-10-24 13:57:39 -05:00
RTC-13831 Stop/restore C9Shell process when entering/leaving sleep/hibernation mode (#1708)
* RTC-13831 Stop C9Shell process when entering sleep/hibernation mode This will improve battery consumption and fix C9 issues (can't call, hang up, change DND mode...) * RTC-13831 Move C9ShellHandler methods sender/webContents param to a property
This commit is contained in:
1 parent
5d305e3eea
commit
0bc2618ba0
3 files changed
+24
-11
No files matched your search
@@ -62,6 +62,7 @@ interface IWebContents {
|
||||
}
|
||||
interface IPowerMonitor {
|
||||
getSystemIdleTime(): void;
|
||||
on(): void;
|
||||
}
|
||||
|
||||
const pathToConfigDir = (): string => {
|
||||
@@ -131,6 +132,7 @@ export const ipcMain: IIpcMain = {
|
||||
|
||||
export const powerMonitor: IPowerMonitor = {
|
||||
getSystemIdleTime: jest.fn().mockReturnValue(mockIdleTime),
|
||||
on: jest.fn(),
|
||||
};
|
||||
|
||||
export const ipcRenderer: IIpcRenderer = {
|
||||
|
||||
+21
-10
@@ -1,4 +1,4 @@
|
||||
import { app, WebContents } from 'electron';
|
||||
import { app, powerMonitor, WebContents } from 'electron';
|
||||
import { isDevEnv, isWindowsOS } from '../common/env';
|
||||
import { logger } from '../common/logger';
|
||||
|
||||
@@ -19,18 +19,31 @@ type StatusCallback = (status: IShellStatus) => void;
|
||||
class C9ShellHandler {
|
||||
private _c9shell: ChildProcess | undefined;
|
||||
private _curStatus: IShellStatus | undefined;
|
||||
private _sender: WebContents;
|
||||
private _statusCallback: StatusCallback | undefined;
|
||||
|
||||
constructor(sender: WebContents) {
|
||||
this._sender = sender;
|
||||
|
||||
powerMonitor.on('suspend', () => {
|
||||
this.terminateShell();
|
||||
});
|
||||
|
||||
powerMonitor.on('resume', () => {
|
||||
this.startShell();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the c9shell process
|
||||
*/
|
||||
public async startShell(sender: WebContents) {
|
||||
public async startShell() {
|
||||
if (this._attachExistingC9Shell()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._c9shell) {
|
||||
this._c9shell = await this._launchC9Shell(sender);
|
||||
this._c9shell = await this._launchC9Shell();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,13 +102,11 @@ class C9ShellHandler {
|
||||
/**
|
||||
* Launches the correct c9shell process
|
||||
*/
|
||||
private async _launchC9Shell(
|
||||
webContents: WebContents,
|
||||
): Promise<ChildProcess | undefined> {
|
||||
private async _launchC9Shell(): Promise<ChildProcess | undefined> {
|
||||
this._curStatus = undefined;
|
||||
const uniquePipeName = getGuid();
|
||||
const proxy = (
|
||||
await webContents.session.resolveProxy(webContents.getURL() ?? '')
|
||||
await this._sender.session.resolveProxy(this._sender.getURL() ?? '')
|
||||
).replace('PROXY ', '');
|
||||
|
||||
const c9ShellPath = isDevEnv
|
||||
@@ -162,19 +173,19 @@ export const loadC9Shell = async (sender: WebContents) => {
|
||||
return;
|
||||
}
|
||||
if (!c9ShellHandler) {
|
||||
c9ShellHandler = new C9ShellHandler();
|
||||
c9ShellHandler = new C9ShellHandler(sender);
|
||||
}
|
||||
c9ShellHandler.setStatusCallback((status: IShellStatus) => {
|
||||
logger.info('c9-shell: sending status', status);
|
||||
sender.send('c9-status-event', { status });
|
||||
});
|
||||
await c9ShellHandler.startShell(sender);
|
||||
await c9ShellHandler.startShell();
|
||||
};
|
||||
|
||||
/**
|
||||
* Terminates the C9 shell process asynchronously, if it is running.
|
||||
*/
|
||||
export const terminateC9Shell = (_sender: WebContents) => {
|
||||
export const terminateC9Shell = () => {
|
||||
if (!c9ShellHandler) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ ipcMain.on(
|
||||
await loadC9Shell(event.sender);
|
||||
break;
|
||||
case apiCmds.terminateCloud9:
|
||||
terminateC9Shell(event.sender);
|
||||
terminateC9Shell();
|
||||
break;
|
||||
case apiCmds.updateAndRestart:
|
||||
autoUpdate.updateAndRestart();
|
||||
|
||||
Reference in new issue
Block a user