From 654441ce8cd1561dcb61808d16f5e2ea6b5bf5f2 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 6 Jul 2017 18:05:36 +0530 Subject: [PATCH 1/2] Implemented method to turn off sandbox mode when the app is running in node env --- js/notify/electron-notify.js | 4 ++-- js/windowMgr.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 950302d9..6a9929b6 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -131,8 +131,8 @@ let config = { acceptFirstMouse: true, webPreferences: { preload: path.join(__dirname, 'electron-notify-preload.js'), - sandbox: true, - nodeIntegration: false + sandbox: !process.env.NODE_ENV, + nodeIntegration: process.env.NODE_ENV } } } diff --git a/js/windowMgr.js b/js/windowMgr.js index decba734..096da835 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -80,8 +80,8 @@ function doCreateMainWindow(initialUrl, initialBounds) { minHeight: MIN_HEIGHT, alwaysOnTop: false, webPreferences: { - sandbox: true, - nodeIntegration: false, + sandbox: !process.env.NODE_ENV, + nodeIntegration: process.env.NODE_ENV, preload: preloadMainScript, } }; From aec84b823b97f90ccc72ea2b7804b6c7fc89e349 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Mon, 10 Jul 2017 13:09:10 +0530 Subject: [PATCH 2/2] Electron-93 - Moved the node env const to misc --- js/notify/electron-notify.js | 6 +++--- js/utils/misc.js | 5 ++++- js/windowMgr.js | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 6a9929b6..bf053d41 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -15,7 +15,7 @@ const electron = require('electron'); const app = electron.app; const BrowserWindow = electron.BrowserWindow; const ipc = electron.ipcMain; -const { isMac } = require('../utils/misc'); +const { isMac, isNodeEnv } = require('../utils/misc'); const log = require('../log.js'); const logLevels = require('../enums/logLevels.js'); @@ -131,8 +131,8 @@ let config = { acceptFirstMouse: true, webPreferences: { preload: path.join(__dirname, 'electron-notify-preload.js'), - sandbox: !process.env.NODE_ENV, - nodeIntegration: process.env.NODE_ENV + sandbox: !isNodeEnv, + nodeIntegration: isNodeEnv } } } diff --git a/js/utils/misc.js b/js/utils/misc.js index 8f0f0b75..b44794c0 100644 --- a/js/utils/misc.js +++ b/js/utils/misc.js @@ -5,7 +5,10 @@ const isDevEnv = process.env.ELECTRON_DEV ? const isMac = (process.platform === 'darwin'); +const isNodeEnv = !!process.env.NODE_ENV; + module.exports = { isDevEnv: isDevEnv, - isMac: isMac + isMac: isMac, + isNodeEnv: isNodeEnv }; diff --git a/js/windowMgr.js b/js/windowMgr.js index 096da835..def70ddb 100644 --- a/js/windowMgr.js +++ b/js/windowMgr.js @@ -19,6 +19,7 @@ const eventEmitter = require('./eventEmitter'); const throttle = require('./utils/throttle.js'); const { getConfigField, updateConfigField } = require('./config.js'); +const { isNodeEnv } = require('./utils/misc'); //context menu const contextMenu = require('./menus/contextMenu.js'); @@ -80,8 +81,8 @@ function doCreateMainWindow(initialUrl, initialBounds) { minHeight: MIN_HEIGHT, alwaysOnTop: false, webPreferences: { - sandbox: !process.env.NODE_ENV, - nodeIntegration: process.env.NODE_ENV, + sandbox: !isNodeEnv, + nodeIntegration: isNodeEnv, preload: preloadMainScript, } };