下载模块 Init

This commit is contained in:
zhongluofeng
2026-07-20 18:28:34 +08:00
parent e84958e0fc
commit 548b022426
37 changed files with 4795 additions and 65 deletions
File diff suppressed because it is too large Load Diff
+43 -5
View File
@@ -1,11 +1,27 @@
import type { ModuleConfig } from '@/types/module'
import type { SearchIndexItem } from '@/stores/searchIndex'
import { invoke } from '@tauri-apps/api/core'
const searchItems: SearchIndexItem[] = [
{
title: '下载管理',
description: '管理下载任务',
keywords: ['下载', 'download', '文件', 'file']
title: '下载任务',
description: '查看与管理下载任务',
keywords: ['下载', 'download', '任务', 'task', 'aria2']
},
{
title: '添加下载',
description: '添加 HTTP/HTTPS 直链下载',
keywords: ['添加', '链接', 'url', 'add', '新建']
},
{
title: '下载设置',
description: '配置下载目录、速度限制与 RPC',
keywords: ['设置', 'setting', 'rpc', '速度', '端口', '目录']
},
{
title: '浏览器扩展',
description: '安装 Thing Extension 接管浏览器下载',
keywords: ['扩展', 'extension', '浏览器', 'chrome', 'edge']
}
]
@@ -13,18 +29,40 @@ export const moduleConfig: ModuleConfig = {
id: 'downloader',
name: '下载器',
icon: 'downloader',
description: 'HTTP下载、BT/磁力链接支持',
description: '基于 aria2 的多线程 HTTP 下载管理',
category: 'network',
defaultEnabled: true,
loader: () => import('./DownloaderModule.vue'),
searchItems,
// 进程由 Aria2Manager 通过 ProcessManager 统一管理(id='downloader'),
// executable/args 在运行时由后端确定,此处仅声明 hasProcess 以便禁用时自动停止。
process: {
name: 'aria2c',
executable: '',
args: ['--enable-rpc', '--rpc-listen-port=6800'],
autoStart: false,
restartOnCrash: true,
maxRestarts: 3
},
lifecycle: {
// 启用模块时若用户开启了"自动启动",则随模块启用而运行 aria2
onEnable: async () => {
try {
const s = await invoke<{ autoStart?: boolean }>('downloader_get_settings')
if (s.autoStart) {
await invoke('downloader_start')
}
} catch {
/* 忽略:可能内核未安装 */
}
},
// 禁用模块时停止 aria2 进程(cleanup_on_exit 会在应用退出时调用)
onDisable: async () => {
try {
await invoke('downloader_stop')
} catch {
/* 忽略:可能进程未运行 */
}
}
},
order: 50
}