2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-07-10 15:59:26 +00:00
|
|
|
<Overlay/>
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
<div id="main" v-if="authenticated">
|
|
|
|
<Hotkeys/>
|
|
|
|
<EventListeners/>
|
|
|
|
<AppHeader/>
|
|
|
|
<MainWrapper/>
|
|
|
|
<AppFooter/>
|
|
|
|
<SupportKoel/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<template v-else>
|
|
|
|
<div class="login-wrapper">
|
|
|
|
<LoginForm @loggedin="onUserLoggedIn"/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-07-08 10:32:44 +00:00
|
|
|
<SongContextMenu/>
|
|
|
|
<AlbumContextMenu/>
|
|
|
|
<ArtistContextMenu/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-07-25 08:35:15 +00:00
|
|
|
import { defineAsyncComponent, nextTick, onMounted, ref } from 'vue'
|
2022-07-08 10:32:44 +00:00
|
|
|
import { $, eventBus, hideOverlay, showOverlay } from '@/utils'
|
2022-07-24 10:53:49 +00:00
|
|
|
import { commonStore, preferenceStore as preferences } from '@/stores'
|
|
|
|
import { authService, playbackService, socketListener, socketService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:29:14 +00:00
|
|
|
import AppHeader from '@/components/layout/AppHeader.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import AppFooter from '@/components/layout/app-footer/index.vue'
|
2022-04-30 21:08:25 +00:00
|
|
|
import EventListeners from '@/components/utils/EventListeners.vue'
|
2022-04-24 08:29:14 +00:00
|
|
|
import Hotkeys from '@/components/utils/HotkeyListener.vue'
|
2022-04-23 23:11:37 +00:00
|
|
|
import LoginForm from '@/components/auth/LoginForm.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import MainWrapper from '@/components/layout/main-wrapper/index.vue'
|
2022-04-24 08:29:14 +00:00
|
|
|
import Overlay from '@/components/ui/Overlay.vue'
|
2022-07-08 10:32:44 +00:00
|
|
|
import AlbumContextMenu from '@/components/album/AlbumContextMenu.vue'
|
|
|
|
import ArtistContextMenu from '@/components/artist/ArtistContextMenu.vue'
|
|
|
|
import SongContextMenu from '@/components/song/SongContextMenu.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:29:14 +00:00
|
|
|
const SupportKoel = defineAsyncComponent(() => import('@/components/meta/SupportKoel.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-20 10:27:10 +00:00
|
|
|
const authenticated = ref(false)
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
/**
|
|
|
|
* Request for notification permission if it's not provided and the user is OK with notifications.
|
|
|
|
*/
|
|
|
|
const requestNotificationPermission = async () => {
|
2022-07-25 08:35:15 +00:00
|
|
|
if (preferences.notify && window.Notification && window.Notification.permission !== 'granted') {
|
2022-04-15 14:24:30 +00:00
|
|
|
preferences.notify = await window.Notification.requestPermission() === 'denied'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const onUserLoggedIn = () => {
|
|
|
|
authenticated.value = true
|
|
|
|
init()
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
// The app has just been initialized, check if we can get the user data with an already existing token
|
2022-04-24 08:50:45 +00:00
|
|
|
if (authService.hasToken()) {
|
2022-04-15 14:24:30 +00:00
|
|
|
authenticated.value = true
|
|
|
|
await init()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add an ugly mac/non-mac class for OS-targeting styles.
|
|
|
|
// I'm crying inside.
|
|
|
|
$.addClass(document.documentElement, navigator.userAgent.includes('Mac') ? 'mac' : 'non-mac')
|
|
|
|
})
|
|
|
|
|
|
|
|
const init = async () => {
|
|
|
|
showOverlay()
|
|
|
|
|
|
|
|
try {
|
2022-04-24 08:50:45 +00:00
|
|
|
await commonStore.init()
|
2022-07-25 08:35:15 +00:00
|
|
|
await nextTick()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-25 08:35:15 +00:00
|
|
|
playbackService.init()
|
|
|
|
await requestNotificationPermission()
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-25 08:35:15 +00:00
|
|
|
window.addEventListener('beforeunload', (e: BeforeUnloadEvent): void => {
|
|
|
|
if (!preferences.confirmClosing) {
|
|
|
|
return
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-25 08:35:15 +00:00
|
|
|
e.preventDefault()
|
|
|
|
e.returnValue = ''
|
|
|
|
})
|
2022-07-24 10:53:49 +00:00
|
|
|
|
|
|
|
await socketService.init() && socketListener.listen()
|
2022-07-25 08:35:15 +00:00
|
|
|
|
|
|
|
hideOverlay()
|
|
|
|
|
|
|
|
// Let all other components know we're ready.
|
|
|
|
eventBus.emit('KOEL_READY')
|
2022-04-15 14:24:30 +00:00
|
|
|
} catch (err) {
|
|
|
|
authenticated.value = false
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2022-04-15 17:00:08 +00:00
|
|
|
@import "#/app.scss";
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
#dragGhost {
|
|
|
|
display: inline-block;
|
|
|
|
background: var(--color-green);
|
|
|
|
padding: .8rem;
|
|
|
|
border-radius: .2rem;
|
|
|
|
color: var(--color-text-primary);
|
|
|
|
font-family: var(--font-family);
|
|
|
|
font-size: 1rem;
|
|
|
|
font-weight: var(--font-weight-light);
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: -1;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#copyArea {
|
|
|
|
position: absolute;
|
|
|
|
left: -9999px;
|
|
|
|
width: 1px;
|
|
|
|
height: 1px;
|
|
|
|
bottom: 1px;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#main, .login-wrapper {
|
|
|
|
display: flex;
|
|
|
|
height: 100vh;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
|
|
|
|
.login-wrapper {
|
|
|
|
@include vertical-center();
|
|
|
|
user-select: none;
|
|
|
|
padding-bottom: 0;
|
|
|
|
}
|
|
|
|
</style>
|