From e1dd7e6db866cb83e768cb1e8c941b4597c8f11d Mon Sep 17 00:00:00 2001 From: Preston Date: Fri, 17 Apr 2020 23:17:45 -0400 Subject: [PATCH] Fix web build script and fix errors when running web version --- _scripts/webpack.web.config.js | 10 +++++++ src/index.ejs | 2 +- src/renderer/App.js | 1 + src/renderer/store/modules/settings.js | 29 +++++++++++++++--- src/renderer/store/modules/subscriptions.js | 21 ++++++++++--- src/renderer/views/Watch/Watch.js | 33 ++++++++++++--------- 6 files changed, 73 insertions(+), 23 deletions(-) diff --git a/_scripts/webpack.web.config.js b/_scripts/webpack.web.config.js index d66f4f7a..0529c014 100644 --- a/_scripts/webpack.web.config.js +++ b/_scripts/webpack.web.config.js @@ -53,6 +53,16 @@ const config = { { loader: 'css-loader', }, + { + loader: 'sass-loader', + options: { + // eslint-disable-next-line + implementation: require('sass'), + sassOptions: { + indentedSyntax: true + } + } + }, ], }, { diff --git a/src/index.ejs b/src/index.ejs index ac6ae92d..7cb00ad6 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -34,7 +34,7 @@ // Add this below content to your HTML page, or add the js file to your page at the very top to register service worker // Check compatibility for the browser we're running this in - if ("serviceWorker" in navigator) { + if ("serviceWorker" in navigator && (window && window.process && window.process.type !== 'renderer')) { if (navigator.serviceWorker.controller) { console.log("[PWA Builder] active service worker found, no need to register"); } else { diff --git a/src/renderer/App.js b/src/renderer/App.js index 79f2372c..cf14ce27 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -27,6 +27,7 @@ export default Vue.extend({ }, mounted: function () { this.$store.dispatch('grabUserSettings') + this.$store.commit('setUsingElectron', useElectron) let baseTheme = localStorage.getItem('baseTheme') let mainColor = localStorage.getItem('mainColor') diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index d33bdb81..b8a7ce91 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -1,10 +1,23 @@ -import electron from 'electron' import Datastore from 'nedb' -// TODO: Add logic for database when electron is not in use -const localDataStorage = electron.remote.app.getPath('userData') + +let dbLocation + +if (window && window.process && window.process.type === 'renderer') { + // Electron is being used + let dbLocation = localStorage.getItem('dbLocation') + + if (dbLocation === null) { + const electron = require('electron') + dbLocation = electron.remote.app.getPath('userData') + } + + dbLocation += '/settings.db' +} else { + dbLocation = 'settings.db' +} const settingsDb = new Datastore({ - filename: localDataStorage + '/settings.db', + filename: dbLocation, autoload: true }) @@ -35,6 +48,7 @@ const state = { debugMode: false, disctractionFreeMode: false, hideWatchedSubs: false, + usingElectron: true, profileList: [{ name: 'All Channels', color: '#304FFE' }], defaultProfile: 'All Channels' } @@ -118,6 +132,10 @@ const getters = { getDefaultQuality: () => { return state.defaultQuality + }, + + getUsingElectron: () => { + return state.usingElectron } } @@ -430,6 +448,9 @@ const mutations = { setHideWatchedSubs (state, hideWatchedSubs) { state.hideWatchedSubs = hideWatchedSubs }, + setUsingElectron (state, usingElectron) { + state.usingElectron = usingElectron + }, setVideoView (state, videoView) { state.videoView = videoView }, diff --git a/src/renderer/store/modules/subscriptions.js b/src/renderer/store/modules/subscriptions.js index 76abb26d..2d48dbfc 100644 --- a/src/renderer/store/modules/subscriptions.js +++ b/src/renderer/store/modules/subscriptions.js @@ -1,10 +1,23 @@ -import electron from 'electron' import Datastore from 'nedb' -// TODO: Add logic for database when electron is not in use -const localDataStorage = electron.remote.app.getPath('userData') + +let dbLocation + +if (window && window.process && window.process.type === 'renderer') { + // Electron is being used + let dbLocation = localStorage.getItem('dbLocation') + + if (dbLocation === null) { + const electron = require('electron') + dbLocation = electron.remote.app.getPath('userData') + } + + dbLocation += '/subscriptions.db' +} else { + dbLocation = 'subscriptions.db' +} const subDb = new Datastore({ - filename: localDataStorage + '/subscriptions.db', + filename: dbLocation, autoload: true }) diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index c9d0ae34..b173dd52 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -52,6 +52,10 @@ export default Vue.extend({ } }, computed: { + usingElectron: function () { + return this.$store.getters.getUsingElectron + }, + backendPreference: function () { return this.$store.getters.getBackendPreference }, @@ -76,18 +80,14 @@ export default Vue.extend({ return this.$store.getters.getForceLocalBackendForLegacy }, - videoDashUrl: function () { - return `${this.invidiousInstance}/api/manifest/dash/id/${this.videoId}.mpd` - }, - youtubeNoCookieEmbeddedFrame: function () { return `` }, dashSrc: function () { - let url = `${this.invidiousInstance}/api/manifest/dash/${this.videoId}.mpd` + let url = `${this.invidiousInstance}/api/manifest/dash/id/${this.videoId}.mpd` - if (this.proxyVideos) { + if (this.proxyVideos || !this.usingElectron) { url = url + '?local=true' } @@ -127,13 +127,17 @@ export default Vue.extend({ this.activeFormat = this.defaultVideoFormat - switch (this.backendPreference) { - case 'local': - this.getVideoInformationLocal() - break - case 'invidious': - this.getVideoInformationInvidious() - break + if (!this.usingElectron) { + this.getVideoInformationInvidious() + } else { + switch (this.backendPreference) { + case 'local': + this.getVideoInformationLocal() + break + case 'invidious': + this.getVideoInformationInvidious() + break + } } }, methods: { @@ -202,8 +206,9 @@ export default Vue.extend({ this.isLoading = false }) .catch(err => { + console.log('Error grabbing video data through local API') console.log(err) - if (this.backendPreference === 'local' && this.backendFallback) { + if (!this.usingElectron || (this.backendPreference === 'local' && this.backendFallback)) { console.log( 'Error getting data with local backend, falling back to Invidious' )