Skip to content

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

feat: toast 通知支持

XiaoYouChR59b32470aca8
diff --git a/app/view/pop_up_window.py b/app/view/pop_up_window.py
index 5da29e8c..612a66a9 100644
--- a/app/view/pop_up_window.py
+++ b/app/view/pop_up_window.py
@@ -9,7 +9,7 @@ from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets.common.screen import getCurrentScreenGeometry
from qframelesswindow import WindowEffect
-from app.common.methods import openFile, bringWindowToTop
+from app.common.methods import openFile, bringWindowToTop, isAbleToShowToast
from app.view.Ui_PopUpWindow import Ui_PopUpWindow
@@ -228,9 +228,31 @@ class FinishedPopUpWindow(PopUpWindowBase):
@classmethod
def showPopUpWindow(cls, fileResolvePath:str, mainWindow=None):
- w = FinishedPopUpWindow(fileResolvePath, mainWindow)
- w.show()
- return w
+ if isAbleToShowToast():
+ from app.common.concurrent.TaskExecutor import TaskExecutor
+ from PySide6.QtCore import QStandardPaths, QFileInfo
+ from win11toast import toast
+ from PySide6.QtWidgets import QFileIconProvider
+ from os.path import dirname
+
+ iconTempFile = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/finished_file_icon.png"
+ QFileIconProvider().icon(QFileInfo(fileResolvePath)).pixmap(128, 128).save(iconTempFile, "PNG")
+
+ icon = {
+ 'src': f"file://{iconTempFile}",
+ 'placement': 'appLogoOverride'
+ }
+
+ buttons = [
+ {'activationType': 'protocol', 'arguments': fileResolvePath, 'content': '打开文件'},
+ {'activationType': 'protocol', 'arguments': dirname(fileResolvePath), 'content': '打开目录'}
+ ]
+
+ return TaskExecutor.run(toast, "下载完成", fileResolvePath, icon=icon, buttons=buttons)
+ else:
+ w = FinishedPopUpWindow(fileResolvePath, mainWindow)
+ w.show()
+ return w
class ReceivedPopUpWindow(PopUpWindowBase):
@@ -251,9 +273,26 @@ class ReceivedPopUpWindow(PopUpWindowBase):
@classmethod
def showPopUpWindow(cls, receiveContent:str, mainWindow=None):
- w = ReceivedPopUpWindow(receiveContent, mainWindow)
- w.show()
- return w
+ if isAbleToShowToast():
+ from app.common.concurrent.TaskExecutor import TaskExecutor
+ from pathlib import Path
+ from PySide6.QtCore import QStandardPaths, QResource
+ from win11toast import toast
+
+ logoTempFile = Path(QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/gd3_logo.png")
+ if not logoTempFile.exists():
+ with open(logoTempFile, "wb") as f:
+ f.write(QResource(":/image/logo.png").data())
+ icon = {
+ 'src': f"file://{logoTempFile}",
+ 'placement': 'appLogoOverride'
+ }
+ return TaskExecutor.run(toast, "接收到来自浏览器的下载任务:", receiveContent,
+ on_click=lambda args: print('clicked!', args), icon=icon)
+ else:
+ w = ReceivedPopUpWindow(receiveContent, mainWindow)
+ w.show()
+ return w
class PopUpWindowManager(QObject):
diff --git a/requirements.txt b/requirements.txt
index a9c8b088..9ebd1699 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,3 +4,4 @@ loguru
httpx[socks]
aiofiles
nuitka==2.6.7
+win11toast; sys_platform=="win32"
diff --git a/tests/test_pop_up_window.py b/tests/test_pop_up_window.py
index 31a23da3..5b6ae088 100644
--- a/tests/test_pop_up_window.py
+++ b/tests/test_pop_up_window.py
@@ -1,5 +1,4 @@
import sys
-
from PySide6.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget
# noinspection PyUnresolvedReferences
@@ -23,8 +22,57 @@ class TestPopUpWindow(QWidget):
finished_button.clicked.connect(self.show_finished_pop_up)
layout.addWidget(finished_button)
+ toast_receive_button = QPushButton("Show Toast Receive Button")
+ toast_receive_button.clicked.connect(self.show_received_toast)
+ layout.addWidget(toast_receive_button)
+
+ toast_finished_button = QPushButton("Show Toast Finished Button")
+ toast_finished_button.clicked.connect(self.show_finished_toast)
+ layout.addWidget(toast_finished_button)
+
self.setLayout(layout)
+ def show_received_toast(self):
+ from app.common.concurrent.TaskExecutor import TaskExecutor
+ from pathlib import Path
+ from PySide6.QtCore import QStandardPaths, QResource
+ from win11toast import toast
+
+ logoTempFile = Path(QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/gd3_logo.png")
+ if not logoTempFile.exists():
+ with open(logoTempFile, "wb") as f:
+ f.write(QResource(":/image/logo.png").data())
+ icon = {
+ 'src': f"file://{logoTempFile}",
+ 'placement': 'appLogoOverride'
+ }
+ TaskExecutor.run(toast, "接收到来自浏览器的下载任务:", "https://cn.pornhub.com", on_click=lambda args: print('clicked!', args), icon=icon)
+
+ def show_finished_toast(self):
+ from app.common.concurrent.TaskExecutor import TaskExecutor
+ from PySide6.QtCore import QStandardPaths, QFileInfo
+ from win11toast import toast
+ from PySide6.QtWidgets import QFileIconProvider
+ from os.path import dirname
+
+ fileResolovePath = r"C:\Users\BGTV\Downloads\Ghost-Downloader-v3.5.4-Windows-x86_64.zip"
+
+ iconTempFile = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/finished_file_icon.png"
+ QFileIconProvider().icon(QFileInfo(fileResolovePath)).pixmap(128, 128).save(iconTempFile, "PNG")
+
+ icon = {
+ 'src': f"file://{iconTempFile}",
+ 'placement': 'appLogoOverride'
+ }
+
+ buttons = [
+ {'activationType': 'protocol', 'arguments': fileResolovePath, 'content': '打开文件'},
+ {'activationType': 'protocol', 'arguments': dirname(fileResolovePath), 'content': '打开目录'}
+ ]
+
+ TaskExecutor.run(toast, "下载完成", fileResolovePath, icon=icon, buttons=buttons)
+
+
def show_received_pop_up(self):
ReceivedPopUpWindow.showPopUpWindow(f"")