diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index 0badc63a748d9..c06679910433c 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -25,7 +25,6 @@ const config = { filename: '[name].js', }, externals: { - electron: '{}', 'youtubei.js': '{}' }, module: { diff --git a/src/renderer/components/download-settings/download-settings.js b/src/renderer/components/download-settings/download-settings.js index de00756b4be8b..a0ad9efa067da 100644 --- a/src/renderer/components/download-settings/download-settings.js +++ b/src/renderer/components/download-settings/download-settings.js @@ -6,7 +6,6 @@ import FtSelect from '../ft-select/ft-select.vue' import FtButton from '../ft-button/ft-button.vue' import FtInput from '../ft-input/ft-input.vue' import { mapActions } from 'vuex' -import { ipcRenderer } from 'electron' import { IpcChannels } from '../../../constants' export default defineComponent({ @@ -48,16 +47,19 @@ export default defineComponent({ handleDownloadingSettingChange: function (value) { this.updateDownloadAskPath(value) }, - chooseDownloadingFolder: async function() { - // only use with electron - const folder = await ipcRenderer.invoke( - IpcChannels.SHOW_OPEN_DIALOG, - { properties: ['openDirectory'] } - ) + chooseDownloadingFolder: async function () { + if (process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') - if (folder.canceled) return + const folder = await ipcRenderer.invoke( + IpcChannels.SHOW_OPEN_DIALOG, + { properties: ['openDirectory'] } + ) - this.updateDownloadFolderPath(folder.filePaths[0]) + if (folder.canceled) return + + this.updateDownloadFolderPath(folder.filePaths[0]) + } }, ...mapActions([ 'updateDownloadAskPath', diff --git a/src/renderer/components/proxy-settings/proxy-settings.js b/src/renderer/components/proxy-settings/proxy-settings.js index c9a0139b953c3..b985c39d60d29 100644 --- a/src/renderer/components/proxy-settings/proxy-settings.js +++ b/src/renderer/components/proxy-settings/proxy-settings.js @@ -8,7 +8,6 @@ import FtInput from '../ft-input/ft-input.vue' import FtLoader from '../ft-loader/ft-loader.vue' import FtFlexBox from '../ft-flex-box/ft-flex-box.vue' -import { ipcRenderer } from 'electron' import debounce from 'lodash.debounce' import { IpcChannels } from '../../../constants' @@ -125,11 +124,17 @@ export default defineComponent({ }, enableProxy: function () { - ipcRenderer.send(IpcChannels.ENABLE_PROXY, this.proxyUrl) + if (process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') + ipcRenderer.send(IpcChannels.ENABLE_PROXY, this.proxyUrl) + } }, disableProxy: function () { - ipcRenderer.send(IpcChannels.DISABLE_PROXY) + if (process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') + ipcRenderer.send(IpcChannels.DISABLE_PROXY) + } this.dataAvailable = false this.proxyIp = '' diff --git a/src/renderer/components/theme-settings/theme-settings.js b/src/renderer/components/theme-settings/theme-settings.js index d53bf2f92784a..5e9d268b60e4e 100644 --- a/src/renderer/components/theme-settings/theme-settings.js +++ b/src/renderer/components/theme-settings/theme-settings.js @@ -146,12 +146,14 @@ export default defineComponent({ return } - this.updateDisableSmoothScrolling( - this.disableSmoothScrollingToggleValue - ).then(() => { - const { ipcRenderer } = require('electron') - ipcRenderer.send('relaunchRequest') - }) + if (process.env.IS_ELECTRON) { + this.updateDisableSmoothScrolling( + this.disableSmoothScrollingToggleValue + ).then(() => { + const { ipcRenderer } = require('electron') + ipcRenderer.send('relaunchRequest') + }) + } }, ...mapActions([ diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index 7aa40616c2f12..cb07106db14d8 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -471,101 +471,102 @@ const customActions = { // Should be a root action, but we'll tolerate setupListenersToSyncWindows: ({ commit, dispatch, getters }) => { - // Already known to be Electron, no need to check - const { ipcRenderer } = require('electron') - - ipcRenderer.on(IpcChannels.SYNC_SETTINGS, (_, { event, data }) => { - switch (event) { - case SyncEvents.GENERAL.UPSERT: - if (getters.settingHasSideEffects(data._id)) { - dispatch(defaultSideEffectsTriggerId(data._id), data.value) - } + if (process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') - commit(defaultMutationId(data._id), data.value) - break + ipcRenderer.on(IpcChannels.SYNC_SETTINGS, (_, { event, data }) => { + switch (event) { + case SyncEvents.GENERAL.UPSERT: + if (getters.settingHasSideEffects(data._id)) { + dispatch(defaultSideEffectsTriggerId(data._id), data.value) + } - default: - console.error('settings: invalid sync event received') - } - }) + commit(defaultMutationId(data._id), data.value) + break - ipcRenderer.on(IpcChannels.SYNC_HISTORY, (_, { event, data }) => { - switch (event) { - case SyncEvents.GENERAL.UPSERT: - commit('upsertToHistoryCache', data) - break + default: + console.error('settings: invalid sync event received') + } + }) - case SyncEvents.HISTORY.UPDATE_WATCH_PROGRESS: - commit('updateRecordWatchProgressInHistoryCache', data) - break + ipcRenderer.on(IpcChannels.SYNC_HISTORY, (_, { event, data }) => { + switch (event) { + case SyncEvents.GENERAL.UPSERT: + commit('upsertToHistoryCache', data) + break - case SyncEvents.HISTORY.UPDATE_PLAYLIST: - commit('updateRecordLastViewedPlaylistIdInHistoryCache', data) - break + case SyncEvents.HISTORY.UPDATE_WATCH_PROGRESS: + commit('updateRecordWatchProgressInHistoryCache', data) + break - case SyncEvents.GENERAL.DELETE: - commit('removeFromHistoryCacheById', data) - break + case SyncEvents.HISTORY.UPDATE_PLAYLIST: + commit('updateRecordLastViewedPlaylistIdInHistoryCache', data) + break - case SyncEvents.GENERAL.DELETE_ALL: - commit('setHistoryCacheSorted', []) - commit('setHistoryCacheById', {}) - break + case SyncEvents.GENERAL.DELETE: + commit('removeFromHistoryCacheById', data) + break - default: - console.error('history: invalid sync event received') - } - }) + case SyncEvents.GENERAL.DELETE_ALL: + commit('setHistoryCacheSorted', []) + commit('setHistoryCacheById', {}) + break - ipcRenderer.on(IpcChannels.SYNC_PROFILES, (_, { event, data }) => { - switch (event) { - case SyncEvents.GENERAL.CREATE: - commit('addProfileToList', data) - break + default: + console.error('history: invalid sync event received') + } + }) - case SyncEvents.GENERAL.UPSERT: - commit('upsertProfileToList', data) - break + ipcRenderer.on(IpcChannels.SYNC_PROFILES, (_, { event, data }) => { + switch (event) { + case SyncEvents.GENERAL.CREATE: + commit('addProfileToList', data) + break - case SyncEvents.GENERAL.DELETE: - commit('removeProfileFromList', data) - break + case SyncEvents.GENERAL.UPSERT: + commit('upsertProfileToList', data) + break - default: - console.error('profiles: invalid sync event received') - } - }) + case SyncEvents.GENERAL.DELETE: + commit('removeProfileFromList', data) + break - ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, { event, data }) => { - switch (event) { - case SyncEvents.GENERAL.CREATE: - commit('addPlaylists', data) - break + default: + console.error('profiles: invalid sync event received') + } + }) - case SyncEvents.GENERAL.DELETE: - commit('removePlaylist', data) - break + ipcRenderer.on(IpcChannels.SYNC_PLAYLISTS, (_, { event, data }) => { + switch (event) { + case SyncEvents.GENERAL.CREATE: + commit('addPlaylists', data) + break - case SyncEvents.GENERAL.UPSERT: - commit('upsertPlaylistToList', data) - break + case SyncEvents.GENERAL.DELETE: + commit('removePlaylist', data) + break - case SyncEvents.PLAYLISTS.UPSERT_VIDEO: - commit('addVideo', data) - break + case SyncEvents.GENERAL.UPSERT: + commit('upsertPlaylistToList', data) + break - case SyncEvents.PLAYLISTS.UPSERT_VIDEOS: - commit('addVideos', data) - break + case SyncEvents.PLAYLISTS.UPSERT_VIDEO: + commit('addVideo', data) + break - case SyncEvents.PLAYLISTS.DELETE_VIDEO: - commit('removeVideo', data) - break + case SyncEvents.PLAYLISTS.UPSERT_VIDEOS: + commit('addVideos', data) + break - default: - console.error('playlists: invalid sync event received') - } - }) + case SyncEvents.PLAYLISTS.DELETE_VIDEO: + commit('removeVideo', data) + break + + default: + console.error('playlists: invalid sync event received') + } + }) + } } } diff --git a/src/renderer/store/modules/utils.js b/src/renderer/store/modules/utils.js index 0a52ca7c44aef..c99290f20f0d3 100644 --- a/src/renderer/store/modules/utils.js +++ b/src/renderer/store/modules/utils.js @@ -728,8 +728,10 @@ const actions = { showToast(i18n.t('Video.External Player.OpeningTemplate', { videoOrPlaylist, externalPlayer })) - const { ipcRenderer } = require('electron') - ipcRenderer.send(IpcChannels.OPEN_IN_EXTERNAL_PLAYER, { executable, args }) + if (process.env.IS_ELECTRON) { + const { ipcRenderer } = require('electron') + ipcRenderer.send(IpcChannels.OPEN_IN_EXTERNAL_PLAYER, { executable, args }) + } } }