From 38de1e0cf41b9d5527d405952e2d66e983ca2a5c Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 May 2021 20:37:32 +0200 Subject: Environmental variables for dev/production mode (#1455) * Restore ELECTRON_IS_DEV environment variable As part of migrating to @electron/remote from electron.remote, 296ce5ce6 removed the electron-is-dev package and with it the support of selecting dev/production mode with the ELECTRON_IS_DEV environmental variable. This commit restores support for this variable. Because even the newest version of the electron-is-dev package breaks in renderer processes, we instead query the environment ourselves. * Add support for NODE_ENV variable Also support NODE_ENV for specifying dev mode in addition to the ELECTRON_IS_DEV variable. This variable is used by e.g., the packaging in Arch Linux to trigger production mode with an explicit electron command line invocation: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=ferdi-git&id=61dc59e5eb19a2c9e8f9edaf0a63aaae72990a0b#n109 * Refactor environmental variable handling --- src/config.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/config.js') diff --git a/src/config.js b/src/config.js index 127dcd2dc..189959a4d 100644 --- a/src/config.js +++ b/src/config.js @@ -196,7 +196,23 @@ if (process.env.FERDI_APPDATA_DIR != null) { app.setPath('userData', path.join(app.getPath('appData'), app.name)); } -export const isDevMode = !app.isPackaged; +const ELECTRON_IS_DEV_VAR = 'ELECTRON_IS_DEV'; +const NODE_ENV_VAR = 'NODE_ENV'; + +// TODO Move this to environment.js and remove the re-export from there. +export const isDevMode = (() => { + const isEnvVarSet = name => name in process.env; + if (isEnvVarSet(ELECTRON_IS_DEV_VAR)) { + // Copied from https://github.com/sindresorhus/electron-is-dev/blob/f05330b856782dac7987b10859bfd95ea6a187a6/index.js + // but electron-is-dev breaks in a renderer process, so we use the app import from above instead. + const electronIsDev = process.env[ELECTRON_IS_DEV_VAR]; + return electronIsDev === 'true' || Number.parseInt(electronIsDev, 10) === 1; + } + if (isEnvVarSet(NODE_ENV_VAR)) { + return process.env[NODE_ENV_VAR] === 'development'; + } + return !app.isPackaged; +})(); if (isDevMode) { app.setPath('userData', path.join(app.getPath('appData'), `${app.name}Dev`)); } -- cgit v1.2.3-70-g09d2