A full-featured download manager.
refactor: task status
Dr_rOotf67b9b8dd607
diff --git a/src/renderer/components/Task/TaskItem.vue b/src/renderer/components/Task/TaskItem.vueindex 2296e99d..877a1ddc 100644--- a/src/renderer/components/Task/TaskItem.vue+++ b/src/renderer/components/Task/TaskItem.vue@@ -54,6 +54,7 @@import {openItem} from '@/components/Native/utils'+ import { TASK_STATUS } from '@shared/constants'export default {name: 'mo-task-item',@@ -90,9 +91,10 @@methods: {onDbClick () {const { status } = this.task- if (status === 'complete') {+ const { COMPLETE, WAITING, PAUSED } = TASK_STATUS+ if (status === COMPLETE) {this.openTask()- } else if (['waiting', 'paused'].includes(status) !== -1) {+ } else if ([WAITING, PAUSED].includes(status) !== -1) {this.toggleTask()}},diff --git a/src/renderer/components/Task/TaskItemActions.vue b/src/renderer/components/Task/TaskItemActions.vueindex bc87515e..b1f521c7 100644--- a/src/renderer/components/Task/TaskItemActions.vue+++ b/src/renderer/components/Task/TaskItemActions.vue@@ -10,7 +10,7 @@<i v-if="action === 'RESUME'" @click.stop="onResumeClick"><mo-icon name="task-start-line" width="14" height="14" /></i>- <i v-if="action === 'RESTART'" @click="onRestartClick">+ <i v-if="action === 'RESTART'" @click.stop="onRestartClick"><mo-icon name="task-restart" width="14" height="14" /></i><i v-if="action === 'DELETE'" @click.stop="onDeleteClick">@@ -38,17 +38,7 @@<script>import is from 'electron-is'import * as clipboard from 'clipboard-polyfill'- import { ADD_TASK_TYPE } from '@shared/constants'- import '@/components/Icons/task-start-line'- import '@/components/Icons/task-pause-line'- import '@/components/Icons/task-stop-line'- import '@/components/Icons/task-restart'- import '@/components/Icons/delete'- import '@/components/Icons/folder'- import '@/components/Icons/link'- import '@/components/Icons/info-circle'- import '@/components/Icons/more'- import '@/components/Icons/trash'+ import { ADD_TASK_TYPE, TASK_STATUS } from '@shared/constants'import {showItemInFolder,moveTaskFilesToTrash@@ -60,15 +50,25 @@getTaskUri,parseHeader} from '@shared/utils'+ import '@/components/Icons/task-start-line'+ import '@/components/Icons/task-pause-line'+ import '@/components/Icons/task-stop-line'+ import '@/components/Icons/task-restart'+ import '@/components/Icons/delete'+ import '@/components/Icons/folder'+ import '@/components/Icons/link'+ import '@/components/Icons/info-circle'+ import '@/components/Icons/more'+ import '@/components/Icons/trash'const taskActionsMap = {- active: ['PAUSE', 'DELETE'],- paused: ['RESUME', 'DELETE'],- waiting: ['RESUME', 'DELETE'],- error: ['RESTART', 'TRASH'],- complete: ['RESTART', 'TRASH'],- removed: ['RESTART', 'TRASH'],- seeding: ['STOP', 'DELETE']+ [TASK_STATUS.ACTIVE]: ['PAUSE', 'DELETE'],+ [TASK_STATUS.PAUSED]: ['RESUME', 'DELETE'],+ [TASK_STATUS.WAITING]: ['RESUME', 'DELETE'],+ [TASK_STATUS.ERROR]: ['RESTART', 'TRASH'],+ [TASK_STATUS.COMPLETE]: ['RESTART', 'TRASH'],+ [TASK_STATUS.REMOVED]: ['RESTART', 'TRASH'],+ [TASK_STATUS.SEEDING]: ['STOP', 'DELETE']}export default {@@ -96,7 +96,7 @@taskStatus () {const { task, isSeeder } = thisif (isSeeder) {- return 'seeding'+ return TASK_STATUS.SEEDING} else {return task.status}@@ -175,7 +175,7 @@const { task, taskName } = thisconst { gid, status } = taskconst uri = getTaskUri(task)- const isNeedShowDialog = status === 'complete' || !!event.altKey+ const isNeedShowDialog = status === TASK_STATUS.COMPLETE || !!event.altKeythis.$store.dispatch('task/getTaskOption', gid).then((data) => {console.log('getTaskOption===>', data)diff --git a/src/renderer/components/Task/TaskProgress.vue b/src/renderer/components/Task/TaskProgress.vueindex 6c74a6f9..bb3ab559 100644--- a/src/renderer/components/Task/TaskProgress.vue+++ b/src/renderer/components/Task/TaskProgress.vue@@ -1,6 +1,6 @@<template><el-progress- v-if="status === 'active'"+ v-if="isActive":percentage="percent":show-text="false"status="success"@@ -15,6 +15,7 @@</template><script>+ import { TASK_STATUS } from '@shared/constants'import { calcProgress } from '@shared/utils'import colors from '@shared/colors'@@ -29,21 +30,19 @@},status: {type: String,- default: 'active'+ default: TASK_STATUS.ACTIVE}},computed: {- percent: function () {+ isActive () {+ return this.status === TASK_STATUS.ACTIVE+ },+ percent () {return calcProgress(this.total, this.completed)},- color: function () {+ color () {return colors[this.status]}- },- methods: {}}</script>--<style lang="scss">-</style>diff --git a/src/renderer/components/Task/TaskProgressInfo.vue b/src/renderer/components/Task/TaskProgressInfo.vuenew file mode 100644index 00000000..2f4b7953--- /dev/null+++ b/src/renderer/components/Task/TaskProgressInfo.vue@@ -0,0 +1,106 @@+<template>+ <el-row class="task-progress-info">+ <el-col :span="10" class="task-progress-info-left">+ <div v-if="task.totalLength > 0">+ {{ task.completedLength | bytesToSize }} / {{ task.totalLength | bytesToSize }}+ </div>+ </el-col>+ <el-col :span="14" class="task-progress-info-right">+ <div class="task-speed-info" v-if="isActive">+ <span class="task-speed-text" v-if="isBT">+ <i><mo-icon name="arrow-up" width="10" height="10" /></i>+ <i>{{ task.uploadSpeed | bytesToSize }}/s</i>+ </span>+ <span class="task-speed-text">+ <i><mo-icon name="arrow-down" width="10" height="10" /></i>+ <i>{{ task.downloadSpeed | bytesToSize }}/s</i>+ </span>+ <span class="task-speed-text" v-if="remaining > 0">+ {{+ remaining | timeFormat({+ prefix: $t('task.remaining-prefix'),+ i18n: {+ 'gt1d': $t('app.gt1d'),+ 'hour': $t('app.hour'),+ 'minute': $t('app.minute'),+ 'second': $t('app.second')+ }+ })+ }}+ </span>+ <span class="task-speed-text">+ <i><mo-icon name="node" width="10" height="10" /></i>+ <i>{{ task.connections }}</i>+ </span>+ </div>+ </el-col>+ </el-row>+</template>++<script>+ import {+ bytesToSize,+ checkTaskIsBT,+ checkTaskIsSeeder,+ timeFormat,+ timeRemaining+ } from '@shared/utils'+ import { TASK_STATUS } from '@shared/constants'+ import '@/components/Icons/arrow-up'+ import '@/components/Icons/arrow-down'+ import '@/components/Icons/node'++ export default {+ name: 'mo-task-progress-info',+ props: {+ task: {+ type: Object+ }+ },+ computed: {+ isActive () {+ return this.task.status === TASK_STATUS.ACTIVE+ },+ isBT () {+ return checkTaskIsBT(this.task)+ },+ isSeeder () {+ return checkTaskIsSeeder(this.task)+ },+ remaining () {+ const { totalLength, completedLength, downloadSpeed } = this.task+ return timeRemaining(totalLength, completedLength, downloadSpeed)+ }+ },+ filters: {+ bytesToSize,+ timeFormat+ }+ }+</script>++<style lang="scss">+ .task-progress-info {+ font-size: 12px;+ line-height: 14px;+ min-height: 14px;+ color: #9B9B9B;+ margin-top: 8px;+ }+ .task-progress-info-left {+ min-height: 14px;+ text-align: left;+ }+ .task-progress-info-right {+ min-height: 14px;+ text-align: right;+ }+ .task-speed-info {+ & > .task-speed-text {+ margin-left: 8px;+ & > i {+ vertical-align: middle;+ }+ }+ }+</style>diff --git a/src/renderer/store/modules/task.js b/src/renderer/store/modules/task.jsindex e2dc5ca4..03b1d898 100644--- a/src/renderer/store/modules/task.js+++ b/src/renderer/store/modules/task.js@@ -1,4 +1,5 @@import api from '@/api'+import { TASK_STATUS } from '@shared/constants'const state = {currentList: 'active',@@ -147,7 +148,8 @@ const actions = {},removeTaskRecord ({ dispatch }, task) {const { gid, status } = task- if (['error', 'complete', 'removed'].indexOf(status) === -1) {+ const { ERROR, COMPLETE, REMOVED } = TASK_STATUS+ if ([ERROR, COMPLETE, REMOVED].indexOf(status) === -1) {return}return api.removeTaskRecord({ gid })@@ -162,9 +164,10 @@ const actions = {},toggleTask ({ dispatch }, task) {const { status } = task- if (status === 'active') {+ const { ACTIVE, WAITING, PAUSED } = TASK_STATUS+ if (status === ACTIVE) {return dispatch('pauseTask', task)- } else if (status === 'waiting' || status === 'paused') {+ } else if (status === WAITING || status === PAUSED) {return dispatch('resumeTask', task)}}diff --git a/src/shared/constants.js b/src/shared/constants.jsindex 74e6275b..2429e859 100644--- a/src/shared/constants.js+++ b/src/shared/constants.js@@ -16,6 +16,16 @@ export const ADD_TASK_TYPE = {TORRENT: 'torrent'}+export const TASK_STATUS = {+ ACTIVE: 'active',+ WAITING: 'waiting',+ PAUSED: 'paused',+ ERROR: 'error',+ COMPLETE: 'complete',+ REMOVED: 'removed',+ SEEDING: 'seeding'+}+export const ENGINE_RPC_HOST = '127.0.0.1'export const ENGINE_RPC_PORT = 16800