Skip to content

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

fix(drag): 内部拖文件不再触发 MainWindow 的拖放接收

XiaoYouChRc93fdc5e59f0
diff --git a/app/platform/application.py b/app/platform/application.py
index e18f1087..aa24bdfb 100644
--- a/app/platform/application.py
+++ b/app/platform/application.py
@@ -35,6 +35,7 @@ class SingletonApplication(QApplication):
def __init__(self, argv: list[str], key: str):
super().__init__(argv)
self._key = key
+ self.isFileDragActive = False
self._memory: QSharedMemory | None = None
self._lockSingleInstance()
diff --git a/app/platform/desktop.py b/app/platform/desktop.py
index d8ccbaee..eeb20dc9 100644
--- a/app/platform/desktop.py
+++ b/app/platform/desktop.py
@@ -6,7 +6,7 @@ from pathlib import Path
from PySide6.QtCore import QMimeData, QProcess, QUrl, Qt
from PySide6.QtGui import QDesktopServices, QDrag
-from PySide6.QtWidgets import QWidget
+from PySide6.QtWidgets import QApplication, QWidget
from loguru import logger
@@ -264,14 +264,18 @@ def raiseWindow(window) -> None:
def startFileDrag(paths: list[Path], source: QWidget) -> None:
- if sys.platform == "win32":
- try:
- hwnd = int(source.window().winId())
- _startFileDragWin32([str(p) for p in paths], hwnd)
- return
- except Exception as e:
- logger.opt(exception=e).debug("COM drag failed, falling back to Qt")
- _startFileDragQt(paths, source)
+ QApplication.instance().isFileDragActive = True
+ try:
+ if sys.platform == "win32":
+ try:
+ hwnd = int(source.window().winId())
+ _startFileDragWin32([str(p) for p in paths], hwnd)
+ return
+ except Exception as e:
+ logger.opt(exception=e).debug("COM drag failed, falling back to Qt")
+ _startFileDragQt(paths, source)
+ finally:
+ QApplication.instance().isFileDragActive = False
def _startFileDragQt(paths: list[Path], source: QWidget) -> None:
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index 3a0b2aff..00b75cce 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -76,6 +76,7 @@ class MainWindow(MSFluentWindow):
coroutineRunner: CoroutineRunner,
plan,
updateService=None,
+ setClipboardUrls=None,
parent=None,
):
self._isGeometryRestored = False
@@ -92,6 +93,7 @@ class MainWindow(MSFluentWindow):
self._speedMeter = speedMeter
self._updateService = updateService
self._plan = plan
+ self._setClipboardUrls = setClipboardUrls
self.setMicaEffectEnabled(False)
if sys.platform != "darwin":
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
@@ -183,7 +185,8 @@ class MainWindow(MSFluentWindow):
if pageClass is TaskPage:
return TaskPage(
self._taskService, self._featureService,
- self._categoryService, self._speedMeter, self._plan, parent=self,
+ self._categoryService, self._speedMeter, self._plan,
+ self._setClipboardUrls, parent=self,
)
if pageClass is SettingPage:
return SettingPage(
@@ -451,6 +454,9 @@ class MainWindow(MSFluentWindow):
QApplication.quit()
def dragEnterEvent(self, event) -> None:
+ if QApplication.instance().isFileDragActive:
+ event.ignore()
+ return
if not event.mimeData().hasUrls():
event.ignore()
return