From 62829b736afff00799887e1bad1296a51df5e5cb Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 15 Sep 2022 10:59:09 +0200 Subject: [PATCH] Electron variable at build time instead of at runtime (#2574) --- _scripts/webpack.renderer.config.js | 8 ++++---- _scripts/webpack.web.config.js | 8 ++++---- src/datastores/handlers/index.js | 3 +-- src/index.ejs | 4 ++-- src/renderer/App.js | 7 ++----- .../components/ft-video-player/ft-video-player.js | 14 +++++--------- .../general-settings/general-settings.js | 5 ----- src/renderer/components/top-nav/top-nav.js | 8 ++------ .../watch-video-live-chat/watch-video-live-chat.js | 6 +----- .../watch-video-playlist/watch-video-playlist.js | 6 +----- src/renderer/main.js | 2 +- src/renderer/store/modules/settings.js | 6 ++---- src/renderer/store/modules/utils.js | 11 ++++------- src/renderer/views/Channel/Channel.js | 8 ++------ src/renderer/views/Settings/Settings.js | 2 +- src/renderer/views/Subscriptions/Subscriptions.js | 6 +----- src/renderer/views/Trending/Trending.js | 9 +++------ src/renderer/views/Watch/Watch.js | 11 ++++------- 18 files changed, 40 insertions(+), 84 deletions(-) diff --git a/_scripts/webpack.renderer.config.js b/_scripts/webpack.renderer.config.js index b6085d4a..d1a9287d 100644 --- a/_scripts/webpack.renderer.config.js +++ b/_scripts/webpack.renderer.config.js @@ -109,7 +109,10 @@ const config = { global: isDevMode, }, plugins: [ - // new WriteFilePlugin(), + new webpack.DefinePlugin({ + 'process.env.PRODUCT_NAME': JSON.stringify(productName), + 'process.env.IS_ELECTRON': true + }), new HtmlWebpackPlugin({ excludeChunks: ['processTaskWorker'], filename: 'index.html', @@ -119,9 +122,6 @@ const config = { : false, }), new VueLoaderPlugin(), - new webpack.DefinePlugin({ - 'process.env.PRODUCT_NAME': JSON.stringify(productName), - }), new MiniCssExtractPlugin({ filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index 27320cb4..bafdf9b7 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -119,7 +119,10 @@ const config = { dns: 'empty' }, plugins: [ - // new WriteFilePlugin(), + new webpack.DefinePlugin({ + 'process.env.PRODUCT_NAME': JSON.stringify(productName), + 'process.env.IS_ELECTRON': false + }), new HtmlWebpackPlugin({ excludeChunks: ['processTaskWorker'], filename: 'index.html', @@ -127,9 +130,6 @@ const config = { nodeModules: false, }), new VueLoaderPlugin(), - new webpack.DefinePlugin({ - 'process.env.PRODUCT_NAME': JSON.stringify(productName), - }), new MiniCssExtractPlugin({ filename: isDevMode ? '[name].css' : '[name].[contenthash].css', chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css', diff --git a/src/datastores/handlers/index.js b/src/datastores/handlers/index.js index 0b1dc938..e96565d1 100644 --- a/src/datastores/handlers/index.js +++ b/src/datastores/handlers/index.js @@ -1,6 +1,5 @@ let handlers -const usingElectron = window?.process?.type === 'renderer' -if (usingElectron) { +if (process.env.IS_ELECTRON) { handlers = require('./electron').default } else { handlers = require('./web').default diff --git a/src/index.ejs b/src/index.ejs index f0dad7e0..e1f4040e 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -21,7 +21,7 @@