From 1934120e463a9ffc9574ec904d25dee5a30ae1ef Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 3 Mar 2021 11:13:35 -0800 Subject: [PATCH] Disable Dev Tools in production releases `--enable-dev-tools` will bring it back. --- app/menu.js | 19 ++++++++++++------- main.js | 15 +++++++++++++++ test/app/menu_test.js | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/menu.js b/app/menu.js index 23979d5e39..10e2a71372 100644 --- a/app/menu.js +++ b/app/menu.js @@ -10,6 +10,7 @@ exports.createTemplate = (options, messages) => { const { isBeta, + devTools, includeSetup, openContactUs, openForums, @@ -118,13 +119,17 @@ exports.createTemplate = (options, messages) => { label: messages.debugLog.message, click: showDebugLog, }, - { - type: 'separator', - }, - { - role: 'toggledevtools', - label: messages.viewMenuToggleDevTools.message, - }, + ...(devTools + ? [ + { + type: 'separator', + }, + { + role: 'toggledevtools', + label: messages.viewMenuToggleDevTools.message, + }, + ] + : []), ], }, { diff --git a/main.js b/main.js index ecafd86190..7126fec468 100644 --- a/main.js +++ b/main.js @@ -112,9 +112,16 @@ const { getTitleBarVisibility, TitleBarVisibility, } = require('./ts/types/Settings'); +const { Environment } = require('./ts/environment'); let appStartInitialSpellcheckSetting = true; +const defaultWebPrefs = { + devTools: + process.argv.some(arg => arg === '--enable-dev-tools') || + config.environment !== Environment.Production, +}; + async function getSpellCheckSetting() { const json = await sql.getItemById('spell-check'); @@ -313,6 +320,7 @@ async function createWindow() { ? '#ffffff' // Tests should always be rendered on a white background : '#3a76f0', webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -667,6 +675,7 @@ function showAbout() { backgroundColor: '#3a76f0', show: false, webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -721,6 +730,7 @@ function showSettingsWindow() { show: false, modal: true, webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -790,6 +800,7 @@ async function showStickerCreator() { backgroundColor: '#3a76f0', show: false, webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -844,6 +855,7 @@ async function showDebugLogWindow() { show: false, modal: true, webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -894,6 +906,7 @@ function showPermissionsPopupWindow(forCalling, forCamera) { show: false, modal: true, webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, nodeIntegrationInWorker: false, contextIsolation: false, @@ -1027,6 +1040,7 @@ app.on('ready', async () => { frame: false, backgroundColor: '#3a76f0', webPreferences: { + ...defaultWebPrefs, nodeIntegration: false, preload: path.join(__dirname, 'loading_preload.js'), }, @@ -1134,6 +1148,7 @@ function setupMenu(options) { showAbout, showSettings: showSettingsWindow, showStickerCreator, + showDevTools: defaultWebPrefs.devTools, openContactUs, openJoinTheBeta, openReleaseNotes, diff --git a/test/app/menu_test.js b/test/app/menu_test.js index a9aa783193..4e3feb7a32 100644 --- a/test/app/menu_test.js +++ b/test/app/menu_test.js @@ -50,6 +50,7 @@ describe('SignalMenu', () => { }; const options = { isBeta: false, + devTools: true, openContactUs: null, openForums: null, openJoinTheBeta: null,