From 8207ac30bae87616f3702702f062b10b57ba8379 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 12 Jan 2023 19:41:27 +0100 Subject: [PATCH] Add an IS_ELECTRON_MAIN define instead of runtime detection --- _scripts/webpack.main.config.js | 7 ++++++- _scripts/webpack.renderer.config.js | 1 + _scripts/webpack.web.config.js | 3 ++- src/datastores/index.js | 3 +-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/_scripts/webpack.main.config.js b/_scripts/webpack.main.config.js index c787cf02b474e..0f3c706c6a973 100644 --- a/_scripts/webpack.main.config.js +++ b/_scripts/webpack.main.config.js @@ -1,4 +1,5 @@ const path = require('path') +const webpack = require('webpack') const CopyWebpackPlugin = require('copy-webpack-plugin') const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin') @@ -33,7 +34,11 @@ const config = { __dirname: isDevMode, __filename: isDevMode }, - plugins: [], + plugins: [ + new webpack.DefinePlugin({ + 'process.env.IS_ELECTRON_MAIN': true + }) + ], output: { filename: '[name].js', libraryTarget: 'commonjs2', diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index 21258d9e4a806..950d421ea46b7 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -112,6 +112,7 @@ const config = { processLocalesPlugin, new webpack.DefinePlugin({ 'process.env.IS_ELECTRON': true, + 'process.env.IS_ELECTRON_MAIN': false, 'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames) }), new HtmlWebpackPlugin({ diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index a61bdbc2d1f0e..64e21f2e25130 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -114,7 +114,8 @@ const config = { }, plugins: [ new webpack.DefinePlugin({ - 'process.env.IS_ELECTRON': false + 'process.env.IS_ELECTRON': false, + 'process.env.IS_ELECTRON_MAIN': false }), new webpack.ProvidePlugin({ process: 'process/browser', diff --git a/src/datastores/index.js b/src/datastores/index.js index 713a0ea304641..a54fd0b4ad3c0 100644 --- a/src/datastores/index.js +++ b/src/datastores/index.js @@ -2,8 +2,7 @@ import Datastore from 'nedb-promises' let dbPath = null -const isElectronMain = !!process?.versions?.electron -if (isElectronMain) { +if (process.env.IS_ELECTRON_MAIN) { const { app } = require('electron') const { join } = require('path') const userDataPath = app.getPath('userData') // This is based on the user's OS