Fix web build script and fix errors when running web version

This commit is contained in:
Preston 2020-04-17 23:17:45 -04:00
parent 320c305949
commit e1dd7e6db8
6 changed files with 73 additions and 23 deletions

View File

@ -53,6 +53,16 @@ const config = {
{ {
loader: 'css-loader', loader: 'css-loader',
}, },
{
loader: 'sass-loader',
options: {
// eslint-disable-next-line
implementation: require('sass'),
sassOptions: {
indentedSyntax: true
}
}
},
], ],
}, },
{ {

View File

@ -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 // 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 // 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) { if (navigator.serviceWorker.controller) {
console.log("[PWA Builder] active service worker found, no need to register"); console.log("[PWA Builder] active service worker found, no need to register");
} else { } else {

View File

@ -27,6 +27,7 @@ export default Vue.extend({
}, },
mounted: function () { mounted: function () {
this.$store.dispatch('grabUserSettings') this.$store.dispatch('grabUserSettings')
this.$store.commit('setUsingElectron', useElectron)
let baseTheme = localStorage.getItem('baseTheme') let baseTheme = localStorage.getItem('baseTheme')
let mainColor = localStorage.getItem('mainColor') let mainColor = localStorage.getItem('mainColor')

View File

@ -1,10 +1,23 @@
import electron from 'electron'
import Datastore from 'nedb' 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({ const settingsDb = new Datastore({
filename: localDataStorage + '/settings.db', filename: dbLocation,
autoload: true autoload: true
}) })
@ -35,6 +48,7 @@ const state = {
debugMode: false, debugMode: false,
disctractionFreeMode: false, disctractionFreeMode: false,
hideWatchedSubs: false, hideWatchedSubs: false,
usingElectron: true,
profileList: [{ name: 'All Channels', color: '#304FFE' }], profileList: [{ name: 'All Channels', color: '#304FFE' }],
defaultProfile: 'All Channels' defaultProfile: 'All Channels'
} }
@ -118,6 +132,10 @@ const getters = {
getDefaultQuality: () => { getDefaultQuality: () => {
return state.defaultQuality return state.defaultQuality
},
getUsingElectron: () => {
return state.usingElectron
} }
} }
@ -430,6 +448,9 @@ const mutations = {
setHideWatchedSubs (state, hideWatchedSubs) { setHideWatchedSubs (state, hideWatchedSubs) {
state.hideWatchedSubs = hideWatchedSubs state.hideWatchedSubs = hideWatchedSubs
}, },
setUsingElectron (state, usingElectron) {
state.usingElectron = usingElectron
},
setVideoView (state, videoView) { setVideoView (state, videoView) {
state.videoView = videoView state.videoView = videoView
}, },

View File

@ -1,10 +1,23 @@
import electron from 'electron'
import Datastore from 'nedb' 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({ const subDb = new Datastore({
filename: localDataStorage + '/subscriptions.db', filename: dbLocation,
autoload: true autoload: true
}) })

View File

@ -52,6 +52,10 @@ export default Vue.extend({
} }
}, },
computed: { computed: {
usingElectron: function () {
return this.$store.getters.getUsingElectron
},
backendPreference: function () { backendPreference: function () {
return this.$store.getters.getBackendPreference return this.$store.getters.getBackendPreference
}, },
@ -76,18 +80,14 @@ export default Vue.extend({
return this.$store.getters.getForceLocalBackendForLegacy return this.$store.getters.getForceLocalBackendForLegacy
}, },
videoDashUrl: function () {
return `${this.invidiousInstance}/api/manifest/dash/id/${this.videoId}.mpd`
},
youtubeNoCookieEmbeddedFrame: function () { youtubeNoCookieEmbeddedFrame: function () {
return `<iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/${this.videoId}?rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>` return `<iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/${this.videoId}?rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>`
}, },
dashSrc: function () { 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' url = url + '?local=true'
} }
@ -127,13 +127,17 @@ export default Vue.extend({
this.activeFormat = this.defaultVideoFormat this.activeFormat = this.defaultVideoFormat
switch (this.backendPreference) { if (!this.usingElectron) {
case 'local': this.getVideoInformationInvidious()
this.getVideoInformationLocal() } else {
break switch (this.backendPreference) {
case 'invidious': case 'local':
this.getVideoInformationInvidious() this.getVideoInformationLocal()
break break
case 'invidious':
this.getVideoInformationInvidious()
break
}
} }
}, },
methods: { methods: {
@ -202,8 +206,9 @@ export default Vue.extend({
this.isLoading = false this.isLoading = false
}) })
.catch(err => { .catch(err => {
console.log('Error grabbing video data through local API')
console.log(err) console.log(err)
if (this.backendPreference === 'local' && this.backendFallback) { if (!this.usingElectron || (this.backendPreference === 'local' && this.backendFallback)) {
console.log( console.log(
'Error getting data with local backend, falling back to Invidious' 'Error getting data with local backend, falling back to Invidious'
) )