A full-featured download manager.
fix: oddly stop seeding notify #604
Dr_rOot6d54e557b977
diff --git a/src/renderer/components/Native/EngineClient.vue b/src/renderer/components/Native/EngineClient.vueindex 0ffb2553..33c52f16 100644--- a/src/renderer/components/Native/EngineClient.vue+++ b/src/renderer/components/Native/EngineClient.vue@@ -7,30 +7,26 @@import { mapState } from 'vuex'import api from '@/api'import {- showItemInFolder,- addToRecentTask+ addToRecentTask,+ getTaskFullPath,+ showItemInFolder} from '@/utils/native'- import {- bytesToSize,- getTaskName,- getTaskFullPath- } from '@shared/utils'+ import { getTaskName } from '@shared/utils'export default {name: 'mo-engine-client',- data () {- return {- downloading: false- }- },computed: {isRenderer: () => is.renderer(),...mapState('app', {+ uploadSpeed: state => state.stat.uploadSpeed,downloadSpeed: state => state.stat.downloadSpeed,+ speed: state => state.stat.uploadSpeed + state.stat.downloadSpeed,interval: state => state.interval,- numActive: state => state.stat.numActive+ downloading: state => state.stat.numActive > 0}),...mapState('task', {+ messages: state => state.messages,+ seedingList: state => state.seedingList,taskItemInfoVisible: state => state.taskItemInfoVisible,currentTaskItem: state => state.currentTaskItem}),@@ -39,12 +35,12 @@})},watch: {- downloadSpeed (val) {- const speed = val > 0 ? `${bytesToSize(val)}/s` : ''- this.$electron.ipcRenderer.send('event', 'download-speed-change', speed)- },- numActive (val) {- this.downloading = val > 0+ speed (val) {+ const { uploadSpeed, downloadSpeed } = this+ this.$electron.ipcRenderer.send('event', 'speed-change', {+ uploadSpeed,+ downloadSpeed+ })},downloading (val, oldVal) {if (val !== oldVal && this.isRenderer) {@@ -65,6 +61,11 @@this.$store.dispatch('task/saveSession')console.log('aria2 onDownloadStart', event)const [{ gid }] = event+ const { seedingList } = this+ if (seedingList.includes(gid)) {+ return+ }+this.fetchTaskItem({ gid }).then((task) => {const taskName = getTaskName(task)@@ -75,6 +76,11 @@onDownloadPause (event) {console.log('aria2 onDownloadPause')const [{ gid }] = event+ const { seedingList } = this+ if (seedingList.includes(gid)) {+ return+ }+this.fetchTaskItem({ gid }).then((task) => {const taskName = getTaskName(task)@@ -114,6 +120,8 @@console.log('aria2 onDownloadComplete')this.$store.dispatch('task/fetchList')const [{ gid }] = event+ this.$store.dispatch('task/removeFromSeedingList', gid)+this.fetchTaskItem({ gid }).then((task) => {this.handleDownloadComplete(task, false)@@ -123,6 +131,13 @@console.log('aria2 onBtDownloadComplete')this.$store.dispatch('task/fetchList')const [{ gid }] = event+ const { seedingList } = this+ if (seedingList.includes(gid)) {+ return+ }++ this.$store.dispatch('task/addToSeedingList', gid)+this.fetchTaskItem({ gid }).then((task) => {this.handleDownloadComplete(task, true)diff --git a/src/renderer/components/Task/Index.vue b/src/renderer/components/Task/Index.vueindex c0546c57..695cb162 100644--- a/src/renderer/components/Task/Index.vue+++ b/src/renderer/components/Task/Index.vue@@ -252,6 +252,10 @@handleStopTaskSeeding (payload) {const { task } = payloadthis.$store.dispatch('task/stopSeeding', task)+ this.$msg.info({+ message: this.$t('task.bt-stopping-seeding-tip'),+ duration: 8000+ })},handleRestartTask (payload) {const { task, taskName, showDialog } = payloaddiff --git a/src/renderer/components/Task/TaskItem.vue b/src/renderer/components/Task/TaskItem.vueindex c6eca11e..0e7912a7 100644--- a/src/renderer/components/Task/TaskItem.vue+++ b/src/renderer/components/Task/TaskItem.vue@@ -16,12 +16,9 @@</template><script>- import {- getTaskFullPath,- getTaskName- } from '@shared/utils'+ import { getTaskName } from '@shared/utils'import { TASK_STATUS } from '@shared/constants'- import { openItem } from '@/utils/native'+ import { openItem, getTaskFullPath } from '@/utils/native'import TaskItemActions from './TaskItemActions'import TaskProgress from './TaskProgress'import TaskProgressInfo from './TaskProgressInfo'diff --git a/src/renderer/components/Task/TaskItemActions.vue b/src/renderer/components/Task/TaskItemActions.vueindex 05df7b60..bb59f566 100644--- a/src/renderer/components/Task/TaskItemActions.vue+++ b/src/renderer/components/Task/TaskItemActions.vue@@ -43,9 +43,9 @@import { TASK_STATUS } from '@shared/constants'import {checkTaskIsSeeder,- getTaskFullPath,getTaskName} from '@shared/utils'+ import { getTaskFullPath } from '@/utils/native'import '@/components/Icons/task-start-line'import '@/components/Icons/task-pause-line'import '@/components/Icons/task-stop-line'diff --git a/src/renderer/store/modules/task.js b/src/renderer/store/modules/task.jsindex 8e9b242b..6cf7bf22 100644--- a/src/renderer/store/modules/task.js+++ b/src/renderer/store/modules/task.js@@ -6,6 +6,7 @@ const state = {currentList: 'active',taskItemInfoVisible: false,currentTaskItem: null,+ seedingList: [],taskList: [],selectedGidList: []}@@ -14,6 +15,9 @@ const getters = {}const mutations = {+ UPDATE_SEEDING_LIST (state, seedingList) {+ state.seedingList = seedingList+ },UPDATE_TASK_LIST (state, taskList) {state.taskList = taskList},@@ -159,8 +163,29 @@ const actions = {dispatch('saveSession')})},- stopSeeding ({ dispatch }, task) {- const { gid } = task+ addToSeedingList ({ state, commit }, gid) {+ const { seedingList } = state+ if (seedingList.includes(gid)) {+ return+ }++ const list = [+ ...seedingList,+ gid+ ]+ commit('UPDATE_SEEDING_LIST', list)+ },+ removeFromSeedingList ({ state, commit }, gid) {+ const { seedingList } = state+ const idx = seedingList.indexOf(gid)+ if (idx === -1) {+ return+ }++ const list = [...seedingList.slice(0, idx), ...seedingList.slice(idx + 1)]+ commit('UPDATE_SEEDING_LIST', list)+ },+ stopSeeding ({ dispatch }, gid) {const options = {seedTime: 0}diff --git a/src/renderer/utils/native.js b/src/renderer/utils/native.jsindex c011b059..4c086a08 100644--- a/src/renderer/utils/native.js+++ b/src/renderer/utils/native.js@@ -1,10 +1,11 @@import is from 'electron-is'import { access, constants } from 'fs'+import { resolve } from 'path'import { Message } from 'element-ui'import {bytesToSize,- getTaskFullPath,+ getFileName,isMagnetTask} from '@shared/utils'import { APP_THEME, TASK_STATUS } from '@shared/constants'@@ -48,6 +49,38 @@ export function openItem (fullPath, { errorMsg }) {return result}+export function getTaskFullPath (task) {+ const { dir, files, bittorrent } = task+ let result = resolve(dir)++ // Magnet link task+ if (isMagnetTask(task)) {+ return result+ }++ if (bittorrent && bittorrent.info && bittorrent.info.name) {+ result = resolve(result, bittorrent.info.name)+ return result+ }++ const [file] = files+ const path = file.path ? resolve(file.path) : ''+ let fileName = ''++ if (path) {+ result = path+ } else {+ if (files && files.length === 1) {+ fileName = getFileName(file)+ if (fileName) {+ result = resolve(result, fileName)+ }+ }+ }++ return result+}+export function moveTaskFilesToTrash (task) {/*** For magnet link tasks, there is bittorrent, but there is no bittorrent.info.diff --git a/src/shared/utils/index.js b/src/shared/utils/index.jsindex f44359e2..54f62eac 100644--- a/src/shared/utils/index.js+++ b/src/shared/utils/index.js@@ -11,7 +11,6 @@ import {parseInt,pick} from 'lodash'-import { resolve } from 'path'import { userKeys, systemKeys, needRestartKeys } from '@shared/configKeys'import { ENGINE_RPC_HOST } from '@shared/constants'@@ -144,38 +143,6 @@ export function getFileName (file) {return path.substring(index + 1)}-export function getTaskFullPath (task) {- const { dir, files, bittorrent } = task- let result = resolve(dir)-- // Magnet link task- if (isMagnetTask(task)) {- return result- }-- if (bittorrent && bittorrent.info && bittorrent.info.name) {- result = resolve(result, bittorrent.info.name)- return result- }-- const [file] = files- const path = file.path ? resolve(file.path) : ''- let fileName = ''-- if (path) {- result = path- } else {- if (files && files.length === 1) {- fileName = getFileName(file)- if (fileName) {- result = resolve(result, fileName)- }- }- }-- return result-}-export function isMagnetTask (task) {const { bittorrent } = taskreturn bittorrent && !bittorrent.info