SDA-2352: add new api for restarting sda (#1050)

This commit is contained in:
Vishwas Shashidhar
2020-08-18 13:17:15 +05:30
committed by GitHub
parent b16801c485
commit 2e7f986975
7 changed files with 53 additions and 2 deletions
+19
View File
@@ -0,0 +1,19 @@
import { app } from 'electron';
import { logger } from '../common/logger';
class AppStateHandler {
/**
* Restarts the app with the command line arguments
* passed from the previous session
*/
public restart() {
logger.info(`Restarting app as per instruction from SFE`);
app.relaunch();
app.exit();
}
}
const appStateHandler = new AppStateHandler();
export default appStateHandler;
+4
View File
@@ -5,6 +5,7 @@ import { LocaleType } from '../common/i18n';
import { logger } from '../common/logger';
import { activityDetection } from './activity-detection';
import { analytics } from './analytics-handler';
import appStateHandler from './app-state-handler';
import { CloudConfigDataTypes, config, ICloudConfig } from './config-handler';
import { downloadHandler } from './download-handler';
import { memoryMonitor } from './memory-monitor';
@@ -164,6 +165,9 @@ ipcMain.on(apiName.symphonyApi, async (event: Electron.IpcMainEvent, arg: IApiAr
case apiCmds.clearDownloadedItems:
downloadHandler.clearDownloadedItems();
break;
case apiCmds.restartApp:
appStateHandler.restart();
break;
case apiCmds.isMisspelled:
if (typeof arg.word === 'string') {
event.returnValue = windowHandler.spellchecker ? windowHandler.spellchecker.isMisspelled(arg.word) : false;
+1
View File
@@ -42,6 +42,7 @@ export enum apiCmds {
openDownloadedItem = 'open-downloaded-item',
showDownloadedItem = 'show-downloaded-item',
clearDownloadedItems = 'clear-downloaded-items',
restartApp = 'restart-app',
}
export enum apiName {
+10
View File
@@ -207,6 +207,7 @@
<td id="cpu-arch"></td>
</tr>
</table>
<input type="button" id="restart-app" value="Restart App"/>
</body>
<script>
@@ -251,6 +252,7 @@
registerRestartFloater: 'register-restart-floater',
getCPUUsage: 'get-cpu-usage',
checkMediaPermission: 'check-media-permission',
restartApp: 'restart-app',
};
let requestId = 0;
@@ -910,5 +912,13 @@
}
});
document.getElementById('restart-app').addEventListener('click', () => {
if (window.ssf) {
window.ssf.restartApp();
} else {
postMessage(apiCmds.restartApp);
}
});
</script>
</html>
+5 -2
View File
@@ -122,6 +122,9 @@ export class AppBridge {
case apiCmds.clearDownloadedItems:
ssf.clearDownloadedItems();
break;
case apiCmds.restartApp:
ssf.restartApp();
break;
case apiCmds.setLocale:
if (typeof data === 'string') {
ssf.setLocale(data as string);
@@ -161,13 +164,13 @@ export class AppBridge {
ssf.closeScreenSharingIndicator(data.streamId as string);
break;
case apiCmds.getMediaSource:
ssf.getMediaSource(data as ICustomSourcesOptions, this.callbackHandlers.onMediaSourceCallback);
await ssf.getMediaSource(data as ICustomSourcesOptions, this.callbackHandlers.onMediaSourceCallback);
break;
case apiCmds.notification:
notification.showNotification(data as INotificationData, this.callbackHandlers.onNotificationCallback);
break;
case apiCmds.closeNotification:
notification.hideNotification(data as number);
await notification.hideNotification(data as number);
break;
case apiCmds.showNotificationSettings:
ssf.showNotificationSettings();
+1
View File
@@ -84,6 +84,7 @@ if (ssfWindow.ssf) {
checkMediaPermission: ssfWindow.ssf.checkMediaPermission,
showNotification: notification.showNotification,
closeNotification: notification.hideNotification,
restartApp: ssfWindow.ssf.restartApp,
});
}
+13
View File
@@ -123,6 +123,12 @@ const throttledClearDownloadedItems = throttle(() => {
});
}, 1000);
const throttledRestart = throttle(() => {
ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.restartApp,
});
}, 1000);
let cryptoLib: ICryptoLib | null;
try {
cryptoLib = remote.require('../app/crypto-handler.js').cryptoLibrary;
@@ -546,6 +552,13 @@ export class SSFApi {
throttledClearDownloadedItems();
}
/**
* Restart the app
*/
public restartApp(): void {
throttledRestart();
}
/**
* get CPU usage
*/