Skip to content

A full-featured download manager.

feat: add taskbar progress (#1424)

Shatyuka41a81e779335
diff --git a/src/main/Application.js b/src/main/Application.js
index b73b5aab..d9687e68 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -846,6 +846,16 @@ export default class Application extends EventEmitter {
}
app.addRecentDocument(path)
})
+
+ this.on('progress-change', (progress) => {
+ if (this.updateManager.isChecking) {
+ return
+ }
+ if (!is.windows() && progress === 2) {
+ progress = 0
+ }
+ this.windowManager.getWindow('index').setProgressBar(progress)
+ })
}
handleIpcMessages () {
diff --git a/src/renderer/api/Api.js b/src/renderer/api/Api.js
index b7d55d52..957bba58 100644
--- a/src/renderer/api/Api.js
+++ b/src/renderer/api/Api.js
@@ -235,6 +235,12 @@ export default class Api {
return this.client.call('tellStopped', ...args)
}
+ fetchActiveTaskList (params = {}) {
+ const { keys } = params
+ const args = compactUndefined([keys])
+ return this.client.call('tellActive', ...args)
+ }
+
fetchTaskList (params = {}) {
const { type } = params
switch (type) {
diff --git a/src/renderer/components/Native/EngineClient.vue b/src/renderer/components/Native/EngineClient.vue
index dab1f53e..50e667b1 100644
--- a/src/renderer/components/Native/EngineClient.vue
+++ b/src/renderer/components/Native/EngineClient.vue
@@ -21,7 +21,8 @@
downloadSpeed: state => state.stat.downloadSpeed,
speed: state => state.stat.uploadSpeed + state.stat.downloadSpeed,
interval: state => state.interval,
- downloading: state => state.stat.numActive > 0
+ downloading: state => state.stat.numActive > 0,
+ progress: state => state.progress
}),
...mapState('task', {
messages: state => state.messages,
@@ -50,6 +51,9 @@
if (val !== oldVal && this.isRenderer) {
this.$electron.ipcRenderer.send('event', 'download-status-change', val)
}
+ },
+ progress (val) {
+ this.$electron.ipcRenderer.send('event', 'progress-change', val)
}
},
methods: {
@@ -217,6 +221,7 @@
},
polling () {
this.$store.dispatch('app/fetchGlobalStat')
+ this.$store.dispatch('app/fetchProgress')
this.$store.dispatch('task/fetchList')
if (this.taskDetailVisible && this.currentTaskGid) {
diff --git a/src/renderer/store/modules/app.js b/src/renderer/store/modules/app.js
index 974d0529..92ff12b1 100644
--- a/src/renderer/store/modules/app.js
+++ b/src/renderer/store/modules/app.js
@@ -28,7 +28,8 @@ const state = {
addTaskType: ADD_TASK_TYPE.URI,
addTaskUrl: '',
addTaskTorrents: [],
- addTaskOptions: {}
+ addTaskOptions: {},
+ progress: 0
}
const getters = {
@@ -92,6 +93,9 @@ const mutations = {
if (state.interval > MIN_INTERVAL) {
state.interval -= millisecond
}
+ },
+ UPDATE_PROGRESS (state, progress) {
+ state.progress = progress
}
}
@@ -172,6 +176,28 @@ const actions = {
},
resetInterval ({ commit }) {
commit('UPDATE_INTERVAL', BASE_INTERVAL)
+ },
+ fetchProgress ({ commit }) {
+ api.fetchActiveTaskList()
+ .then((data) => {
+ let progress = -1
+ if (data.length !== 0) {
+ data.forEach((task) => {
+ task.totalLength = Number(task.totalLength)
+ task.completedLength = Number(task.completedLength)
+ })
+ const realTotal = data.reduce((total, task) => total + task.totalLength, 0)
+ if (realTotal === 0) {
+ progress = 2
+ } else {
+ const tasks = data.filter((task) => task.totalLength !== 0)
+ const completed = tasks.reduce((total, task) => total + task.completedLength, 0)
+ const total = tasks.reduce((total, task) => total + task.totalLength, 0)
+ progress = completed / total
+ }
+ }
+ commit('UPDATE_PROGRESS', progress)
+ })
}
}