/
App.vue
73 lines (69 loc) · 1.96 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template>
<v-app>
<component
:is="modal.component"
v-for="modal in modals"
:key="modal.guid"
v-bind="{ guid: modal.guid, ...modal.props }"
/>
<Navbar v-if="isAuthenticated" />
<v-main class="background">
<router-view />
</v-main>
</v-app>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
import Navbar from '@/components/Navbar/Navbar.vue'
import qbit from '@/services/qbit'
import { General } from '@/mixins'
export default {
name: 'App',
components: { Navbar },
mixins: [General],
computed: {
...mapState(['rid', 'mainData', 'preferences', 'modals', 'webuiSettings']),
...mapGetters(['getAuthenticated']),
isAuthenticated() {
return this.getAuthenticated()
},
onLoginPage() {
return this.$router.currentRoute.name.includes('login')
}
},
created() {
self.addEventListener('fetch', function (event) {
event.respondWith(async function () {
try {
var res = await fetch(event.request)
var cache = await caches.open('cache')
cache.put(event.request.url, res.clone())
return res
} catch (error) {
return caches.match(event.request)
}
}())
})
this.$store.commit('SET_APP_VERSION', process.env['APPLICATION_VERSION'])
this.checkDeviceDarkTheme()
this.checkAuthenticated()
},
methods: {
async checkAuthenticated() {
const res = await qbit.login()
const authenticated = res === 'Ok.'
this.$store.commit('LOGIN', authenticated)
this.$store.commit('updateMainData')
if (!authenticated && !this.onLoginPage) return this.$router.push('login')
},
checkDeviceDarkTheme() {
if (this.webuiSettings.useDeviceDarkMode) {
const darkMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
if (darkMediaQuery.matches) {
setTimeout(() => this.$vuetify.theme.dark = true, 0)
}
}
}
}
}
</script>