Skip to content

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

完善检查更新功能,更新版本号为v3.3.4

XiaoYouChRc105859a19c7
diff --git a/app/common/config.py b/app/common/config.py
index 8053b40b..35e862e1 100644
--- a/app/common/config.py
+++ b/app/common/config.py
@@ -33,7 +33,7 @@ class Config(QConfig):
YEAR = 2024
AUTHOR = "XiaoYouChR"
-VERSION = "3.3.3"
+VERSION = "3.3.4"
AUTHOR_URL = "https://space.bilibili.com/437313511"
FEEDBACK_URL = "https://github.com/XiaoYouChR/Ghost-Downloader-3/issues"
# RELEASE_URL = "https://github.com/XiaoYouChR/Ghost-Downloader-3/releases/latest"
diff --git a/app/common/download_task.py b/app/common/download_task.py
index 7b41a414..d2111c52 100644
--- a/app/common/download_task.py
+++ b/app/common/download_task.py
@@ -168,15 +168,15 @@ class DownloadTask(QThread):
# 首先,尝试处理 Content-Disposition 中的 self.fileName* (RFC 5987 格式)
headerValue = head["content-disposition"]
if 'fileName*' in headerValue:
- match = re.search(r'fileName\*\s*=\s*([^;]+)', headerValue, re.IGNORECASE)
+ match = re.search(r'filename\*\s*=\s*([^;]+)', headerValue, re.IGNORECASE)
if match:
self.fileName = match.group(1)
self.fileName = decode_rfc2231(self.fileName)
self.fileName = urllib.parse.unquote(self.fileName[2]) # self.fileName* 后的部分是编码信息
# 如果 self.fileName* 没有成功获取,尝试处理普通的 self.fileName
- if not self.fileName and 'fileName' in headerValue:
- match = re.search(r'fileName\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)
+ if not self.fileName and 'filename' in headerValue:
+ match = re.search(r'filename\s*=\s*["\']?([^"\';]+)["\']?', headerValue, re.IGNORECASE)
if match:
self.fileName = match.group(1)
@@ -195,7 +195,7 @@ class DownloadTask(QThread):
# 获取 response-content-disposition 参数
# 解码并分割 disposition
# 提取文件名
- self.fileName = unquote(parse_qs(urlparse(self.url).query).get('response-content-disposition', [''])[0]).split("fileName=")[-1]
+ self.fileName = unquote(parse_qs(urlparse(self.url).query).get('response-content-disposition', [''])[0]).split("filename=")[-1]
# 去掉可能存在的引号
if self.fileName.startswith('"') and self.fileName.endswith('"'):
self.fileName = self.fileName[1:-1]
diff --git a/app/components/update_dialog.py b/app/components/update_dialog.py
new file mode 100644
index 00000000..3fce2bfe
--- /dev/null
+++ b/app/components/update_dialog.py
@@ -0,0 +1,116 @@
+import httpx
+from PySide6.QtCore import QThread, Signal
+from PySide6.QtGui import QColor
+from PySide6.QtWidgets import QVBoxLayout, QSizePolicy, QHBoxLayout, QListWidgetItem
+from qfluentwidgets import isDarkTheme, SettingCardGroup, TextEdit, ListWidget, BodyLabel, PrimaryPushButton, PushButton
+from qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBase
+
+from app.common.config import VERSION, cfg
+from app.common.methods import getWindowsProxy
+from app.common.signal_bus import signalBus
+
+
+class GetUpdateThread(QThread):
+ gotResponse = Signal(dict)
+ def __init__(self, parent=None):
+ super().__init__(parent)
+
+ def run(self):
+ content = httpx.get(url="https://api.github.com/repos/XiaoYouChR/Ghost-Downloader-3/releases/latest", headers={
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.64"},
+ proxy=getWindowsProxy(), follow_redirects=True).json()
+
+ tagName = content["tag_name"][1:]
+
+ latestVersion = list(map(int, tagName.split(".")))
+ currentVersion = list(map(int, VERSION.split(".")))
+
+ if latestVersion > currentVersion:
+ self.gotResponse.emit(content)
+
+
+class UpdateDialog(MaskDialogBase):
+ def __init__(self, parent, content: dict):
+ super().__init__(parent=parent)
+
+ self.content = content
+ self.urls = []
+
+ self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 50))
+ self.setMaskColor(QColor(0, 0, 0, 76))
+
+ self.VBoxLayout = QVBoxLayout(self.widget)
+ self.VBoxLayout.setContentsMargins(18, 18, 18, 18)
+
+ self.widget.setLayout(self.VBoxLayout)
+
+ self.widget.setMinimumSize(410, 420)
+ self.widget.setMaximumSize(520, 420)
+
+ if isDarkTheme():
+ # C = ThemeColor.DARK_3.color()
+ self.widget.setStyleSheet(".QFrame{border-radius:10px;background-color:rgb(39,39,39)}")
+ else:
+ self.widget.setStyleSheet(".QFrame{border-radius:10px;background-color:white}")
+
+ self.mainGroup = SettingCardGroup(
+ "检测到新版本", self.widget)
+
+ self.logTextEdit = TextEdit(self.mainGroup)
+ self.logTextEdit.setMinimumHeight(200)
+ sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
+ self.logTextEdit.setSizePolicy(sizePolicy)
+
+ self.mainGroup.addSettingCard(self.logTextEdit)
+
+ self.fileListWidget = ListWidget(self.mainGroup)
+ self.fileListWidget.setMinimumHeight(80)
+ self.mainGroup.addSettingCard(self.fileListWidget)
+
+ self.updateTimeLabel = BodyLabel(self.mainGroup)
+ self.mainGroup.addSettingCard(self.updateTimeLabel)
+
+ self.buttonLayout = QHBoxLayout()
+
+ self.yesButton = PrimaryPushButton(self)
+ self.yesButton.setObjectName("yesButton")
+ self.yesButton.setText("下载此版本")
+ self.noButton = PushButton(self)
+ self.noButton.setObjectName("noButton")
+ self.noButton.setText("稍后再说")
+
+ self.buttonLayout.addWidget(self.noButton)
+ self.buttonLayout.addWidget(self.yesButton)
+ self.buttonLayout.setSpacing(18)
+
+ self.VBoxLayout.addWidget(self.mainGroup)
+ self.VBoxLayout.addLayout(self.buttonLayout)
+
+ self.__analyzeContent()
+
+ # connect signal to slot
+ self.noButton.clicked.connect(self.close)
+ self.yesButton.clicked.connect(self.__onYesButtonClicked)
+
+ def __analyzeContent(self):
+ assets = self.content["assets"]
+ for i in assets:
+ _ = QListWidgetItem(i["name"])
+ _.setData(1, i["browser_download_url"])
+ self.fileListWidget.addItem(_)
+
+ body = self.content["body"]
+
+ self.logTextEdit.setPlainText(body)
+ self.updateTimeLabel.setText(f"更新时间:{self.content['published_at']}")
+ self.mainGroup.titleLabel.setText(f"检测到新版本:{self.content['tag_name']}")
+
+ def __onYesButtonClicked(self):
+ url = self.fileListWidget.currentItem().data(1)
+ signalBus.addTaskSignal.emit(url, cfg.downloadFolder.value, cfg.maxBlockNum.value, None, "working", False)
+ self.close()
+
+def checkUpdate(parent):
+ thread = GetUpdateThread(parent)
+ thread.gotResponse.connect(lambda content: UpdateDialog(parent, content).exec())
+ thread.start()
\ No newline at end of file
diff --git a/app/view/main_window.py b/app/view/main_window.py
index 7283be94..eeb06546 100644
--- a/app/view/main_window.py
+++ b/app/view/main_window.py
@@ -18,6 +18,7 @@ from ..common.custom_socket import GhostDownloaderSocketServer
from ..common.signal_bus import signalBus
from ..components.add_task_dialog import AddTaskOptionDialog
from ..components.custom_tray import CustomSystemTrayIcon
+from ..components.update_dialog import checkUpdate
class ThemeChangedListener(QThread):
@@ -72,6 +73,11 @@ class MainWindow(MSFluentWindow):
self.tray = CustomSystemTrayIcon(self)
self.tray.show()
+ # 检查更新
+ if cfg.checkUpdateAtStartUp.value == True:
+ checkUpdate(self)
+ print("启动!")
+
self.splashScreen.finish()
def runBrowserExtensionServer(self):