2020-06-24 20:54:36 +00:00
|
|
|
import Vue from 'vue'
|
2020-06-19 19:53:32 +00:00
|
|
|
|
2020-07-20 11:09:00 +00:00
|
|
|
// Object is needed for vue change detection
|
2020-06-29 18:23:56 +00:00
|
|
|
window.vol = {
|
|
|
|
preview_max_volume: 100
|
|
|
|
}
|
2020-06-24 17:10:10 +00:00
|
|
|
|
2020-07-16 22:11:28 +00:00
|
|
|
import App from '@components/App.vue'
|
|
|
|
import i18n from '@/plugins/i18n'
|
2020-06-19 19:53:32 +00:00
|
|
|
|
2020-05-07 20:10:13 +00:00
|
|
|
import $ from 'jquery'
|
2020-07-16 22:11:28 +00:00
|
|
|
import { socket } from '@/utils/socket'
|
|
|
|
import { toast } from '@/utils/toasts'
|
|
|
|
import { init as initTabs } from '@js/tabs.js'
|
2020-04-19 20:02:06 +00:00
|
|
|
|
2020-05-15 20:21:31 +00:00
|
|
|
/* ===== App initialization ===== */
|
|
|
|
|
|
|
|
function startApp() {
|
2020-06-29 18:23:56 +00:00
|
|
|
mountApp()
|
2020-07-14 20:27:48 +00:00
|
|
|
initTabs()
|
2020-05-15 20:21:31 +00:00
|
|
|
}
|
2020-05-22 22:15:29 +00:00
|
|
|
|
2020-06-29 18:23:56 +00:00
|
|
|
function mountApp() {
|
2020-07-06 18:46:25 +00:00
|
|
|
// TODO Remove the App instance from the window when deemix will be a complete Vue App
|
2020-07-16 22:11:28 +00:00
|
|
|
new Vue({
|
|
|
|
i18n,
|
2020-06-29 18:23:56 +00:00
|
|
|
render: h => h(App)
|
|
|
|
}).$mount('#app')
|
2020-06-24 20:54:36 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 22:15:29 +00:00
|
|
|
function initClient() {
|
2020-05-19 16:30:18 +00:00
|
|
|
window.clientMode = true
|
|
|
|
document.querySelector(`#open_downloads_folder`).classList.remove('hide')
|
|
|
|
}
|
2020-05-15 20:21:31 +00:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', startApp)
|
2020-05-19 16:30:18 +00:00
|
|
|
window.addEventListener('pywebviewready', initClient)
|
2020-05-15 20:21:31 +00:00
|
|
|
|
2020-04-19 20:02:06 +00:00
|
|
|
/* ===== Socketio listeners ===== */
|
|
|
|
|
|
|
|
// Debug messages for socketio
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('message', function(msg) {
|
2020-04-19 20:02:06 +00:00
|
|
|
console.log(msg)
|
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('logging_in', function() {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
|
2020-04-19 20:02:06 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('init_autologin', function() {
|
2020-05-31 12:25:49 +00:00
|
|
|
let arl = localStorage.getItem('arl')
|
2020-05-30 17:31:42 +00:00
|
|
|
let accountNum = localStorage.getItem('accountNum')
|
2020-06-18 16:29:38 +00:00
|
|
|
if (arl) {
|
2020-05-31 12:25:49 +00:00
|
|
|
arl = arl.trim()
|
2020-06-18 16:29:38 +00:00
|
|
|
if (accountNum != 0) {
|
2020-05-30 17:31:42 +00:00
|
|
|
socket.emit('login', arl, true, accountNum)
|
2020-06-18 16:29:38 +00:00
|
|
|
} else {
|
2020-05-30 17:31:42 +00:00
|
|
|
socket.emit('login', arl)
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 11:32:02 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('logged_in', function(data) {
|
2020-04-19 20:02:06 +00:00
|
|
|
switch (data.status) {
|
|
|
|
case 1:
|
|
|
|
case 3:
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.loggedIn'), 'done', true, 'login-toast')
|
2020-04-19 20:02:06 +00:00
|
|
|
if (data.arl) {
|
|
|
|
localStorage.setItem('arl', data.arl)
|
|
|
|
$('#login_input_arl').val(data.arl)
|
|
|
|
}
|
|
|
|
$('#open_login_prompt').hide()
|
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
2020-04-29 19:46:10 +00:00
|
|
|
// $('#logged_in_info').show()
|
|
|
|
document.getElementById('logged_in_info').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
}
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
case 2:
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.alreadyLogged'), 'done', true, 'login-toast')
|
2020-04-19 20:02:06 +00:00
|
|
|
if (data.user) {
|
|
|
|
$('#settings_username').text(data.user.name)
|
|
|
|
$('#settings_picture').attr(
|
|
|
|
'src',
|
|
|
|
`https://e-cdns-images.dzcdn.net/images/user/${data.user.picture}/125x125-000000-80-0-0.jpg`
|
|
|
|
)
|
2020-04-29 19:46:10 +00:00
|
|
|
// $('#logged_in_info').show()
|
|
|
|
document.getElementById('logged_in_info').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
}
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
case 0:
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.loginFailed'), 'close', true, 'login-toast')
|
2020-04-19 20:02:06 +00:00
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
|
|
|
$('#open_login_prompt').show()
|
2020-04-29 19:46:10 +00:00
|
|
|
document.getElementById('logged_in_info').classList.add('hide')
|
|
|
|
// $('#logged_in_info').hide()
|
2020-04-19 20:02:06 +00:00
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('logged_out', function() {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.loggedOut'), 'done', true, 'login-toast')
|
2020-04-19 20:02:06 +00:00
|
|
|
localStorage.removeItem('arl')
|
|
|
|
$('#login_input_arl').val('')
|
|
|
|
$('#open_login_prompt').show()
|
2020-04-29 19:46:10 +00:00
|
|
|
document.getElementById('logged_in_info').classList.add('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
$('#settings_username').text('Not Logged')
|
|
|
|
$('#settings_picture').attr('src', `https://e-cdns-images.dzcdn.net/images/user/125x125-000000-80-0-0.jpg`)
|
2020-05-09 12:45:28 +00:00
|
|
|
document.getElementById('home_not_logged_in').classList.remove('hide')
|
2020-04-19 20:02:06 +00:00
|
|
|
})
|
2020-06-05 08:46:22 +00:00
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('cancellingCurrentItem', function(uuid) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.cancellingCurrentItem'), 'loading', false, 'cancelling_' + uuid)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('currentItemCancelled', function(uuid) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.currentItemCancelled'), 'done', true, 'cancelling_' + uuid)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('startAddingArtist', function(data) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.startAddingArtist', [data.name]), 'loading', false, 'artist_' + data.id)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('finishAddingArtist', function(data) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.finishAddingArtist', [data.name]), 'done', true, 'artist_' + data.id)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('startConvertingSpotifyPlaylist', function(id) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.startConvertingSpotifyPlaylist'), 'loading', false, 'spotifyplaylist_' + id)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('finishConvertingSpotifyPlaylist', function(id) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.finishConvertingSpotifyPlaylist'), 'done', true, 'spotifyplaylist_' + id)
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('errorMessage', function(error) {
|
2020-06-05 08:46:22 +00:00
|
|
|
toast(error, 'error')
|
|
|
|
})
|
|
|
|
|
2020-06-24 17:10:10 +00:00
|
|
|
socket.on('alreadyInQueue', function(data) {
|
2020-07-21 09:09:47 +00:00
|
|
|
toast(i18n.t('toasts.alreadyInQueue', [data.title]), 'playlist_add_check')
|
2020-06-05 08:46:22 +00:00
|
|
|
})
|