Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Context from './core/Context'
import ConfigManager from './core/ConfigManager'
import { setupLocaleManager } from './ui/Locale'
import Engine from './core/Engine'
import HistoryManager from './core/HistoryManager'
import EngineClient from './core/EngineClient'
import UPnPManager from './core/UPnPManager'
import AutoLaunchManager from './core/AutoLaunchManager'
Expand Down Expand Up @@ -58,6 +59,8 @@ export default class Application extends EventEmitter {

this.initUPnPManager()

this.initHistoryManager()

this.startEngine()

this.initEngineClient()
Expand Down Expand Up @@ -190,6 +193,10 @@ export default class Application extends EventEmitter {
})
}

initHistoryManager () {
this.historyManager = new HistoryManager()
}

initAutoLaunchManager () {
this.autoLaunchManager = new AutoLaunchManager()
}
Expand Down Expand Up @@ -956,6 +963,7 @@ export default class Application extends EventEmitter {
})

this.on('task-download-complete', (task, path) => {
this.historyManager.add(task)
this.dockManager.openDock(path)

if (is.linux()) {
Expand Down Expand Up @@ -1021,5 +1029,17 @@ export default class Application extends EventEmitter {
}
return result
})

ipcMain.handle('history:get-list', async () => {
return this.historyManager.getAll()
})

ipcMain.handle('history:remove', async (event, gid) => {
return this.historyManager.remove(gid)
})

ipcMain.handle('history:clear', async () => {
return this.historyManager.clear()
})
}
}
52 changes: 52 additions & 0 deletions src/main/core/HistoryManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Store from 'electron-store'
import { getConfigBasePath } from '../utils/index'

export default class HistoryManager {
constructor () {
this.store = new Store({
name: 'history',
cwd: getConfigBasePath(),
defaults: {
tasks: []
}
})
}

add (task) {
const tasks = this.store.get('tasks', [])
// Avoid duplicates by GID
const exists = tasks.find(t => t.gid === task.gid)
if (exists) {
return
}

// Add timestamp
const record = {
...task,
completedTime: Date.now()
}

tasks.unshift(record)

// Keep only last 1000 records
if (tasks.length > 1000) {
tasks.pop()
}

this.store.set('tasks', tasks)
}

getAll () {
return this.store.get('tasks', [])
}

remove (gid) {
const tasks = this.store.get('tasks', [])
const newTasks = tasks.filter(t => t.gid !== gid)
this.store.set('tasks', newTasks)
}

clear () {
this.store.set('tasks', [])
}
}
15 changes: 15 additions & 0 deletions src/renderer/api/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,26 @@ export default class Api {
return this.fetchWaitingTaskList(params)
case 'stopped':
return this.fetchStoppedTaskList(params)
case 'history':
return this.fetchHistoryTaskList(params)
default:
return this.fetchDownloadingTaskList(params)
}
}

fetchHistoryTaskList (params = {}) {
return ipcRenderer.invoke('history:get-list')
}

removeHistoryTask (params = {}) {
const { gid } = params
return ipcRenderer.invoke('history:remove', gid)
}

clearHistoryTaskList (params = {}) {
return ipcRenderer.invoke('history:clear')
}

fetchTaskItem (params = {}) {
const { gid, keys } = params
const args = compactUndefined([gid, keys])
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/Subnav/TaskSubnav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
</i>
<span>{{ $t('task.stopped') }}</span>
</li>
<li
@click="() => nav('history')"
:class="[ current === 'history' ? 'active' : '' ]"
>
<i class="subnav-icon">
<mo-icon name="task-history" width="20" height="20" />
</i>
<span>{{ $t('task.history') }}</span>
</li>
</ul>
</nav>
</template>
Expand All @@ -37,6 +46,7 @@
import '@/components/Icons/task-start'
import '@/components/Icons/task-pause'
import '@/components/Icons/task-stop'
import '@/components/Icons/task-history'

export default {
name: 'mo-task-subnav',
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/Task/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
key: 'stopped',
title: this.$t('task.stopped'),
route: '/task/stopped'
},
{
key: 'history',
title: this.$t('task.history'),
route: '/task/history'
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Task/TaskActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
effect="dark"
placement="bottom"
:content="$t('task.delete-selected-tasks')"
v-if="currentList !== 'stopped'"
v-if="!['stopped', 'history'].includes(currentList)"
>
<i
class="task-action"
Expand Down Expand Up @@ -59,7 +59,7 @@
effect="dark"
placement="bottom"
:content="$t('task.purge-record')"
v-if="currentList === 'stopped'"
v-if="['stopped', 'history'].includes(currentList)"
>
<i class="task-action" @click="onPurgeRecordClick">
<mo-icon name="purge" width="14" height="14" />
Expand Down
23 changes: 18 additions & 5 deletions src/renderer/store/modules/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ const actions = {
dispatch('hideTaskDetail')
}

return api.removeTask({ gid })
const promise = state.currentList === 'history'
? api.removeHistoryTask({ gid })
: api.removeTask({ gid })

return promise
.finally(() => {
dispatch('fetchList')
dispatch('saveSession')
Expand Down Expand Up @@ -250,17 +254,26 @@ const actions = {
}

const { ERROR, COMPLETE, REMOVED } = TASK_STATUS
if ([ERROR, COMPLETE, REMOVED].indexOf(status) === -1) {
if ([ERROR, COMPLETE, REMOVED].indexOf(status) === -1 && state.currentList !== 'history') {
return
}
return api.removeTaskRecord({ gid })

const promise = state.currentList === 'history'
? api.removeHistoryTask({ gid })
: api.removeTaskRecord({ gid })

return promise
.finally(() => dispatch('fetchList'))
},
saveSession () {
api.saveSession()
},
purgeTaskRecord ({ dispatch }) {
return api.purgeTaskRecord()
purgeTaskRecord ({ state, dispatch }) {
const promise = state.currentList === 'history'
? api.clearHistoryTaskList()
: api.purgeTaskRecord()

return promise
.finally(() => dispatch('fetchList'))
},
toggleTask ({ dispatch }, task) {
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/en-US/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
'active': 'Downloading',
'waiting': 'Waiting',
'stopped': 'Stopped',
'history': 'History',
'new-task': 'New Task',
'new-bt-task': 'New BT Task',
'open-file': 'Open Torrent File...',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/zh-CN/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
'active': '下载中',
'waiting': '等待中',
'stopped': '已停止',
'history': '历史记录',
'new-task': '新建任务',
'new-bt-task': '新建 BT 任务',
'open-file': '打开种子文件...',
Expand Down