2020-06-24 22:54:36 +02:00
|
|
|
import Vue from 'vue'
|
2020-06-19 21:53:32 +02:00
|
|
|
|
2020-07-20 13:09:00 +02:00
|
|
|
// Object is needed for vue change detection
|
2020-06-29 20:23:56 +02:00
|
|
|
window.vol = {
|
|
|
|
preview_max_volume: 100
|
|
|
|
}
|
2020-06-24 19:10:10 +02:00
|
|
|
|
2020-11-07 19:00:34 +01:00
|
|
|
import '@/styles/vendor/material-icons.css'
|
|
|
|
import '@/styles/vendor/OpenSans.css'
|
2020-11-02 12:25:08 +01:00
|
|
|
|
2020-10-09 20:53:24 +02:00
|
|
|
import '@/styles/scss/style.scss'
|
2020-11-10 19:48:02 +01:00
|
|
|
import '@/styles/css/normalize.css'
|
|
|
|
import '@/styles/css/base.css'
|
2020-10-10 20:03:19 +02:00
|
|
|
import '@/styles/css/components.css'
|
2020-11-02 12:25:08 +01:00
|
|
|
import '@/styles/css/helpers.css'
|
2020-11-07 19:00:34 +01:00
|
|
|
import '@/styles/css/typography.css'
|
2020-10-10 20:03:19 +02:00
|
|
|
|
2020-09-25 20:43:23 +02:00
|
|
|
import App from '@/App.vue'
|
2020-07-17 00:11:28 +02:00
|
|
|
import i18n from '@/plugins/i18n'
|
2020-08-23 00:39:31 +02:00
|
|
|
import router from '@/router'
|
|
|
|
import store from '@/store'
|
2020-06-19 21:53:32 +02:00
|
|
|
|
2020-07-17 00:11:28 +02:00
|
|
|
import { socket } from '@/utils/socket'
|
|
|
|
import { toast } from '@/utils/toasts'
|
2020-08-25 15:29:11 +02:00
|
|
|
import { isValidURL } from '@/utils/utils'
|
2020-09-26 17:53:25 +02:00
|
|
|
import { sendAddToQueue } from '@/utils/downloads'
|
2020-08-25 15:29:11 +02:00
|
|
|
|
2020-05-15 22:21:31 +02:00
|
|
|
/* ===== App initialization ===== */
|
|
|
|
function startApp() {
|
2020-07-17 00:11:28 +02:00
|
|
|
new Vue({
|
2020-08-23 00:39:31 +02:00
|
|
|
store,
|
2020-07-28 21:39:44 +02:00
|
|
|
router,
|
2020-07-17 00:11:28 +02:00
|
|
|
i18n,
|
2020-06-29 20:23:56 +02:00
|
|
|
render: h => h(App)
|
|
|
|
}).$mount('#app')
|
2020-06-24 22:54:36 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 00:15:29 +02:00
|
|
|
function initClient() {
|
2020-09-22 22:40:41 +02:00
|
|
|
store.dispatch('setClientMode', true)
|
2020-09-24 18:33:56 +02:00
|
|
|
setClientModeKeyBindings()
|
2020-05-19 18:30:18 +02:00
|
|
|
}
|
2020-05-15 22:21:31 +02:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', startApp)
|
2020-05-19 18:30:18 +02:00
|
|
|
window.addEventListener('pywebviewready', initClient)
|
2020-05-15 22:21:31 +02:00
|
|
|
|
2020-08-25 15:29:11 +02:00
|
|
|
/* ===== Global shortcuts ===== */
|
|
|
|
|
|
|
|
document.addEventListener('paste', pasteEvent => {
|
2020-09-26 17:53:25 +02:00
|
|
|
if (pasteEvent.target.localName === 'input') return
|
|
|
|
|
|
|
|
let pastedText = pasteEvent.clipboardData.getData('Text')
|
2020-09-17 23:55:57 +02:00
|
|
|
|
2020-09-26 17:53:25 +02:00
|
|
|
if (isValidURL(pastedText)) {
|
|
|
|
if (router.currentRoute.name === 'Link Analyzer') {
|
|
|
|
socket.emit('analyzeLink', pastedText)
|
2020-09-17 22:43:52 +02:00
|
|
|
} else {
|
2020-09-26 17:53:25 +02:00
|
|
|
sendAddToQueue(pastedText)
|
2020-08-25 15:29:11 +02:00
|
|
|
}
|
2020-09-26 17:53:25 +02:00
|
|
|
} else {
|
|
|
|
let searchbar = document.querySelector('#searchbar')
|
|
|
|
searchbar.select()
|
|
|
|
searchbar.setSelectionRange(0, 99999)
|
2020-09-23 15:44:43 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-09-24 18:33:56 +02:00
|
|
|
/**
|
|
|
|
* Sets up key bindings that already work in the browser (server mode)
|
|
|
|
*/
|
|
|
|
function setClientModeKeyBindings() {
|
|
|
|
document.addEventListener('keyup', keyEvent => {
|
|
|
|
// ALT + left
|
|
|
|
if (keyEvent.altKey && keyEvent.key === 'ArrowLeft') {
|
|
|
|
router.back()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ALT + right
|
|
|
|
if (keyEvent.altKey && keyEvent.key === 'ArrowRight') {
|
|
|
|
router.forward()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-04-19 22:02:06 +02:00
|
|
|
/* ===== Socketio listeners ===== */
|
|
|
|
|
|
|
|
// Debug messages for socketio
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('message', function(msg) {
|
2020-04-19 22:02:06 +02:00
|
|
|
console.log(msg)
|
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('logging_in', function() {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
|
2020-04-19 22:02:06 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('init_autologin', function() {
|
2020-05-31 14:25:49 +02:00
|
|
|
let arl = localStorage.getItem('arl')
|
2020-05-30 19:31:42 +02:00
|
|
|
let accountNum = localStorage.getItem('accountNum')
|
2020-09-17 23:55:57 +02:00
|
|
|
|
2020-06-18 18:29:38 +02:00
|
|
|
if (arl) {
|
2020-05-31 14:25:49 +02:00
|
|
|
arl = arl.trim()
|
2020-09-17 23:55:57 +02:00
|
|
|
|
2020-06-18 18:29:38 +02:00
|
|
|
if (accountNum != 0) {
|
2020-05-30 19:31:42 +02:00
|
|
|
socket.emit('login', arl, true, accountNum)
|
2020-06-18 18:29:38 +02:00
|
|
|
} else {
|
2020-05-30 19:31:42 +02:00
|
|
|
socket.emit('login', arl)
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 13:32:02 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('logged_in', function(data) {
|
2020-09-17 22:43:52 +02:00
|
|
|
const { status, user } = data
|
|
|
|
|
|
|
|
switch (status) {
|
2020-04-19 22:02:06 +02:00
|
|
|
case 1:
|
|
|
|
case 3:
|
2020-09-17 22:43:52 +02:00
|
|
|
// Login ok
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.loggedIn'), 'done', true, 'login-toast')
|
2020-08-22 23:34:16 +02:00
|
|
|
|
2020-09-17 22:43:52 +02:00
|
|
|
store.dispatch('login', data)
|
2020-04-19 22:02:06 +02:00
|
|
|
break
|
|
|
|
case 2:
|
2020-09-17 22:43:52 +02:00
|
|
|
// Already logged in
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.alreadyLogged'), 'done', true, 'login-toast')
|
2020-08-22 23:34:16 +02:00
|
|
|
|
2020-09-17 22:43:52 +02:00
|
|
|
store.dispatch('setUser', user)
|
2020-04-19 22:02:06 +02:00
|
|
|
break
|
|
|
|
case 0:
|
2020-09-17 22:43:52 +02:00
|
|
|
// Login failed
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.loginFailed'), 'close', true, 'login-toast')
|
2020-09-17 22:43:52 +02:00
|
|
|
|
|
|
|
store.dispatch('removeARL')
|
2020-04-19 22:02:06 +02:00
|
|
|
break
|
2020-09-20 12:32:53 +02:00
|
|
|
case -1:
|
|
|
|
toast(i18n.t('toasts.deezerNotAvailable'), 'close', true, 'login-toast')
|
2020-09-23 18:15:59 +02:00
|
|
|
return
|
|
|
|
// TODO
|
|
|
|
// $('#open_login_prompt').show()
|
|
|
|
// document.getElementById('logged_in_info').classList.add('hide')
|
|
|
|
// $('#settings_username').text('Not Logged')
|
|
|
|
// $('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
|
|
|
// document.getElementById('home_not_logged_in').classList.remove('hide')
|
2020-04-19 22:02:06 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('logged_out', function() {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.loggedOut'), 'done', true, 'login-toast')
|
2020-09-17 22:43:52 +02:00
|
|
|
|
|
|
|
store.dispatch('logout')
|
2020-04-19 22:02:06 +02:00
|
|
|
})
|
2020-06-05 10:46:22 +02:00
|
|
|
|
2020-08-16 01:34:55 +02:00
|
|
|
socket.on('restoringQueue', function() {
|
|
|
|
toast(i18n.t('toasts.restoringQueue'), 'loading', false, 'restoring_queue')
|
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('cancellingCurrentItem', function(uuid) {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.cancellingCurrentItem'), 'loading', false, 'cancelling_' + uuid)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('currentItemCancelled', function(uuid) {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.currentItemCancelled'), 'done', true, 'cancelling_' + uuid)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('startAddingArtist', function(data) {
|
2020-09-17 22:43:52 +02:00
|
|
|
toast(i18n.t('toasts.startAddingArtist', { artist: data.name }), 'loading', false, 'artist_' + data.id)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('finishAddingArtist', function(data) {
|
2020-09-17 22:43:52 +02:00
|
|
|
toast(i18n.t('toasts.finishAddingArtist', { artist: data.name }), 'done', true, 'artist_' + data.id)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('startConvertingSpotifyPlaylist', function(id) {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.startConvertingSpotifyPlaylist'), 'loading', false, 'spotifyplaylist_' + id)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('finishConvertingSpotifyPlaylist', function(id) {
|
2020-07-21 11:09:47 +02:00
|
|
|
toast(i18n.t('toasts.finishConvertingSpotifyPlaylist'), 'done', true, 'spotifyplaylist_' + id)
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('errorMessage', function(error) {
|
2020-06-05 10:46:22 +02:00
|
|
|
toast(error, 'error')
|
|
|
|
})
|
|
|
|
|
2020-07-23 16:43:20 +02:00
|
|
|
socket.on('queueError', function(queueItem) {
|
2020-09-17 23:55:57 +02:00
|
|
|
if (queueItem.errid) {
|
2020-11-02 12:25:08 +01:00
|
|
|
toast(queueItem.link + ' - ' + i18n.t(`errors.ids.${queueItem.errid}`), 'error')
|
2020-09-17 23:55:57 +02:00
|
|
|
} else {
|
2020-11-02 12:25:08 +01:00
|
|
|
toast(queueItem.link + ' - ' + queueItem.error, 'error')
|
2020-09-17 23:55:57 +02:00
|
|
|
}
|
2020-07-23 16:43:20 +02:00
|
|
|
})
|
|
|
|
|
2020-06-24 19:10:10 +02:00
|
|
|
socket.on('alreadyInQueue', function(data) {
|
2020-09-17 22:43:52 +02:00
|
|
|
toast(i18n.t('toasts.alreadyInQueue', { item: data.title }), 'playlist_add_check')
|
2020-06-05 10:46:22 +02:00
|
|
|
})
|
2020-07-29 22:24:44 +02:00
|
|
|
|
|
|
|
socket.on('loginNeededToDownload', function(data) {
|
|
|
|
toast(i18n.t('toasts.loginNeededToDownload'), 'report')
|
|
|
|
})
|
2020-10-14 23:29:24 +02:00
|
|
|
|
|
|
|
socket.on('startGeneratingItems', function(data) {
|
|
|
|
toast(i18n.t('toasts.startGeneratingItems', { n: data.total }), 'loading', false, 'batch_' + data.uuid)
|
|
|
|
})
|
|
|
|
|
|
|
|
socket.on('finishGeneratingItems', function(data) {
|
|
|
|
toast(i18n.t('toasts.finishGeneratingItems', { n: data.total }), 'done', true, 'batch_' + data.uuid)
|
|
|
|
})
|