2018-08-11 01:47:10 -04:00
|
|
|
<template>
|
|
|
|
<div id="app">
|
|
|
|
<navbar-top />
|
2023-07-02 13:20:44 -04:00
|
|
|
<vue-progress-bar class="fd-progress-bar has-background-info" />
|
2022-02-19 00:18:01 -05:00
|
|
|
<router-view v-slot="{ Component }">
|
2023-06-21 09:14:17 -04:00
|
|
|
<component :is="Component" />
|
2022-02-19 00:18:01 -05:00
|
|
|
</router-view>
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
<modal-dialog-remote-pairing
|
|
|
|
:show="pairing_active"
|
|
|
|
@close="pairing_active = false"
|
|
|
|
/>
|
2022-01-09 12:29:24 -05:00
|
|
|
<modal-dialog-update
|
2022-02-19 00:39:14 -05:00
|
|
|
:show="show_update_dialog"
|
|
|
|
@close="show_update_dialog = false"
|
|
|
|
/>
|
2022-02-19 01:05:59 -05:00
|
|
|
<notification-list v-show="!show_burger_menu" />
|
2020-04-18 00:57:55 -04:00
|
|
|
<navbar-bottom />
|
2022-02-19 00:39:14 -05:00
|
|
|
<div
|
|
|
|
v-show="show_burger_menu || show_player_menu"
|
|
|
|
class="fd-overlay-fullscreen"
|
|
|
|
@click="show_burger_menu = show_player_menu = false"
|
|
|
|
/>
|
2018-08-11 01:47:10 -04:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-02-19 00:18:01 -05:00
|
|
|
import NavbarTop from '@/components/NavbarTop.vue'
|
|
|
|
import NavbarBottom from '@/components/NavbarBottom.vue'
|
2022-02-19 01:05:59 -05:00
|
|
|
import NotificationList from '@/components/NotificationList.vue'
|
2022-02-19 00:18:01 -05:00
|
|
|
import ModalDialogRemotePairing from '@/components/ModalDialogRemotePairing.vue'
|
|
|
|
import ModalDialogUpdate from '@/components/ModalDialogUpdate.vue'
|
2018-08-11 01:47:10 -04:00
|
|
|
import webapi from '@/webapi'
|
|
|
|
import * as types from '@/store/mutation_types'
|
|
|
|
import ReconnectingWebSocket from 'reconnectingwebsocket'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
2022-02-19 00:39:14 -05:00
|
|
|
components: {
|
|
|
|
NavbarTop,
|
|
|
|
NavbarBottom,
|
2022-02-19 01:05:59 -05:00
|
|
|
NotificationList,
|
2022-02-19 00:39:14 -05:00
|
|
|
ModalDialogRemotePairing,
|
|
|
|
ModalDialogUpdate
|
|
|
|
},
|
2018-08-11 01:47:10 -04:00
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
data() {
|
2018-08-11 01:47:10 -04:00
|
|
|
return {
|
2018-10-26 14:14:30 -04:00
|
|
|
token_timer_id: 0,
|
2020-03-15 05:00:16 -04:00
|
|
|
reconnect_attempts: 0,
|
|
|
|
pairing_active: false
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-04-18 00:57:55 -04:00
|
|
|
show_burger_menu: {
|
2022-02-19 00:39:14 -05:00
|
|
|
get() {
|
2020-04-18 00:57:55 -04:00
|
|
|
return this.$store.state.show_burger_menu
|
|
|
|
},
|
2022-02-19 00:39:14 -05:00
|
|
|
set(value) {
|
2020-04-18 00:57:55 -04:00
|
|
|
this.$store.commit(types.SHOW_BURGER_MENU, value)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
show_player_menu: {
|
2022-02-19 00:39:14 -05:00
|
|
|
get() {
|
2020-04-18 00:57:55 -04:00
|
|
|
return this.$store.state.show_player_menu
|
|
|
|
},
|
2022-02-19 00:39:14 -05:00
|
|
|
set(value) {
|
2020-04-18 00:57:55 -04:00
|
|
|
this.$store.commit(types.SHOW_PLAYER_MENU, value)
|
|
|
|
}
|
2022-01-09 12:29:24 -05:00
|
|
|
},
|
|
|
|
show_update_dialog: {
|
2022-02-19 00:39:14 -05:00
|
|
|
get() {
|
2022-01-09 12:29:24 -05:00
|
|
|
return this.$store.state.show_update_dialog
|
|
|
|
},
|
2022-02-19 00:39:14 -05:00
|
|
|
set(value) {
|
2022-01-09 12:29:24 -05:00
|
|
|
this.$store.commit(types.SHOW_UPDATE_DIALOG, value)
|
|
|
|
}
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
watch: {
|
|
|
|
show_burger_menu() {
|
|
|
|
this.update_is_clipped()
|
|
|
|
},
|
|
|
|
show_player_menu() {
|
|
|
|
this.update_is_clipped()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
created() {
|
2018-08-11 01:47:10 -04:00
|
|
|
this.connect()
|
|
|
|
|
|
|
|
// Start the progress bar on app start
|
|
|
|
this.$Progress.start()
|
|
|
|
|
|
|
|
// Hook the progress bar to start before we move router-view
|
|
|
|
this.$router.beforeEach((to, from, next) => {
|
2023-07-26 00:45:46 -04:00
|
|
|
if (to.meta.show_progress && !(to.path === from.path && to.hash)) {
|
2018-08-11 01:47:10 -04:00
|
|
|
if (to.meta.progress !== undefined) {
|
2020-04-11 13:43:53 -04:00
|
|
|
const meta = to.meta.progress
|
2018-08-11 01:47:10 -04:00
|
|
|
this.$Progress.parseMeta(meta)
|
|
|
|
}
|
|
|
|
this.$Progress.start()
|
|
|
|
}
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
// Hook the progress bar to finish after we've finished moving router-view
|
2018-08-11 01:47:10 -04:00
|
|
|
this.$router.afterEach((to, from) => {
|
|
|
|
if (to.meta.show_progress) {
|
|
|
|
this.$Progress.finish()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2023-06-07 15:25:54 -04:00
|
|
|
connect() {
|
2022-02-19 00:39:14 -05:00
|
|
|
webapi
|
|
|
|
.config()
|
|
|
|
.then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_CONFIG, data)
|
|
|
|
this.$store.commit(types.HIDE_SINGLES, data.hide_singles)
|
|
|
|
document.title = data.library_name
|
2018-08-11 01:47:10 -04:00
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
this.open_ws()
|
|
|
|
this.$Progress.finish()
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.$store.dispatch('add_notification', {
|
2023-03-16 19:19:14 -04:00
|
|
|
text: this.$t('server.connection-failed'),
|
2022-02-19 00:39:14 -05:00
|
|
|
type: 'danger',
|
|
|
|
topic: 'connection'
|
|
|
|
})
|
|
|
|
})
|
2018-08-11 01:47:10 -04:00
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
open_ws() {
|
2018-08-11 01:47:10 -04:00
|
|
|
if (this.$store.state.config.websocket_port <= 0) {
|
2022-02-19 00:39:14 -05:00
|
|
|
this.$store.dispatch('add_notification', {
|
2022-05-20 07:44:22 -04:00
|
|
|
text: this.$t('server.missing-port'),
|
2022-02-19 00:39:14 -05:00
|
|
|
type: 'danger'
|
|
|
|
})
|
2018-08-11 01:47:10 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const vm = this
|
|
|
|
|
2021-01-10 01:51:50 -05:00
|
|
|
let protocol = 'ws://'
|
2019-01-15 13:46:37 -05:00
|
|
|
if (window.location.protocol === 'https:') {
|
|
|
|
protocol = 'wss://'
|
|
|
|
}
|
|
|
|
|
2023-11-23 14:23:40 -05:00
|
|
|
let wsUrl = `${protocol + window.location.hostname}:${
|
2022-02-19 00:39:14 -05:00
|
|
|
vm.$store.state.config.websocket_port
|
2023-11-23 14:23:40 -05:00
|
|
|
}`
|
2022-03-19 13:35:32 -04:00
|
|
|
|
|
|
|
if (import.meta.env.DEV && import.meta.env.VITE_OWNTONE_URL) {
|
|
|
|
// If we are running in development mode, construct the websocket url
|
|
|
|
// from the host of the environment variable VITE_OWNTONE_URL
|
|
|
|
const owntoneUrl = new URL(import.meta.env.VITE_OWNTONE_URL)
|
2023-11-23 14:23:40 -05:00
|
|
|
wsUrl = `${protocol + owntoneUrl.hostname}:${
|
2022-03-19 13:35:32 -04:00
|
|
|
vm.$store.state.config.websocket_port
|
2023-11-23 14:23:40 -05:00
|
|
|
}`
|
2020-05-02 02:43:10 -04:00
|
|
|
}
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
const socket = new ReconnectingWebSocket(wsUrl, 'notify', {
|
2022-03-05 06:10:13 -05:00
|
|
|
reconnectInterval: 1000,
|
|
|
|
maxReconnectInterval: 2000
|
2022-02-19 00:39:14 -05:00
|
|
|
})
|
2018-08-11 01:47:10 -04:00
|
|
|
|
|
|
|
socket.onopen = function () {
|
2018-10-26 14:14:30 -04:00
|
|
|
vm.reconnect_attempts = 0
|
2022-02-19 00:39:14 -05:00
|
|
|
socket.send(
|
|
|
|
JSON.stringify({
|
|
|
|
notify: [
|
|
|
|
'update',
|
|
|
|
'database',
|
|
|
|
'player',
|
|
|
|
'options',
|
|
|
|
'outputs',
|
|
|
|
'volume',
|
|
|
|
'queue',
|
|
|
|
'spotify',
|
|
|
|
'lastfm',
|
|
|
|
'pairing'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
)
|
2018-08-11 01:47:10 -04:00
|
|
|
|
|
|
|
vm.update_outputs()
|
|
|
|
vm.update_player_status()
|
|
|
|
vm.update_library_stats()
|
2019-07-07 02:22:56 -04:00
|
|
|
vm.update_settings()
|
2018-08-11 01:47:10 -04:00
|
|
|
vm.update_queue()
|
|
|
|
vm.update_spotify()
|
2020-01-04 12:53:27 -05:00
|
|
|
vm.update_lastfm()
|
|
|
|
vm.update_pairing()
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
socket.onclose = function () {
|
|
|
|
// vm.$store.dispatch('add_notification', { text: 'Connection closed', type: 'danger', timeout: 2000 })
|
|
|
|
}
|
2022-03-05 06:06:03 -05:00
|
|
|
|
|
|
|
// When the app becomes active, force an update of all information, because we
|
|
|
|
// may have missed notifications while the app was inactive.
|
|
|
|
// There are two relevant events (focus and visibilitychange), so we throttle
|
|
|
|
// the updates to avoid multiple redundant updates
|
|
|
|
var update_throttled = false
|
|
|
|
|
|
|
|
function update_info() {
|
2022-03-19 13:35:32 -04:00
|
|
|
if (update_throttled) {
|
2022-03-05 06:06:03 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.update_outputs()
|
|
|
|
vm.update_player_status()
|
|
|
|
vm.update_library_stats()
|
|
|
|
vm.update_settings()
|
|
|
|
vm.update_queue()
|
|
|
|
vm.update_spotify()
|
|
|
|
vm.update_lastfm()
|
|
|
|
vm.update_pairing()
|
|
|
|
|
|
|
|
update_throttled = true
|
2023-06-07 15:25:54 -04:00
|
|
|
setTimeout(() => {
|
2022-03-19 13:35:32 -04:00
|
|
|
update_throttled = false
|
|
|
|
}, 500)
|
2022-03-05 06:06:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// These events are fired when the window becomes active in different ways
|
|
|
|
// When this happens, we should update 'now playing' info etc
|
|
|
|
window.addEventListener('focus', update_info)
|
2023-06-07 15:25:54 -04:00
|
|
|
document.addEventListener('visibilitychange', () => {
|
2022-03-05 06:06:03 -05:00
|
|
|
if (document.visibilityState === 'visible') {
|
|
|
|
update_info()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-08-11 01:47:10 -04:00
|
|
|
socket.onmessage = function (response) {
|
2021-01-10 01:51:50 -05:00
|
|
|
const data = JSON.parse(response.data)
|
2022-02-19 00:39:14 -05:00
|
|
|
if (
|
|
|
|
data.notify.includes('update') ||
|
|
|
|
data.notify.includes('database')
|
|
|
|
) {
|
2018-08-11 01:47:10 -04:00
|
|
|
vm.update_library_stats()
|
|
|
|
}
|
2022-02-19 00:39:14 -05:00
|
|
|
if (
|
|
|
|
data.notify.includes('player') ||
|
|
|
|
data.notify.includes('options') ||
|
|
|
|
data.notify.includes('volume')
|
|
|
|
) {
|
2018-08-11 01:47:10 -04:00
|
|
|
vm.update_player_status()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('outputs') || data.notify.includes('volume')) {
|
|
|
|
vm.update_outputs()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('queue')) {
|
|
|
|
vm.update_queue()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('spotify')) {
|
|
|
|
vm.update_spotify()
|
|
|
|
}
|
2020-01-04 12:53:27 -05:00
|
|
|
if (data.notify.includes('lastfm')) {
|
|
|
|
vm.update_lastfm()
|
|
|
|
}
|
|
|
|
if (data.notify.includes('pairing')) {
|
|
|
|
vm.update_pairing()
|
|
|
|
}
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_library_stats() {
|
2018-08-11 01:47:10 -04:00
|
|
|
webapi.library_stats().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_STATS, data)
|
|
|
|
})
|
|
|
|
webapi.library_count('media_kind is audiobook').then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_AUDIOBOOKS_COUNT, data)
|
|
|
|
})
|
|
|
|
webapi.library_count('media_kind is podcast').then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_PODCASTS_COUNT, data)
|
|
|
|
})
|
2022-01-09 12:29:24 -05:00
|
|
|
webapi.library_count('scan_kind is rss').then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LIBRARY_RSS_COUNT, data)
|
|
|
|
})
|
2018-08-11 01:47:10 -04:00
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_outputs() {
|
2018-08-11 01:47:10 -04:00
|
|
|
webapi.outputs().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_OUTPUTS, data.outputs)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_player_status() {
|
2018-08-11 01:47:10 -04:00
|
|
|
webapi.player_status().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_PLAYER_STATUS, data)
|
2023-09-21 12:53:20 -04:00
|
|
|
this.update_lyrics()
|
2018-08-11 01:47:10 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_queue() {
|
2018-08-11 01:47:10 -04:00
|
|
|
webapi.queue().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_QUEUE, data)
|
2023-09-21 12:53:20 -04:00
|
|
|
this.update_lyrics()
|
2018-08-11 01:47:10 -04:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-09-21 12:53:20 -04:00
|
|
|
update_lyrics() {
|
|
|
|
let track = this.$store.state.queue.items.filter(
|
|
|
|
(e) => e.id == this.$store.state.player.item_id
|
|
|
|
)
|
|
|
|
if (track.length >= 1)
|
|
|
|
webapi.library_track(track[0].track_id).then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LYRICS, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_settings() {
|
2019-07-07 02:22:56 -04:00
|
|
|
webapi.settings().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_SETTINGS, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_lastfm() {
|
2020-01-04 12:53:27 -05:00
|
|
|
webapi.lastfm().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_LASTFM, data)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_spotify() {
|
2018-08-11 01:47:10 -04:00
|
|
|
webapi.spotify().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_SPOTIFY, data)
|
|
|
|
|
|
|
|
if (this.token_timer_id > 0) {
|
|
|
|
window.clearTimeout(this.token_timer_id)
|
|
|
|
this.token_timer_id = 0
|
|
|
|
}
|
|
|
|
if (data.webapi_token_expires_in > 0 && data.webapi_token) {
|
2022-02-19 00:39:14 -05:00
|
|
|
this.token_timer_id = window.setTimeout(
|
|
|
|
this.update_spotify,
|
|
|
|
1000 * data.webapi_token_expires_in
|
|
|
|
)
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
})
|
2020-01-04 12:53:27 -05:00
|
|
|
},
|
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_pairing() {
|
2020-01-04 12:53:27 -05:00
|
|
|
webapi.pairing().then(({ data }) => {
|
|
|
|
this.$store.commit(types.UPDATE_PAIRING, data)
|
2020-03-15 05:00:16 -04:00
|
|
|
this.pairing_active = data.active
|
2020-01-04 12:53:27 -05:00
|
|
|
})
|
2020-04-18 00:57:55 -04:00
|
|
|
},
|
2018-08-11 01:47:10 -04:00
|
|
|
|
2023-06-07 15:25:54 -04:00
|
|
|
update_is_clipped() {
|
2020-04-18 00:57:55 -04:00
|
|
|
if (this.show_burger_menu || this.show_player_menu) {
|
2018-08-11 01:47:10 -04:00
|
|
|
document.querySelector('html').classList.add('is-clipped')
|
|
|
|
} else {
|
|
|
|
document.querySelector('html').classList.remove('is-clipped')
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 00:57:55 -04:00
|
|
|
},
|
2022-02-19 00:39:14 -05:00
|
|
|
template: '<App/>'
|
2018-08-11 01:47:10 -04:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-02-19 00:39:14 -05:00
|
|
|
<style></style>
|