A full-featured download manager.
refactor: remove task
Dr_rOot3777a1f75343
diff --git a/src/renderer/components/Task/TaskItemActions.vue b/src/renderer/components/Task/TaskItemActions.vueindex b1f521c7..fd87fb26 100644--- a/src/renderer/components/Task/TaskItemActions.vue+++ b/src/renderer/components/Task/TaskItemActions.vue@@ -119,18 +119,29 @@methods: {isRenderer: is.renderer,deleteTaskFiles (task) {- moveTaskFilesToTrash(task, {- pathErrorMsg: this.$t('task.file-path-error'),- delFailMsg: this.$t('task.remove-task-file-fail'),- delConfigFailMsg: this.$t('task.remove-task-config-file-fail')- })+ try {+ const result = moveTaskFilesToTrash(task)++ if (!result) {+ throw new Error('task.remove-task-file-fail')+ }+ } catch (err) {+ this.$msg.error(this.$t(err.message))+ }},- removeTaskItem (task, isRemoveWithFiles) {- this.$store.dispatch('task/removeTask', this.task)- .then(() => {+ removeTask (task, isRemoveWithFiles) {+ this.$store.dispatch('task/forcePauseTask', task)+ .finally(() => {if (isRemoveWithFiles) {this.deleteTaskFiles(task)}++ return this.removeTaskItem(task)+ })+ },+ removeTaskItem (task) {+ return this.$store.dispatch('task/removeTask', this.task)+ .then(() => {this.$msg.success(this.$t('task.delete-task-success', {taskName: this.taskName}))@@ -144,11 +155,18 @@})},removeTaskRecord (task, isRemoveWithFiles) {- this.$store.dispatch('task/removeTaskRecord', this.task)- .then(() => {+ this.$store.dispatch('task/forcePauseTask', task)+ .finally(() => {if (isRemoveWithFiles) {this.deleteTaskFiles(task)}++ return this.removeTaskRecordItem(task)+ })+ },+ removeTaskRecordItem (task) {+ return this.$store.dispatch('task/removeTaskRecord', this.task)+ .then(() => {this.$msg.success(this.$t('task.remove-record-success', {taskName: this.taskName}))@@ -260,7 +278,7 @@checkboxChecked: isChecked}).then(({ response, checkboxChecked }) => {if (response === 0) {- self.removeTaskItem(task, checkboxChecked)+ self.removeTask(task, checkboxChecked)}})},@@ -312,6 +330,7 @@// width: 28px;height: 24px;padding: 0 10px;+ margin: 0;overflow: hidden;user-select: none;cursor: default;diff --git a/src/renderer/store/modules/task.js b/src/renderer/store/modules/task.jsindex 03b1d898..6447c547 100644--- a/src/renderer/store/modules/task.js+++ b/src/renderer/store/modules/task.js@@ -91,18 +91,20 @@ const actions = {},removeTask ({ dispatch }, task) {const { gid } = task- return api.forcePauseTask({ gid })- .catch((e) => {- console.log(`[Motrix] removeTask.forcePauseTask#[${gid}] fail`, e.message)- })+ return api.removeTask({ gid }).finally(() => {- return api.removeTask({ gid })- .finally(() => {- dispatch('fetchList')- dispatch('saveSession')- })+ dispatch('fetchList')+ dispatch('saveSession')})},+ forcePauseTask (_, task) {+ const { gid, status } = task+ if (status !== TASK_STATUS.ACTIVE) {+ return Promise.resolve(true)+ }++ return api.forcePauseTask({ gid })+ },pauseTask ({ dispatch }, task) {const { gid } = taskreturn api.pauseTask({ gid })