Skip to content

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

完善检查更新功能,显示任务初始化状态.

XiaoYouChR1c5090b0a13e
diff --git a/app/common/download_task.py b/app/common/download_task.py
index d2111c52..3e786ac5 100644
--- a/app/common/download_task.py
+++ b/app/common/download_task.py
@@ -68,7 +68,9 @@ def getRealUrl(url: str):
except ValueError as err:
logger.error(f"Cannot connect to the Internet! Error: {err}")
return
-
+ except httpx.ConnectTimeout as err:
+ logger.error(f"Cannot connect to the Internet! Error: {err}")
+ return
class DownloadTask(QThread):
"""作用相当于包工头"""
diff --git a/app/components/task_card.py b/app/components/task_card.py
index 978c1972..cac5b157 100644
--- a/app/components/task_card.py
+++ b/app/components/task_card.py
@@ -58,7 +58,10 @@ class TaskCard(CardWidget, Ui_TaskCard):
self.lastProcess = 0
self.autoCreated = autoCreated
- # self.number = number
+ # Show Information
+ self.speedLable.setText("若任务初始化过久,请检查网络连接后重试.")
+ self.TitleLabel.setText("正在初始化任务...")
+
self.progressBar = TaskProgressBar(maxBlockNum, self)
self.progressBar.setObjectName(u"progressBar")
@@ -190,40 +193,42 @@ class TaskCard(CardWidget, Ui_TaskCard):
self.pauseButton.setDisabled(True)
self.cancelButton.setDisabled(True)
- if self.status == "working":
- self.pauseTask()
-
- if completely:
- # 删除文件
- tryCount = 0
- isDeleted = False
- while not isDeleted and tryCount < 3:
- try:
- Path(f"{self.filePath}/{self.fileName}").unlink()
- Path(f"{self.filePath}/{self.fileName}.ghd").unlink()
- logger.info(f"self:{self.fileName}, delete file successfully!")
-
- isDeleted = True
- tryCount = 5
-
- except FileNotFoundError:
- isDeleted = True
- tryCount = 5
- except Exception as e:
- logger.error(f"Task:{self.fileName}, it seems that cannot delete file, error: {e}")
- tryCount += 1
-
- sleep(0.1)
+ try:
+ if self.status == "working":
+ self.pauseTask()
+
+ if completely:
+ # 删除文件
+ tryCount = 0
+ isDeleted = False
+ while not isDeleted and tryCount < 3:
+ try:
+ Path(f"{self.filePath}/{self.fileName}").unlink()
+ Path(f"{self.filePath}/{self.fileName}.ghd").unlink()
+ logger.info(f"self:{self.fileName}, delete file successfully!")
+
+ isDeleted = True
+ tryCount = 5
+
+ except FileNotFoundError:
+ isDeleted = True
+ tryCount = 5
+ except Exception as e:
+ logger.error(f"Task:{self.fileName}, it seems that cannot delete file, error: {e}")
+ tryCount += 1
+
+ # 删除记录文件
+ with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "r", encoding="utf-8") as f:
+ _ = f.read()
- # 删除记录文件
- with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "r", encoding="utf-8") as f:
- _ = f.read()
+ _ = _.replace(str({"url": self.url, "fileName": self.fileName, "filePath": str(self.filePath),
+ "blockNum": self.maxBlockNum, "status": self.status}) + "\n", "")
- _ = _.replace(str({"url": self.url, "fileName": self.fileName, "filePath": str(self.filePath),
- "blockNum": self.maxBlockNum, "status": self.status}) + "\n", "")
+ with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "w", encoding="utf-8") as f:
+ f.write(_)
- with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "w", encoding="utf-8") as f:
- f.write(_)
+ except Exception as e:
+ logger.warning(f"Task:{self.fileName}, 删除时遇到错误: {e}")
self.status = "canceled"
diff --git a/app/components/update_dialog.py b/app/components/update_dialog.py
index 3fce2bfe..29193cd7 100644
--- a/app/components/update_dialog.py
+++ b/app/components/update_dialog.py
@@ -2,7 +2,9 @@ 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 loguru import logger
+from qfluentwidgets import isDarkTheme, SettingCardGroup, TextEdit, ListWidget, BodyLabel, PrimaryPushButton, \
+ PushButton, TitleLabel, SubtitleLabel, InfoBar, InfoBarPosition
from qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBase
from app.common.config import VERSION, cfg
@@ -16,17 +18,24 @@ class GetUpdateThread(QThread):
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()
+ try:
+ 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:]
+ tagName = content["tag_name"][1:]
- latestVersion = list(map(int, tagName.split(".")))
- currentVersion = list(map(int, VERSION.split(".")))
+ latestVersion = list(map(int, tagName.split(".")))
+ currentVersion = list(map(int, VERSION.split(".")))
- if latestVersion > currentVersion:
- self.gotResponse.emit(content)
+ if latestVersion > currentVersion:
+ self.gotResponse.emit(content)
+ elif latestVersion <= currentVersion:
+ self.gotResponse.emit({"INFO" : "当前版本已是最新版本"})
+
+ except Exception as e:
+ logger.error(f"获取更新失败:{e}")
+ self.gotResponse.emit({"ERROR" : f"获取更新失败:{e}"})
class UpdateDialog(MaskDialogBase):
@@ -39,7 +48,7 @@ class UpdateDialog(MaskDialogBase):
self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 50))
self.setMaskColor(QColor(0, 0, 0, 76))
- self.VBoxLayout = QVBoxLayout(self.widget)
+ self.VBoxLayout = QVBoxLayout()
self.VBoxLayout.setContentsMargins(18, 18, 18, 18)
self.widget.setLayout(self.VBoxLayout)
@@ -53,22 +62,21 @@ class UpdateDialog(MaskDialogBase):
else:
self.widget.setStyleSheet(".QFrame{border-radius:10px;background-color:white}")
- self.mainGroup = SettingCardGroup(
- "检测到新版本", self.widget)
+ self.titleLabel = SubtitleLabel("检测到新版本", self.widget)
+ self.VBoxLayout.addWidget(self.titleLabel)
- self.logTextEdit = TextEdit(self.mainGroup)
- self.logTextEdit.setMinimumHeight(200)
- sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
+ self.logTextEdit = TextEdit(self)
+ self.logTextEdit.setReadOnly(True)
+ sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.logTextEdit.setSizePolicy(sizePolicy)
- self.mainGroup.addSettingCard(self.logTextEdit)
+ self.VBoxLayout.addWidget(self.logTextEdit)
- self.fileListWidget = ListWidget(self.mainGroup)
- self.fileListWidget.setMinimumHeight(80)
- self.mainGroup.addSettingCard(self.fileListWidget)
+ self.updateTimeLabel = BodyLabel(self)
+ self.VBoxLayout.addWidget(self.updateTimeLabel)
- self.updateTimeLabel = BodyLabel(self.mainGroup)
- self.mainGroup.addSettingCard(self.updateTimeLabel)
+ self.fileListWidget = ListWidget(self)
+ self.VBoxLayout.addWidget(self.fileListWidget)
self.buttonLayout = QHBoxLayout()
@@ -83,7 +91,6 @@ class UpdateDialog(MaskDialogBase):
self.buttonLayout.addWidget(self.yesButton)
self.buttonLayout.setSpacing(18)
- self.VBoxLayout.addWidget(self.mainGroup)
self.VBoxLayout.addLayout(self.buttonLayout)
self.__analyzeContent()
@@ -101,16 +108,24 @@ class UpdateDialog(MaskDialogBase):
body = self.content["body"]
- self.logTextEdit.setPlainText(body)
+ self.logTextEdit.setMarkdown(body)
self.updateTimeLabel.setText(f"更新时间:{self.content['published_at']}")
- self.mainGroup.titleLabel.setText(f"检测到新版本:{self.content['tag_name']}")
+ self.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 __showResponse(parent, content: dict):
+ if "INFO" in content:
+ InfoBar.info(title="当前已是最新版本", position=InfoBarPosition.TOP_RIGHT, parent=parent, duration=5000)
+ elif "ERROR" in content:
+ InfoBar.error(title="检查更新失败", content=content["ERROR"], position=InfoBarPosition.TOP_RIGHT, parent=parent, duration=5000)
+ else:
+ UpdateDialog(parent, content).exec()
+
def checkUpdate(parent):
thread = GetUpdateThread(parent)
- thread.gotResponse.connect(lambda content: UpdateDialog(parent, content).exec())
+ thread.gotResponse.connect(lambda content: __showResponse(parent, content))
thread.start()
\ No newline at end of file
diff --git a/app/view/setting_interface.py b/app/view/setting_interface.py
index b0716a0a..62571acb 100644
--- a/app/view/setting_interface.py
+++ b/app/view/setting_interface.py
@@ -11,13 +11,12 @@ from qfluentwidgets import (SettingCardGroup, SwitchSettingCard, OptionsSettingC
setTheme, RangeSettingCard)
from ..common.config import cfg, FEEDBACK_URL, AUTHOR, VERSION, YEAR, AUTHOR_URL
+from ..components.update_dialog import checkUpdate
class SettingInterface(ScrollArea):
""" Setting interface """
- checkUpdateSig = Signal()
-
def __init__(self, parent=None):
super().__init__(parent=parent)
self.scrollWidget = QWidget()
@@ -265,6 +264,9 @@ class SettingInterface(ScrollArea):
parent=self.parent()
)
+ def __onAboutCardClicked(self):
+ """ check update and show information """
+ checkUpdate(self)
def __connectSignalToSlot(self):
""" connect signal to slot """
@@ -284,6 +286,6 @@ class SettingInterface(ScrollArea):
self.autoRunCard.checkedChanged.connect(self.__onAutoRunCardChecked)
# about
- self.aboutCard.clicked.connect(self.checkUpdateSig)
+ self.aboutCard.clicked.connect(self.__onAboutCardClicked)
self.feedbackCard.clicked.connect(
lambda: QDesktopServices.openUrl(QUrl(FEEDBACK_URL)))