2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-07-10 15:59:26 +00:00
|
|
|
<Overlay/>
|
2022-09-08 05:06:49 +00:00
|
|
|
<DialogBox ref="dialog"/>
|
|
|
|
<MessageToaster ref="toaster"/>
|
2022-10-07 14:33:50 +00:00
|
|
|
<GlobalEventListeners/>
|
2022-10-27 13:44:40 +00:00
|
|
|
<OfflineNotification v-if="offline"/>
|
2022-07-10 15:59:26 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
<div v-if="authenticated" id="main" @dragend="onDragEnd" @dragover="onDragOver" @drop="onDrop">
|
2022-04-15 14:24:30 +00:00
|
|
|
<Hotkeys/>
|
|
|
|
<MainWrapper/>
|
|
|
|
<AppFooter/>
|
|
|
|
<SupportKoel/>
|
2022-09-08 05:06:49 +00:00
|
|
|
<SongContextMenu/>
|
|
|
|
<AlbumContextMenu/>
|
|
|
|
<ArtistContextMenu/>
|
|
|
|
<PlaylistContextMenu/>
|
|
|
|
<PlaylistFolderContextMenu/>
|
|
|
|
<CreateNewPlaylistContextMenu/>
|
2022-09-12 11:11:56 +00:00
|
|
|
<DropZone v-show="showDropZone"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
<div v-else class="login-wrapper">
|
2022-09-08 05:06:49 +00:00
|
|
|
<LoginForm @loggedin="onUserLoggedIn"/>
|
|
|
|
</div>
|
2022-04-15 14:24:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-10-13 15:18:47 +00:00
|
|
|
import { defineAsyncComponent, nextTick, onMounted, provide, ref, watch } from 'vue'
|
2022-10-08 10:54:25 +00:00
|
|
|
import { eventBus, hideOverlay, requireInjection, showOverlay } from '@/utils'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { commonStore, preferenceStore as preferences, queueStore } from '@/stores'
|
2022-08-04 10:39:03 +00:00
|
|
|
import { authService, playbackService, socketListener, socketService, uploadService } from '@/services'
|
2022-10-13 15:18:47 +00:00
|
|
|
import { CurrentSongKey, DialogBoxKey, MessageToasterKey, RouterKey } from '@/symbols'
|
2022-10-27 13:44:40 +00:00
|
|
|
import { useNetworkStatus } from '@/composables'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-26 09:51:19 +00:00
|
|
|
import DialogBox from '@/components/ui/DialogBox.vue'
|
|
|
|
import MessageToaster from '@/components/ui/MessageToaster.vue'
|
2022-09-08 05:06:49 +00:00
|
|
|
import Overlay from '@/components/ui/Overlay.vue'
|
2022-10-27 13:44:40 +00:00
|
|
|
import OfflineNotification from '@/components/ui/OfflineNotification.vue'
|
2022-09-08 05:06:49 +00:00
|
|
|
|
|
|
|
// Do not dynamic-import app footer, as it contains the <audio> element
|
|
|
|
// that is necessary to properly initialize the playService and equalizer.
|
|
|
|
import AppFooter from '@/components/layout/app-footer/index.vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-10-07 14:33:50 +00:00
|
|
|
// GlobalEventListener must NOT be lazy-loaded, so that it can handle LOG_OUT event properly.
|
2022-10-27 13:33:32 +00:00
|
|
|
import { GlobalEventListeners } from '@/components/utils/GlobalEventListeners'
|
2022-10-07 14:33:50 +00:00
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
const Hotkeys = defineAsyncComponent(() => import('@/components/utils/HotkeyListener.vue'))
|
|
|
|
const LoginForm = defineAsyncComponent(() => import('@/components/auth/LoginForm.vue'))
|
|
|
|
const MainWrapper = defineAsyncComponent(() => import('@/components/layout/main-wrapper/index.vue'))
|
|
|
|
const AlbumContextMenu = defineAsyncComponent(() => import('@/components/album/AlbumContextMenu.vue'))
|
|
|
|
const ArtistContextMenu = defineAsyncComponent(() => import('@/components/artist/ArtistContextMenu.vue'))
|
|
|
|
const PlaylistContextMenu = defineAsyncComponent(() => import('@/components/playlist/PlaylistContextMenu.vue'))
|
|
|
|
const PlaylistFolderContextMenu = defineAsyncComponent(() => import('@/components/playlist/PlaylistFolderContextMenu.vue'))
|
|
|
|
const SongContextMenu = defineAsyncComponent(() => import('@/components/song/SongContextMenu.vue'))
|
|
|
|
const CreateNewPlaylistContextMenu = defineAsyncComponent(() => import('@/components/playlist/CreateNewPlaylistContextMenu.vue'))
|
2022-04-24 08:29:14 +00:00
|
|
|
const SupportKoel = defineAsyncComponent(() => import('@/components/meta/SupportKoel.vue'))
|
2022-09-12 11:11:56 +00:00
|
|
|
const DropZone = defineAsyncComponent(() => import('@/components/ui/upload/DropZone.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-07-26 09:51:19 +00:00
|
|
|
const dialog = ref<InstanceType<typeof DialogBox>>()
|
2022-09-08 05:06:49 +00:00
|
|
|
const toaster = ref<InstanceType<typeof MessageToaster>>()
|
2022-10-13 15:18:47 +00:00
|
|
|
const currentSong = ref<Song | null>(null)
|
2022-04-20 10:27:10 +00:00
|
|
|
const authenticated = ref(false)
|
2022-09-12 11:11:56 +00:00
|
|
|
const showDropZone = ref(false)
|
2022-04-20 10:27:10 +00:00
|
|
|
|
2022-10-27 13:44:40 +00:00
|
|
|
const { offline } = useNetworkStatus()
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-08 05:06:49 +00:00
|
|
|
const onUserLoggedIn = async () => {
|
2022-04-15 14:24:30 +00:00
|
|
|
authenticated.value = true
|
2022-09-08 05:06:49 +00:00
|
|
|
await init()
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2022-07-25 12:57:58 +00:00
|
|
|
document.documentElement.classList.add(navigator.userAgent.includes('Mac') ? 'mac' : 'non-mac')
|
2022-04-15 14:24:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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-08-04 10:39:03 +00:00
|
|
|
window.addEventListener('beforeunload', (e: BeforeUnloadEvent) => {
|
|
|
|
if (uploadService.shouldWarnUponWindowUnload() || preferences.confirmClosing) {
|
|
|
|
e.preventDefault()
|
|
|
|
e.returnValue = ''
|
2022-07-25 08:35:15 +00:00
|
|
|
}
|
|
|
|
})
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 09:51:19 +00:00
|
|
|
|
2022-10-08 10:54:25 +00:00
|
|
|
const router = requireInjection(RouterKey)
|
|
|
|
|
2022-09-12 11:11:56 +00:00
|
|
|
const onDragOver = (e: DragEvent) => {
|
2022-10-08 10:54:25 +00:00
|
|
|
showDropZone.value = Boolean(e.dataTransfer?.types.includes('Files')) && router.$currentRoute.value.screen !== 'Upload'
|
2022-09-12 11:11:56 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
watch(() => queueStore.current, song => (currentSong.value = song))
|
|
|
|
|
2022-09-12 11:11:56 +00:00
|
|
|
const onDragEnd = () => (showDropZone.value = false)
|
|
|
|
const onDrop = () => (showDropZone.value = false)
|
|
|
|
|
2022-07-26 09:51:19 +00:00
|
|
|
provide(DialogBoxKey, dialog)
|
|
|
|
provide(MessageToasterKey, toaster)
|
2022-10-13 15:18:47 +00:00
|
|
|
provide(CurrentSongKey, currentSong)
|
2022-04-15 14:24:30 +00:00
|
|
|
</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;
|
2022-07-26 09:51:19 +00:00
|
|
|
border-radius: .3rem;
|
2022-04-15 14:24:30 +00:00
|
|
|
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;
|
2022-09-08 05:06:49 +00:00
|
|
|
justify-content: flex-end;
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-13 15:18:47 +00:00
|
|
|
#main {
|
|
|
|
@media screen and (max-width: 768px) {
|
2022-10-22 07:29:51 +00:00
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
top: 0;
|
2022-10-13 15:18:47 +00:00
|
|
|
padding-top: var(--header-height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 14:24:30 +00:00
|
|
|
.login-wrapper {
|
|
|
|
@include vertical-center();
|
|
|
|
user-select: none;
|
|
|
|
padding-bottom: 0;
|
|
|
|
}
|
|
|
|
</style>
|