Skip to content

The only downloader you need. 下载器的集大成者。

feat(cards): 实现任务链接复制功能支持自定义MIME类型

XiaoYouChR888f8a3a1c84
diff --git a/app/supports/config.py b/app/supports/config.py
index 7b28a344..e96bfeb3 100644
--- a/app/supports/config.py
+++ b/app/supports/config.py
@@ -249,3 +249,4 @@ attachmentTypes = """3gp 7z aac ace aif arj asf avi bin bz2 dmg exe gz gzip img
wav wma wmv z zip esd wim msp apk apks apkm cab msp pkg"""
cfg = Config()
+GD3_COPY_MIME_TYPE = "application/x-gd3-copy"
diff --git a/app/view/components/cards.py b/app/view/components/cards.py
index 5675df1c..8f188fec 100644
--- a/app/view/components/cards.py
+++ b/app/view/components/cards.py
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import Any
-from PySide6.QtCore import Signal, QFileInfo, Qt, QEvent
+from PySide6.QtCore import Signal, QFileInfo, Qt, QEvent, QMimeData
from PySide6.QtGui import QColor, QPainter, QPen, QMouseEvent
from PySide6.QtWidgets import QWidget, QHBoxLayout, QFileIconProvider, QVBoxLayout, QApplication
from loguru import logger
@@ -13,6 +13,7 @@ from app.bases.models import Task, TaskStatus
from app.services.core_service import coreService
from app.supports.recorder import taskRecorder
from app.supports.utils import openFile, getReadableSize, getReadableTime, openFolder
+from app.supports.config import GD3_COPY_MIME_TYPE
from app.view.components.dialogs import DeleteTaskDialog
from app.view.components.labels import IconBodyLabel
@@ -151,10 +152,17 @@ class TaskCard(CardWidget):
def createContextMenu(self) -> RoundMenu | None:
menu = RoundMenu(parent=self)
copyUrlAction = Action(FluentIcon.COPY, self.tr("复制下载链接"), self)
- copyUrlAction.triggered.connect(lambda: QApplication.clipboard().setText(self.task.url))
+ copyUrlAction.triggered.connect(self._copyTaskUrl)
menu.addAction(copyUrlAction)
return menu
+ def _copyTaskUrl(self):
+ clipboard = QApplication.clipboard()
+ mimeData = QMimeData()
+ mimeData.setText(self.task.url)
+ mimeData.setData(GD3_COPY_MIME_TYPE, b"1")
+ clipboard.setMimeData(mimeData)
+
def mouseReleaseEvent(self, e):
super().mouseReleaseEvent(e)
if e.button() != Qt.MouseButton.LeftButton:
@@ -174,7 +182,7 @@ class TaskCard(CardWidget):
def contextMenuEvent(self, e):
menu = self.createContextMenu()
if menu is None:
- return super().contextMenuEvent(e)
+ super().contextMenuEvent(e)
menu.exec(e.globalPos())
e.accept()
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index 61b843e7..ee6c4f51 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -14,7 +14,7 @@ from qfluentwidgets import MSFluentWindow, SplashScreen, FluentIcon, NavigationI
from app.services.browser_service import BrowserService
from app.services.core_service import coreService
from app.services.feature_service import featureService
-from app.supports.config import cfg, DEFAULT_HEADERS, AUTHOR_URL, VERSION, FEEDBACK_URL
+from app.supports.config import cfg, DEFAULT_HEADERS, AUTHOR_URL, VERSION, FEEDBACK_URL, GD3_COPY_MIME_TYPE
from app.supports.recorder import taskRecorder
from app.supports.signal_bus import signalBus
from app.supports.update import fetchLatestRelease, hasNewerRelease, releaseVersion, selectCurrentPlatformAsset
@@ -213,7 +213,12 @@ class MainWindow(MSFluentWindow):
return urls
def _onClipboardDataChanged(self):
- urls = self._extractClipboardUrls(QApplication.clipboard().text())
+ clipboard = QApplication.clipboard()
+ mimeData = clipboard.mimeData()
+ if mimeData.hasFormat(GD3_COPY_MIME_TYPE):
+ return
+
+ urls = self._extractClipboardUrls(clipboard.text())
if not urls:
return