The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
fix(platform): 窗口销毁后 URL 协议唤醒失效
XiaoYouChR72ae7227d2bf
diff --git a/app/platform/application.py b/app/platform/application.pyindex 267a6ec5..5afc05ca 100644--- a/app/platform/application.py+++ b/app/platform/application.py@@ -37,7 +37,9 @@ class SingletonApplication(QApplication):except Exception as e:logger.warning("Failed to register SIGINT handler: {}", e)- if sys.platform == "linux" and not IS_ANDROID:+ if sys.platform == "win32":+ self._registerIpcReceiver()+ elif sys.platform == "linux" and not IS_ANDROID:self._registerDbusReceiver()def exec(self) -> int:@@ -106,6 +108,9 @@ class SingletonApplication(QApplication):logger.error("KeyboardInterrupt, quitting")self.quit()+ def _registerIpcReceiver(self) -> None:+ self._ipcHwnd = _createIpcWindow()+def _registerDbusReceiver(self) -> None:from PySide6.QtDBus import QDBusConnection@@ -125,8 +130,10 @@ class SingletonApplication(QApplication):if sys.platform == "win32":import ctypesfrom ctypes import wintypes+ import win32apiimport win32gui+ IPC_CLASS_NAME = "GhostDownloaderIPC"COPYDATA_OPEN_FILES = 0x4744WM_COPYDATA = 0x004AWM_USER_WAKE = 1025@@ -138,8 +145,39 @@ if sys.platform == "win32":("lpData", ctypes.c_void_p),]+ def _onIpcWake(hWnd, msg, wParam, lParam):+ signalBus.activationRequested.emit()+ return 0++ def _onIpcCopyData(hWnd, msg, wParam, lParam):+ payload = _CopyDataStruct.from_address(lParam)+ if payload.dwData == COPYDATA_OPEN_FILES:+ raw = ctypes.string_at(payload.lpData, payload.cbData)+ uris = [line for line in raw.decode("utf-16-le").rstrip("\x00").split("\n") if line]+ if uris:+ signalBus.openFileRequested.emit(uris)+ return 1++ _IPC_MESSAGE_MAP = {+ WM_USER_WAKE: _onIpcWake,+ WM_COPYDATA: _onIpcCopyData,+ }++ def _createIpcWindow() -> int:+ hInstance = win32api.GetModuleHandle(None)+ wc = win32gui.WNDCLASS()+ wc.lpfnWndProc = _IPC_MESSAGE_MAP+ wc.hInstance = hInstance+ wc.lpszClassName = IPC_CLASS_NAME+ win32gui.RegisterClass(wc)+ return win32gui.CreateWindow(+ IPC_CLASS_NAME, IPC_CLASS_NAME, 0,+ 0, 0, 0, 0,+ 0, 0, hInstance, None,+ )+def _sendToRunningWindows() -> None:- hWnd = win32gui.FindWindow(None, "Ghost Downloader")+ hWnd = win32gui.FindWindow(IPC_CLASS_NAME, None)if not hWnd:returnuris = fileUrisFromArgv(sys.argv)@@ -152,13 +190,6 @@ if sys.platform == "win32":win32gui.SendMessage(hWnd, WM_USER_WAKE, 0, 0)win32gui.SetForegroundWindow(hWnd)- def fileUrisFromCopyData(lParam: int) -> list[str]:- payload = _CopyDataStruct.from_address(lParam)- if payload.dwData != COPYDATA_OPEN_FILES:- return []- raw = ctypes.string_at(payload.lpData, payload.cbData)- return [line for line in raw.decode("utf-16-le").rstrip("\x00").split("\n") if line]-if sys.platform == "linux":from PySide6.QtCore import QObject, Slot, ClassInfodiff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.pyindex 7160fcc9..39b6b99c 100644--- a/app/view/windows/main_window.py+++ b/app/view/windows/main_window.py@@ -245,26 +245,6 @@ class MainWindow(MSFluentWindow):desktop = QApplication.primaryScreen().availableGeometry()self.move(desktop.center() - self.rect().center())- def nativeEvent(self, eventType, message):- if sys.platform == "win32" and eventType == "windows_generic_MSG":- from ctypes.wintypes import MSG- from app.platform.application import WM_USER_WAKE, WM_COPYDATA, fileUrisFromCopyData- msg = MSG.from_address(message.__int__())-- if msg.message == WM_USER_WAKE:- from app.platform.desktop import raiseWindow- raiseWindow(self)- return True, 0-- if msg.message == WM_COPYDATA:- uris = fileUrisFromCopyData(msg.lParam)- if uris:- signalBus.openFileRequested.emit(uris)- raiseWindow(self)- return True, 1-- return super().nativeEvent(eventType, message)-def changeEvent(self, event) -> None:super().changeEvent(event)if event.type() == QEvent.Type.PaletteChange:@@ -368,7 +348,6 @@ if sys.platform == "win32":def _win10NativeEvent(self, eventType, message):if eventType == "windows_generic_MSG":from ctypes.wintypes import MSG- from app.platform.application import WM_USER_WAKE, WM_COPYDATA, fileUrisFromCopyDatamsg = MSG.from_address(message.__int__())WM_ENTERSIZEMOVE = 561@@ -380,16 +359,6 @@ if sys.platform == "win32":self.windowEffect.setAcrylicEffect(self.winId(), "00000030" if isDarkTheme() else "FFFFFF30",)- elif msg.message == WM_USER_WAKE:- from app.platform.desktop import raiseWindow- raiseWindow(self)- return True, 0- elif msg.message == WM_COPYDATA:- uris = fileUrisFromCopyData(msg.lParam)- if uris:- signalBus.openFileRequested.emit(uris)- raiseWindow(self)- return True, 1return FramelessWindow.nativeEvent(self, eventType, message)