2020-07-14 20:27:48 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
id="download_tab_container"
|
2020-10-14 20:18:13 +00:00
|
|
|
class="block tab_hidden bg-panels-bg text-panels-text"
|
2020-07-14 20:27:48 +00:00
|
|
|
@transitionend="$refs.container.style.transition = ''"
|
|
|
|
ref="container"
|
2020-07-21 09:09:47 +00:00
|
|
|
:data-label="$t('downloads')"
|
2020-09-26 19:48:55 +00:00
|
|
|
aria-label="downloads"
|
2020-07-14 20:27:48 +00:00
|
|
|
>
|
2020-10-14 20:18:13 +00:00
|
|
|
<!-- Drag Handler -->
|
|
|
|
<div
|
|
|
|
v-show="isExpanded"
|
|
|
|
class="absolute w-4 h-full bg-grayscale-200"
|
|
|
|
@mousedown.prevent="startDrag"
|
|
|
|
style="cursor: ew-resize"
|
|
|
|
></div>
|
|
|
|
|
2020-07-14 20:27:48 +00:00
|
|
|
<i
|
|
|
|
id="toggle_download_tab"
|
2020-10-14 20:18:13 +00:00
|
|
|
class="m-1 text-2xl cursor-pointer material-icons"
|
2020-07-14 20:27:48 +00:00
|
|
|
@click.prevent="toggleDownloadTab"
|
|
|
|
ref="toggler"
|
2020-07-25 13:51:36 +00:00
|
|
|
:title="$t('globals.toggle_download_tab_hint')"
|
2020-07-14 20:27:48 +00:00
|
|
|
></i>
|
|
|
|
<div id="queue_buttons">
|
2020-09-15 20:44:29 +00:00
|
|
|
<i
|
2020-09-17 21:55:57 +00:00
|
|
|
v-if="clientMode"
|
2020-10-14 20:18:13 +00:00
|
|
|
class="m-1 text-2xl cursor-pointer material-icons"
|
2020-09-15 20:44:29 +00:00
|
|
|
:title="$t('globals.open_downloads_folder')"
|
|
|
|
@click="openDownloadsFolder"
|
|
|
|
>
|
|
|
|
folder_open
|
|
|
|
</i>
|
2020-10-14 20:18:13 +00:00
|
|
|
<i class="m-1 text-2xl cursor-pointer material-icons" @click="cleanQueue" :title="$t('globals.clean_queue_hint')">
|
2020-09-15 20:44:29 +00:00
|
|
|
clear_all
|
|
|
|
</i>
|
2020-10-14 20:18:13 +00:00
|
|
|
<i
|
|
|
|
class="m-1 text-2xl cursor-pointer material-icons"
|
|
|
|
@click="cancelQueue"
|
|
|
|
:title="$t('globals.cancel_queue_hint')"
|
|
|
|
>
|
2020-09-15 20:44:29 +00:00
|
|
|
delete_sweep
|
|
|
|
</i>
|
2020-07-14 20:27:48 +00:00
|
|
|
</div>
|
2020-10-14 20:18:13 +00:00
|
|
|
|
|
|
|
<div v-show="isExpanded" id="download_list" class="w-full pr-2" ref="list">
|
2020-09-20 11:18:06 +00:00
|
|
|
<QueueItem
|
|
|
|
v-for="item in queueList"
|
|
|
|
:queue-item="item"
|
|
|
|
:key="item.uuid"
|
|
|
|
@show-errors="showErrorsTab"
|
|
|
|
@remove-item="onRemoveItem"
|
|
|
|
/>
|
2020-09-19 15:07:28 +00:00
|
|
|
</div>
|
2020-07-14 20:27:48 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2020-09-15 20:44:29 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
#download_tab_container {
|
|
|
|
height: 100vh;
|
|
|
|
}
|
2020-10-14 20:18:13 +00:00
|
|
|
|
|
|
|
#download_list {
|
|
|
|
height: calc(100% - 32px);
|
|
|
|
padding-left: 28px;
|
|
|
|
overflow-y: scroll;
|
|
|
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
width: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-webkit-scrollbar-track {
|
|
|
|
background: var(--panels-background);
|
|
|
|
}
|
|
|
|
|
|
|
|
&::-webkit-scrollbar-thumb {
|
|
|
|
background: var(--panels-scroll);
|
|
|
|
border-radius: 4px;
|
|
|
|
width: 6px;
|
|
|
|
padding: 0px 2px;
|
|
|
|
}
|
|
|
|
}
|
2020-09-15 20:44:29 +00:00
|
|
|
</style>
|
2020-09-19 13:11:06 +00:00
|
|
|
|
2020-07-14 20:27:48 +00:00
|
|
|
<script>
|
2020-09-22 20:40:41 +00:00
|
|
|
import { mapActions, mapGetters } from 'vuex'
|
2020-09-20 11:18:06 +00:00
|
|
|
import QueueItem from '@components/downloads/QueueItem.vue'
|
|
|
|
|
2020-07-16 22:11:28 +00:00
|
|
|
import { socket } from '@/utils/socket'
|
|
|
|
import { toast } from '@/utils/toasts'
|
2020-09-19 15:07:28 +00:00
|
|
|
|
2020-07-14 20:27:48 +00:00
|
|
|
const tabMinWidth = 250
|
|
|
|
const tabMaxWidth = 500
|
|
|
|
|
|
|
|
export default {
|
2020-09-19 15:07:28 +00:00
|
|
|
components: {
|
|
|
|
QueueItem
|
|
|
|
},
|
2020-09-17 21:55:57 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
cachedTabWidth: parseInt(localStorage.getItem('downloadTabWidth')) || 300,
|
|
|
|
queue: [],
|
|
|
|
queueList: {},
|
2020-10-14 20:18:13 +00:00
|
|
|
queueComplete: [],
|
|
|
|
isExpanded: localStorage.getItem('downloadTabOpen') === 'true'
|
2020-09-17 21:55:57 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-22 20:40:41 +00:00
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
clientMode: 'getClientMode'
|
|
|
|
})
|
|
|
|
},
|
2020-09-26 19:48:55 +00:00
|
|
|
created() {
|
|
|
|
const checkIfToggleBar = keyEvent => {
|
|
|
|
if (!(keyEvent.ctrlKey && keyEvent.key === 'b')) return
|
|
|
|
|
|
|
|
this.toggleDownloadTab()
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('keyup', checkIfToggleBar)
|
|
|
|
|
|
|
|
this.$on('hook:destroyed', () => {
|
|
|
|
document.removeEventListener('keyup', checkIfToggleBar)
|
|
|
|
})
|
|
|
|
},
|
2020-07-14 20:27:48 +00:00
|
|
|
mounted() {
|
2020-07-16 20:20:13 +00:00
|
|
|
socket.on('startDownload', this.startDownload)
|
2020-08-14 17:49:36 +00:00
|
|
|
socket.on('startConversion', this.startConversion)
|
2020-07-16 20:20:13 +00:00
|
|
|
socket.on('init_downloadQueue', this.initQueue)
|
|
|
|
socket.on('addedToQueue', this.addToQueue)
|
|
|
|
socket.on('updateQueue', this.updateQueue)
|
|
|
|
socket.on('removedFromQueue', this.removeFromQueue)
|
|
|
|
socket.on('finishDownload', this.finishDownload)
|
|
|
|
socket.on('removedAllDownloads', this.removeAllDownloads)
|
|
|
|
socket.on('removedFinishedDownloads', this.removedFinishedDownloads)
|
|
|
|
|
2020-07-14 20:27:48 +00:00
|
|
|
// Check if download tab has slim entries
|
|
|
|
if ('true' === localStorage.getItem('slimDownloads')) {
|
|
|
|
this.$refs.list.classList.add('slim')
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('true' === localStorage.getItem('downloadTabOpen')) {
|
|
|
|
this.$refs.container.classList.remove('tab_hidden')
|
|
|
|
|
|
|
|
this.setTabWidth(this.cachedTabWidth)
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('mouseup', () => {
|
|
|
|
document.removeEventListener('mousemove', this.handleDrag)
|
|
|
|
})
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', () => {
|
|
|
|
localStorage.setItem('downloadTabWidth', this.cachedTabWidth)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
2020-09-19 13:11:06 +00:00
|
|
|
...mapActions(['setErrors']),
|
2020-09-20 11:18:06 +00:00
|
|
|
onRemoveItem(uuid) {
|
|
|
|
socket.emit('removeFromQueue', uuid)
|
|
|
|
},
|
2020-07-14 20:27:48 +00:00
|
|
|
setTabWidth(newWidth) {
|
|
|
|
if (undefined === newWidth) {
|
|
|
|
this.$refs.container.style.width = ''
|
|
|
|
this.$refs.list.style.width = ''
|
|
|
|
} else {
|
|
|
|
this.$refs.container.style.width = newWidth + 'px'
|
|
|
|
this.$refs.list.style.width = newWidth + 'px'
|
|
|
|
}
|
|
|
|
},
|
2020-07-16 20:20:13 +00:00
|
|
|
initQueue(data) {
|
2020-09-15 20:44:29 +00:00
|
|
|
const {
|
|
|
|
queue: initQueue,
|
|
|
|
queueComplete: initQueueComplete,
|
|
|
|
currentItem,
|
|
|
|
queueList: initQueueList,
|
|
|
|
restored
|
|
|
|
} = data
|
2020-07-16 20:20:13 +00:00
|
|
|
|
|
|
|
if (initQueueComplete.length) {
|
|
|
|
initQueueComplete.forEach(item => {
|
2020-08-17 09:06:24 +00:00
|
|
|
initQueueList[item].silent = true
|
2020-07-16 20:20:13 +00:00
|
|
|
this.addToQueue(initQueueList[item])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentItem) {
|
2020-08-17 09:06:24 +00:00
|
|
|
initQueueList[currentItem].silent = true
|
2020-07-16 20:20:13 +00:00
|
|
|
this.addToQueue(initQueueList[currentItem], true)
|
|
|
|
}
|
|
|
|
|
|
|
|
initQueue.forEach(item => {
|
2020-08-17 09:06:24 +00:00
|
|
|
initQueueList[item].silent = true
|
2020-07-16 20:20:13 +00:00
|
|
|
this.addToQueue(initQueueList[item])
|
|
|
|
})
|
2020-08-15 23:34:55 +00:00
|
|
|
|
2020-09-15 20:44:29 +00:00
|
|
|
if (restored) {
|
2020-08-16 10:29:08 +00:00
|
|
|
toast(this.$t('toasts.queueRestored'), 'done', true, 'restoring_queue')
|
|
|
|
socket.emit('queueRestored')
|
|
|
|
}
|
2020-07-16 20:20:13 +00:00
|
|
|
},
|
|
|
|
addToQueue(queueItem, current = false) {
|
2020-09-15 20:44:29 +00:00
|
|
|
if (Array.isArray(queueItem)) {
|
|
|
|
if (queueItem.length > 1) {
|
2020-08-17 09:06:24 +00:00
|
|
|
queueItem.forEach((item, i) => {
|
|
|
|
item.silent = true
|
|
|
|
this.addToQueue(item)
|
2020-09-15 20:44:29 +00:00
|
|
|
})
|
|
|
|
toast(this.$t('toasts.addedMoreToQueue', { n: queueItem.length }), 'playlist_add_check')
|
2020-08-17 09:06:24 +00:00
|
|
|
return
|
2020-09-15 20:44:29 +00:00
|
|
|
} else {
|
2020-08-17 09:06:24 +00:00
|
|
|
queueItem = queueItem[0]
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 20:20:13 +00:00
|
|
|
|
2020-09-20 11:18:06 +00:00
|
|
|
// * Here we have only queueItem objects
|
|
|
|
this.$set(queueItem, 'current', current)
|
2020-09-19 15:07:28 +00:00
|
|
|
this.$set(this.queueList, queueItem.uuid, queueItem)
|
|
|
|
|
|
|
|
// * Used when opening the app in another tab
|
2020-09-20 11:18:06 +00:00
|
|
|
const itemIsAlreadyDownloaded = queueItem.downloaded + queueItem.failed == queueItem.size
|
2020-09-19 15:07:28 +00:00
|
|
|
|
|
|
|
if (itemIsAlreadyDownloaded) {
|
2020-09-20 11:18:06 +00:00
|
|
|
const itemIsNotInCompletedQueue = this.queueComplete.indexOf(queueItem.uuid) == -1
|
|
|
|
|
|
|
|
this.$set(this.queueList[queueItem.uuid], 'status', 'download finished')
|
2020-09-19 15:07:28 +00:00
|
|
|
|
|
|
|
if (itemIsNotInCompletedQueue) {
|
|
|
|
// * Add it
|
2020-07-16 20:20:13 +00:00
|
|
|
this.queueComplete.push(queueItem.uuid)
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-20 11:18:06 +00:00
|
|
|
const itemIsNotInQueue = this.queue.indexOf(queueItem.uuid) == -1
|
2020-09-19 15:07:28 +00:00
|
|
|
|
|
|
|
if (itemIsNotInQueue) {
|
2020-07-16 20:20:13 +00:00
|
|
|
this.queue.push(queueItem.uuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:18:06 +00:00
|
|
|
const needToStartDownload = (queueItem.progress > 0 && queueItem.progress < 100) || current
|
2020-09-19 15:07:28 +00:00
|
|
|
|
|
|
|
if (needToStartDownload) {
|
2020-07-16 20:20:13 +00:00
|
|
|
this.startDownload(queueItem.uuid)
|
|
|
|
}
|
|
|
|
|
2020-08-17 09:06:24 +00:00
|
|
|
if (!queueItem.silent) {
|
2020-09-15 20:44:29 +00:00
|
|
|
toast(this.$t('toasts.addedToQueue', { item: queueItem.title }), 'playlist_add_check')
|
2020-07-16 20:20:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updateQueue(update) {
|
|
|
|
// downloaded and failed default to false?
|
2020-08-14 17:49:36 +00:00
|
|
|
const { uuid, downloaded, failed, progress, conversion, error, data, errid } = update
|
2020-07-16 20:20:13 +00:00
|
|
|
|
|
|
|
if (uuid && this.queue.indexOf(uuid) > -1) {
|
|
|
|
if (downloaded) {
|
|
|
|
this.queueList[uuid].downloaded++
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
this.queueList[uuid].failed++
|
2020-07-23 14:18:28 +00:00
|
|
|
this.queueList[uuid].errors.push({ message: error, data: data, errid: errid })
|
2020-07-16 20:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (progress) {
|
|
|
|
this.queueList[uuid].progress = progress
|
|
|
|
}
|
2020-08-14 17:49:36 +00:00
|
|
|
|
|
|
|
if (conversion) {
|
2020-09-20 11:18:06 +00:00
|
|
|
this.queueList[uuid].conversion = conversion
|
2020-08-14 17:49:36 +00:00
|
|
|
}
|
2020-07-16 20:20:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
removeFromQueue(uuid) {
|
|
|
|
let index = this.queue.indexOf(uuid)
|
|
|
|
|
|
|
|
if (index > -1) {
|
2020-09-19 15:07:28 +00:00
|
|
|
this.$delete(this.queue, index)
|
|
|
|
this.$delete(this.queueList, uuid)
|
2020-07-16 20:20:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
removeAllDownloads(currentItem) {
|
|
|
|
this.queueComplete = []
|
|
|
|
|
2020-09-20 11:18:06 +00:00
|
|
|
if (!currentItem) {
|
2020-07-16 20:20:13 +00:00
|
|
|
this.queue = []
|
|
|
|
this.queueList = {}
|
|
|
|
} else {
|
|
|
|
this.queue = [currentItem]
|
2020-09-19 15:07:28 +00:00
|
|
|
|
2020-07-16 20:20:13 +00:00
|
|
|
let tempQueueItem = this.queueList[currentItem]
|
2020-09-19 15:07:28 +00:00
|
|
|
|
2020-07-16 20:20:13 +00:00
|
|
|
this.queueList = {}
|
|
|
|
this.queueList[currentItem] = tempQueueItem
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removedFinishedDownloads() {
|
2020-09-20 11:18:06 +00:00
|
|
|
this.queueComplete.forEach(uuid => {
|
|
|
|
this.$delete(this.queueList, uuid)
|
2020-07-16 20:20:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
this.queueComplete = []
|
|
|
|
},
|
2020-09-26 19:48:55 +00:00
|
|
|
toggleDownloadTab() {
|
2020-07-14 20:27:48 +00:00
|
|
|
this.setTabWidth()
|
|
|
|
|
|
|
|
this.$refs.container.style.transition = 'all 250ms ease-in-out'
|
|
|
|
|
|
|
|
// Toggle returns a Boolean based on the action it performed
|
|
|
|
let isHidden = this.$refs.container.classList.toggle('tab_hidden')
|
2020-10-14 20:18:13 +00:00
|
|
|
this.isExpanded = !isHidden
|
2020-07-14 20:27:48 +00:00
|
|
|
|
2020-10-14 20:18:13 +00:00
|
|
|
if (this.isExpanded) {
|
2020-07-14 20:27:48 +00:00
|
|
|
this.setTabWidth(this.cachedTabWidth)
|
|
|
|
}
|
|
|
|
|
2020-10-14 20:18:13 +00:00
|
|
|
localStorage.setItem('downloadTabOpen', this.isExpanded)
|
2020-07-14 20:27:48 +00:00
|
|
|
},
|
|
|
|
cleanQueue() {
|
|
|
|
socket.emit('removeFinishedDownloads')
|
|
|
|
},
|
|
|
|
cancelQueue() {
|
|
|
|
socket.emit('cancelAllDownloads')
|
|
|
|
},
|
2020-09-20 11:18:06 +00:00
|
|
|
openDownloadsFolder() {
|
|
|
|
// if (this.clientMode) {
|
|
|
|
socket.emit('openDownloadsFolder')
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
handleDrag(event) {
|
|
|
|
let newWidth = window.innerWidth - event.pageX + 2
|
|
|
|
|
|
|
|
if (newWidth < tabMinWidth) {
|
|
|
|
newWidth = tabMinWidth
|
|
|
|
} else if (newWidth > tabMaxWidth) {
|
|
|
|
newWidth = tabMaxWidth
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cachedTabWidth = newWidth
|
|
|
|
this.setTabWidth(newWidth)
|
|
|
|
},
|
|
|
|
startDrag() {
|
|
|
|
document.addEventListener('mousemove', this.handleDrag)
|
|
|
|
},
|
|
|
|
startDownload(uuid) {
|
|
|
|
this.$set(this.queueList[uuid], 'status', 'downloading')
|
|
|
|
},
|
2020-07-16 20:20:13 +00:00
|
|
|
finishDownload(uuid) {
|
2020-09-19 15:07:28 +00:00
|
|
|
let isInQueue = this.queue.indexOf(uuid) > -1
|
2020-07-16 20:20:13 +00:00
|
|
|
|
2020-09-19 15:07:28 +00:00
|
|
|
if (!isInQueue) return
|
2020-07-16 20:20:13 +00:00
|
|
|
|
2020-09-20 11:18:06 +00:00
|
|
|
this.$set(this.queueList[uuid], 'status', 'download finished')
|
2020-09-19 15:07:28 +00:00
|
|
|
toast(this.$t('toasts.finishDownload', { item: this.queueList[uuid].title }), 'done')
|
2020-07-16 20:20:13 +00:00
|
|
|
|
2020-09-19 15:07:28 +00:00
|
|
|
let index = this.queue.indexOf(uuid)
|
|
|
|
|
|
|
|
if (index > -1) {
|
|
|
|
this.queue.splice(index, 1)
|
|
|
|
this.queueComplete.push(uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.queue.length <= 0) {
|
|
|
|
toast(this.$t('toasts.allDownloaded'), 'done_all')
|
|
|
|
}
|
2020-07-16 20:20:13 +00:00
|
|
|
},
|
2020-08-14 17:49:36 +00:00
|
|
|
startConversion(uuid) {
|
2020-09-20 11:18:06 +00:00
|
|
|
this.$set(this.queueList[uuid], 'status', 'converting')
|
|
|
|
this.$set(this.queueList[uuid], 'conversion', 0)
|
2020-09-19 15:07:28 +00:00
|
|
|
},
|
2020-09-20 11:18:06 +00:00
|
|
|
async showErrorsTab(item) {
|
|
|
|
await this.setErrors(item)
|
2020-09-19 13:11:06 +00:00
|
|
|
|
|
|
|
this.$router.push({ name: 'Errors' })
|
2020-07-14 20:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|