Add an IS_ELECTRON_MAIN define instead of runtime detection (#3056)

This commit is contained in:
absidue 2023-01-13 17:54:05 +01:00 committed by GitHub
parent c1462dc3d1
commit 7becd36120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 4 deletions

View File

@ -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',

View File

@ -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({

View File

@ -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',

View File

@ -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