From 2f00b7dba153eaa106e0b5b5782e75de11937ff0 Mon Sep 17 00:00:00 2001 From: Alfred Dagenais Date: Mon, 12 Oct 2020 16:35:21 -0400 Subject: [PATCH] CHG: Ajustement from javascript error --- lib/api.js | 3 +++ lib/application.js | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index 73554850b..737ee69c9 100644 --- a/lib/api.js +++ b/lib/api.js @@ -139,6 +139,7 @@ Api.prototype.loadApi = function () { function addMainProcessModules() { api.electron.remote = {}; + if (typeof electron.remote !== 'object') return; Object.getOwnPropertyNames(electron.remote).forEach(function (key) { if (ignoreModule(key)) return; if (isRemoteFunction(key)) { @@ -161,6 +162,7 @@ Api.prototype.loadApi = function () { } function addBrowserWindow() { + if (typeof electron.remote !== 'object') return; const currentWindow = electron.remote.getCurrentWindow(); for (const name in currentWindow) { if (ignoreApi(name)) continue; @@ -172,6 +174,7 @@ Api.prototype.loadApi = function () { } function addWebContents() { + if (typeof electron.remote !== 'object') return; const webContents = electron.remote.getCurrentWebContents(); for (const name in webContents) { if (ignoreApi(name)) continue; diff --git a/lib/application.js b/lib/application.js index f57d33308..34686708e 100644 --- a/lib/application.js +++ b/lib/application.js @@ -88,7 +88,26 @@ Application.prototype.stop = function () { }; if (self.api.nodeIntegration) { - self.client.electron.remote.app.quit().then(endClient, reject); + // Check if electron remote app has really a quit() function + if ( + Object.prototype.hasOwnProperty.call(self.client.electron, 'remote') && + Object.prototype.hasOwnProperty.call( + self.client.electron.remote, + 'app' + ) && + typeof self.client.electron.remote.app.quit === 'function' + ) { + self.client.electron.remote.app.quit().then(endClient, reject); + } else { + const fakeAppQuit = new Promise(function (resolve, reject) { + try { + resolve(); + } catch (error) { + reject(Error('fakeAppQuit Promise not valid')); + } + }); + fakeAppQuit.then(endClient, reject); + } } else { self.client .windowByIndex(0)