The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(core): 添加桌面通知功能和优化路径获取
XiaoYouChR17c883955512
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.pyindex 04a096fd..4dc28734 100644--- a/Ghost-Downloader-3.py+++ b/Ghost-Downloader-3.py@@ -13,7 +13,7 @@ from app.services.feature_service import featureServicefrom app.supports.application import SingletonApplicationfrom app.supports.config import cfg-appLocalDataLocation = QStandardPaths.standardLocations(QStandardPaths.StandardLocation.AppLocalDataLocation)[0]+appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation)qconfig.load(f"{appLocalDataLocation}/GhostDownloader/UserConfig.json", cfg)diff --git a/app/services/core_service.py b/app/services/core_service.pyindex c9e9227b..e43c42e8 100644--- a/app/services/core_service.py+++ b/app/services/core_service.py@@ -1,25 +1,26 @@import asyncioimport traceback+from pathlib import Pathfrom typing import Callable, Dict, Any, Coroutine-from PySide6.QtCore import QThread, QTimer-from PySide6.QtWidgets import QApplication+from PySide6.QtCore import QThread, QTimer, QStandardPaths, QResource, QFileInfo, Qt+from PySide6.QtWidgets import QApplication, QFileIconProvider+from desktop_notifier import DesktopNotifier, Icon, Buttonfrom loguru import loggerfrom app.bases.models import Task, TaskStatusfrom app.services.feature_service import featureService+from app.supports.utils import openFile+def getNotifierIcon() -> Path:+ _ = Path(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.TempLocation) + "/gd3_logo.png")+ if not _.exists():+ with open(_, "wb") as f:+ f.write(QResource(":/image/logo.png").data())+ return _+class CoreService(QThread):- """核心服务类,在子线程中运行独立的 AsyncIO 事件循环-- 设计理念:- 1. 在 QThread 子线程中创建并运行独立的 asyncio 事件循环- 2. 提供线程安全的接口供主线程(Qt UI)调用- 3. 仅使用回调函数进行通知,避免 Qt Signal 的维护复杂性- 4. 通过 Qt 的线程安全机制确保 UI 更新的安全性- 5. 协调 FeatureService 进行 URL 解析和任务创建- """def __init__(self):super().__init__()@@ -29,6 +30,16 @@ class CoreService(QThread):self.tasks: set[Task] = set()self.runningTasks: dict[str, asyncio.Task] = {}self._pendingCallbacks: Dict[str, Callable[[dict, str | None], Coroutine | None]] = {}+ self.desktopNotifier = DesktopNotifier(app_name="Ghost Downloader", app_icon=Icon(path=getNotifierIcon()))++ def sendNotification(self, task: Task):+ iconTempPath = Path(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.TempLocation)) / "finished_file_icon.png"+ QFileIconProvider().icon(QFileInfo(task.stages[0].resolvePath)).pixmap(48, 48).scaled(128, 128,+ aspectMode=Qt.AspectRatioMode.KeepAspectRatio,+ mode=Qt.TransformationMode.SmoothTransformation).save(str(iconTempPath), "PNG")+ buttons = [Button(self.tr('打开文件'), lambda: openFile(task.stages[0].resolvePath)), Button(self.tr('打开目录'), lambda: openFile(task.path))]+ self.loop.create_task(self.desktopNotifier.send(self.tr("下载完成"), task.title, buttons=buttons, on_clicked=lambda: openFile(task.stages[0].resolvePath), icon=Icon(path=iconTempPath)))+def runCoroutine(self, coroutine: Coroutine, callback: Callable[[dict, str | None], Coroutine | None] | None = None):if callback is not None:diff --git a/app/supports/recorder.py b/app/supports/recorder.pyindex eb936c7b..aa4ded97 100644--- a/app/supports/recorder.py+++ b/app/supports/recorder.py@@ -10,7 +10,7 @@ from app.bases.models import Taskclass TaskRecorder:def __init__(self):- appLocalDataLocation = QStandardPaths.standardLocations(QStandardPaths.StandardLocation.AppLocalDataLocation)[0]+ appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation)recordFile = Path(f"{appLocalDataLocation}/GhostDownloader/Memory.log")if not recordFile.exists():recordFile.parent.mkdir(parents=True, exist_ok=True)@@ -18,7 +18,7 @@ class TaskRecorder:self.fileHandle = open(recordFile, "a+", encoding="utf-8")self.fileHandle.seek(0)- self.memorizedTasks: dict[str, Task] = []+ self.memorizedTasks: dict[str, Task] = {}def load(self):self.memorizedTasks = self.read()diff --git a/app/view/pages/task_page.py b/app/view/pages/task_page.pyindex 6b28bf2a..69c4b862 100644--- a/app/view/pages/task_page.py+++ b/app/view/pages/task_page.py@@ -1,7 +1,7 @@from enum import IntEnumfrom sys import platform-from PySide6.QtCore import Qt, QSize, QTimer+from PySide6.QtCore import Qt, QSize, QTimer, Slotfrom PySide6.QtGui import QPainter, QColor, QActionGroupfrom PySide6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGraphicsDropShadowEffect, QDialogfrom loguru import logger@@ -10,6 +10,7 @@ from qfluentwidgets import ScrollArea, PrimaryPushButton, FluentIcon, PushButtonCommandBarView, isDarkTheme, IconWidget, CaptionLabel, CheckableMenu, MenuIndicatorType, \DropDownToolButton+from app.services.core_service import coreServicefrom app.services.feature_service import featureServicefrom app.bases.models import TaskStatusfrom app.supports.config import cfg@@ -190,7 +191,12 @@ class TaskPage(ScrollArea):self.sortCards()self.refreshCardVisibility()+ @Slot()def _onCardFinished(self):+ sender = self.sender()+ if isinstance(sender, TaskCard):+ coreService.sendNotification(sender.task)+if not self.planButton.isChecked() or not self.planAction or not self.cards:return