Skip to content

Commit

Permalink
fix: oddly stop seeding notify #604
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Jun 20, 2020
1 parent 3e61adc commit 6d54e55
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 61 deletions.
53 changes: 34 additions & 19 deletions src/renderer/components/Native/EngineClient.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/Task/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@
handleStopTaskSeeding (payload) {
const { task } = payload
this.$store.dispatch('task/stopSeeding', task)
this.$msg.info({
message: this.$t('task.bt-stopping-seeding-tip'),
duration: 8000
})
},
handleRestartTask (payload) {
const { task, taskName, showDialog } = payload
Expand Down
7 changes: 2 additions & 5 deletions src/renderer/components/Task/TaskItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Task/TaskItemActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
29 changes: 27 additions & 2 deletions src/renderer/store/modules/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const state = {
currentList: 'active',
taskItemInfoVisible: false,
currentTaskItem: null,
seedingList: [],
taskList: [],
selectedGidList: []
}
Expand All @@ -14,6 +15,9 @@ const getters = {
}

const mutations = {
UPDATE_SEEDING_LIST (state, seedingList) {
state.seedingList = seedingList
},
UPDATE_TASK_LIST (state, taskList) {
state.taskList = taskList
},
Expand Down Expand Up @@ -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
}
Expand Down
35 changes: 34 additions & 1 deletion src/renderer/utils/native.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 0 additions & 33 deletions src/shared/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 } = task
return bittorrent && !bittorrent.info
Expand Down

0 comments on commit 6d54e55

Please sign in to comment.