Skip to content

Commit

Permalink
Fix imports of the "electron" module that are missing an Electron gua…
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Apr 14, 2024
1 parent 372bc1b commit bb7d90b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 97 deletions.
1 change: 0 additions & 1 deletion _scripts/webpack.web.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const config = {
filename: '[name].js',
},
externals: {
electron: '{}',
'youtubei.js': '{}'
},
module: {
Expand Down
20 changes: 11 additions & 9 deletions src/renderer/components/download-settings/download-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 8 additions & 3 deletions src/renderer/components/proxy-settings/proxy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = ''
Expand Down
14 changes: 8 additions & 6 deletions src/renderer/components/theme-settings/theme-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
153 changes: 77 additions & 76 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/renderer/store/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
}

Expand Down

0 comments on commit bb7d90b

Please sign in to comment.