Skip to content

Commit

Permalink
Fix some development code not getting optimised out (#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue committed Sep 26, 2022
1 parent 8e72e7f commit fa8d423
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/index.ejs
Expand Up @@ -18,15 +18,16 @@

<body>
<div id="app"></div>
<% if (process.env.NODE_ENV !== 'development') { %>
<!-- Set `__static` path to static files in production -->
<script>
try {
if ('<%= process.env.NODE_ENV %>' !== 'development')
window.__static = require('path')
.join(__dirname, '/static')
.replace(/\\/g, '\\\\')
} catch {}
</script>
<% } %>

<script>
// This is the service worker with the Advanced caching
Expand Down
6 changes: 1 addition & 5 deletions src/renderer/App.js
Expand Up @@ -50,9 +50,6 @@ export default Vue.extend({
}
},
computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},
isOpen: function () {
return this.$store.getters.getIsSideNavOpen
},
Expand Down Expand Up @@ -148,7 +145,7 @@ export default Vue.extend({
this.grabUserSettings().then(async () => {
this.checkThemeSettings()

await this.fetchInvidiousInstances({ isDev: this.isDev })
await this.fetchInvidiousInstances()
if (this.defaultInvidiousInstance === '') {
await this.setRandomCurrentInvidiousInstance()
}
Expand Down Expand Up @@ -257,7 +254,6 @@ export default Vue.extend({

checkExternalPlayer: async function () {
const payload = {
isDev: this.isDev,
externalPlayer: this.externalPlayer
}
this.getExternalPlayerCmdArgumentsData(payload)
Expand Down
Expand Up @@ -21,10 +21,6 @@ export default Vue.extend({
return {}
},
computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},

externalPlayerNames: function () {
const fallbackNames = this.$store.getters.getExternalPlayerNames
const nameTranslationKeys = this.$store.getters.getExternalPlayerNameTranslationKeys
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/components/general-settings/general-settings.js
Expand Up @@ -61,9 +61,6 @@ export default Vue.extend({
}
},
computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},
currentInvidiousInstance: function () {
return this.$store.getters.getCurrentInvidiousInstance
},
Expand Down
Expand Up @@ -42,10 +42,6 @@ export default Vue.extend({
}
},
computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},

backendPreference: function () {
return this.$store.getters.getBackendPreference
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/store/modules/invidious.js
Expand Up @@ -21,7 +21,7 @@ const getters = {
}

const actions = {
async fetchInvidiousInstances({ commit }, payload) {
async fetchInvidiousInstances({ commit }) {
const requestUrl = 'https://api.invidious.io/instances.json'

let instances = []
Expand All @@ -43,7 +43,7 @@ const actions = {
// And fallback to hardcoded entry(s) if static file absent
const fileName = 'invidious-instances.json'
/* eslint-disable-next-line */
const fileLocation = payload.isDev ? './static/' : `${__dirname}/static/`
const fileLocation = process.env.NODE_ENV === 'development' ? './static/' : `${__dirname}/static/`
if (fs.existsSync(`${fileLocation}${fileName}`)) {
console.warn('reading static file for invidious instances')
const fileData = fs.readFileSync(`${fileLocation}${fileName}`)
Expand Down
1 change: 0 additions & 1 deletion src/renderer/store/modules/settings.js
Expand Up @@ -323,7 +323,6 @@ const stateWithSideEffects = {

i18n.locale = targetLocale
dispatch('getRegionData', {
isDev: process.env.NODE_ENV === 'development',
locale: targetLocale
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/store/modules/utils.js
Expand Up @@ -547,7 +547,7 @@ const actions = {
getRegionData ({ commit }, payload) {
let fileData
/* eslint-disable-next-line */
const fileLocation = payload.isDev ? './static/geolocations/' : `${__dirname}/static/geolocations/`
const fileLocation = process.env.NODE_ENV === 'development' ? './static/geolocations/' : `${__dirname}/static/geolocations/`
if (fs.existsSync(`${fileLocation}${payload.locale}`)) {
fileData = fs.readFileSync(`${fileLocation}${payload.locale}/countries.json`)
} else {
Expand Down Expand Up @@ -1028,7 +1028,7 @@ const actions = {
const fileName = 'external-player-map.json'
let fileData
/* eslint-disable-next-line */
const fileLocation = payload.isDev ? './static/' : `${__dirname}/static/`
const fileLocation = process.env.NODE_ENV === 'development' ? './static/' : `${__dirname}/static/`

if (fs.existsSync(`${fileLocation}${fileName}`)) {
fileData = fs.readFileSync(`${fileLocation}${fileName}`)
Expand Down
11 changes: 5 additions & 6 deletions src/renderer/views/Watch/Watch.js
Expand Up @@ -16,6 +16,8 @@ import WatchVideoRecommendations from '../../components/watch-video-recommendati
import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricted.vue'
import i18n from '../../i18n/index'

const isDev = process.env.NODE_ENV === 'development'

export default Vue.extend({
name: 'Watch',
components: {
Expand Down Expand Up @@ -86,9 +88,6 @@ export default Vue.extend({
}
},
computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},
historyCache: function () {
return this.$store.getters.getHistoryCache
},
Expand Down Expand Up @@ -1127,7 +1126,7 @@ export default Vue.extend({

if (this.removeVideoMetaFiles) {
const userData = await this.getUserDataPath()
if (this.isDev) {
if (isDev) {
const dashFileLocation = `static/dashFiles/${videoId}.xml`
const vttFileLocation = `static/storyboards/${videoId}.vtt`
// only delete the file it actually exists
Expand Down Expand Up @@ -1174,7 +1173,7 @@ export default Vue.extend({
const userData = await this.getUserDataPath()
let fileLocation
let uriSchema
if (this.isDev) {
if (isDev) {
fileLocation = `static/dashFiles/${this.videoId}.xml`
uriSchema = `dashFiles/${this.videoId}.xml`
// if the location does not exist, writeFileSync will not create the directory, so we have to do that manually
Expand Down Expand Up @@ -1255,7 +1254,7 @@ export default Vue.extend({

// Dev mode doesn't have access to the file:// schema, so we access
// storyboards differently when run in dev
if (this.isDev) {
if (isDev) {
fileLocation = `static/storyboards/${this.videoId}.vtt`
uriSchema = `storyboards/${this.videoId}.vtt`
// if the location does not exist, writeFileSync will not create the directory, so we have to do that manually
Expand Down

0 comments on commit fa8d423

Please sign in to comment.