The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
更新界面优化
XiaoYouChR9c0a2f2f6eda
diff --git a/app/common/methods.py b/app/common/methods.pyindex de4f7d82..6b3839e8 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -3,7 +3,8 @@ import inspectimport osimport sysfrom functools import wraps-from time import sleep+from time import sleep, localtime+from datetime import datetime, timedelta, timezonefrom PySide6.QtWidgets import QApplicationfrom loguru import logger@@ -131,3 +132,22 @@ def openFile(fileResolve):os.system(f"open '{fileResolve}'")else:os.system(f"xdg-open '{fileResolve}'")+++def getLocalTimeFromGithubApiTime(gmtTimeStr:str):+ # 解析 GMT 时间+ gmtTime = datetime.fromisoformat(gmtTimeStr.replace("Z", "+00:00"))++ # 获取本地时间的时区偏移量(秒)+ localTimeOffsetSec = localtime().tm_gmtoff++ # 创建带有本地时区偏移量的时区信息+ localTz = timezone(timedelta(seconds=localTimeOffsetSec))++ # 转换为系统本地时间+ localTime = gmtTime.astimezone(localTz)++ # 去掉时区信息+ localTimeNaive = localTime.replace(tzinfo=None)++ return localTimeNaive\ No newline at end of filediff --git a/app/components/Ui_UpdateDialog.py b/app/components/Ui_UpdateDialog.pynew file mode 100644index 00000000..02dee808--- /dev/null+++ b/app/components/Ui_UpdateDialog.py@@ -0,0 +1,116 @@+# -*- coding: utf-8 -*-++################################################################################+## Form generated from reading UI file 'UpdateDialog.ui'+##+## Created by: Qt User Interface Compiler version 6.7.2+##+## WARNING! All changes made in this file will be lost when recompiling UI file!+################################################################################++from PySide6.QtCore import (QCoreApplication, QMetaObject)+from PySide6.QtWidgets import (QFrame, QHBoxLayout,+ QSizePolicy, QVBoxLayout, QAbstractItemView)++from qfluentwidgets import (PillPushButton, PrimaryPushButton, PushButton, StrongBodyLabel,+ SubtitleLabel, TextEdit, TableWidget, TitleLabel, FluentIcon)++class Ui_UpdateDialog(object):+ def setupUi(self, UpdateDialog):+ if not UpdateDialog.objectName():+ UpdateDialog.setObjectName(u"UpdateDialog")+ UpdateDialog.resize(681, 721)+ self.verticalLayout = QVBoxLayout(UpdateDialog)+ self.verticalLayout.setObjectName(u"verticalLayout")+ self.verticalLayout.setContentsMargins(11, 11, 11, 11)+ self.verticalLayout.setSpacing(11)++ self.horizontalLayout = QHBoxLayout()+ self.horizontalLayout.setObjectName(u"horizontalLayout")+ self.titleLabel = SubtitleLabel(UpdateDialog)+ self.titleLabel.setObjectName(u"titleLabel")++ self.horizontalLayout.addWidget(self.titleLabel)++ self.versionLabel = StrongBodyLabel(UpdateDialog)+ self.versionLabel.setObjectName(u"versionLabel")++ self.horizontalLayout.addWidget(self.versionLabel)++ self.updatedDateLabel = StrongBodyLabel(UpdateDialog)+ self.updatedDateLabel.setObjectName(u"updatedDateLabel")++ self.horizontalLayout.addWidget(self.updatedDateLabel)++ self.sponsorButton = PillPushButton(UpdateDialog)+ self.sponsorButton.setObjectName(u"sponsorButton")+ self.sponsorButton.setProperty("hasIcon", True)+ self.sponsorButton.setIcon(FluentIcon.HEART)++ self.horizontalLayout.addWidget(self.sponsorButton)+++ self.verticalLayout.addLayout(self.horizontalLayout)++ self.logTextEdit = TextEdit(UpdateDialog)+ self.logTextEdit.setObjectName(u"logTextEdit")+ sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)+ sizePolicy.setHorizontalStretch(0)+ sizePolicy.setVerticalStretch(0)+ sizePolicy.setHeightForWidth(self.logTextEdit.sizePolicy().hasHeightForWidth())+ self.logTextEdit.setSizePolicy(sizePolicy)+ self.logTextEdit.setReadOnly(True)++ self.verticalLayout.addWidget(self.logTextEdit)++ self.tableView = TableWidget(UpdateDialog)++ self.tableView.setObjectName(u"tableView")+ sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)+ sizePolicy1.setHorizontalStretch(0)+ sizePolicy1.setVerticalStretch(0)+ sizePolicy1.setHeightForWidth(self.tableView.sizePolicy().hasHeightForWidth())+ self.tableView.setSizePolicy(sizePolicy1)++ self.tableView.setBorderVisible(True)+ self.tableView.setBorderRadius(8)+ self.tableView.setWordWrap(False)+ self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) # ReadOnly+ self.tableView.setColumnCount(3)+ self.tableView.verticalHeader().setVisible(False) # 隐藏垂直表头++ self.verticalLayout.addWidget(self.tableView)++ self.horizontalLayout_2 = QHBoxLayout()+ self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")+ self.noButton = PushButton(UpdateDialog)+ self.noButton.setObjectName(u"noButton")++ self.horizontalLayout_2.addWidget(self.noButton)++ self.yesButton = PrimaryPushButton(UpdateDialog)+ self.yesButton.setObjectName(u"yesButton")++ self.horizontalLayout_2.addWidget(self.yesButton)+++ self.verticalLayout.addLayout(self.horizontalLayout_2)+++ self.retranslateUi(UpdateDialog)++ QMetaObject.connectSlotsByName(UpdateDialog)+ # setupUi++ def retranslateUi(self, UpdateDialog):+ UpdateDialog.setWindowTitle(QCoreApplication.translate("UpdateDialog", u"Dialog", None))+ self.titleLabel.setText(QCoreApplication.translate("UpdateDialog", u"\u68c0\u6d4b\u5230\u65b0\u7248\u672c", None))+ self.versionLabel.setText("")+ self.updatedDateLabel.setText("")+ self.sponsorButton.setText(QCoreApplication.translate("UpdateDialog", u"Sponsor", None))+ self.logTextEdit.setMarkdown("")++ self.noButton.setText(QCoreApplication.translate("UpdateDialog", u"\u7a0d\u540e\u518d\u8bf4", None))+ self.yesButton.setText(QCoreApplication.translate("UpdateDialog", u"\u4e0b\u8f7d\u6b64\u7248\u672c", None))+ # retranslateUi+diff --git a/app/components/task_card.py b/app/components/task_card.pyindex 85f3536a..df7122d9 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -250,14 +250,13 @@ class TaskCard(CardWidget, Ui_TaskCard):def __changeInfo(self, content: list):# 理论来说 worker 直增不减 所以ProgressBar不用考虑线程减少的问题- # process = int(content)+_ = len(content) - self.progressBar.blockNumif _:self.progressBar.addProgressBar(content, _)process = 0-for e, i in enumerate(content):process += i["process"] - i["start"]self.progressBar.progressBarList[e].setValue( ( (i["process"] - i["start"]) / (i["end"] - i["start"]) ) * 100)diff --git a/app/components/update_dialog.py b/app/components/update_dialog.pyindex dc1a81be..9dad54c8 100644--- a/app/components/update_dialog.py+++ b/app/components/update_dialog.py@@ -1,15 +1,16 @@import httpxfrom PySide6.QtCore import QThread, Signalfrom PySide6.QtGui import QColor-from PySide6.QtWidgets import QVBoxLayout, QSizePolicy, QHBoxLayout, QListWidgetItem+from PySide6.QtWidgets import QVBoxLayout, QSizePolicy, QHBoxLayout, QListWidgetItem, QTableWidgetItemfrom loguru import loggerfrom qfluentwidgets import isDarkTheme, TextEdit, ListWidget, BodyLabel, PrimaryPushButton, \PushButton, SubtitleLabel, InfoBar, InfoBarPositionfrom qfluentwidgets.components.dialog_box.mask_dialog_base import MaskDialogBasefrom app.common.config import VERSION, cfg-from app.common.methods import getProxy+from app.common.methods import getProxy, getLocalTimeFromGithubApiTime, getReadableSizefrom app.common.signal_bus import signalBus+from app.components.Ui_UpdateDialog import Ui_UpdateDialogclass GetUpdateThread(QThread):@@ -38,23 +39,23 @@ class GetUpdateThread(QThread):self.gotResponse.emit({"ERROR" : f"获取更新失败:{repr(e)}"})-class UpdateDialog(MaskDialogBase):+class UpdateDialog(MaskDialogBase, Ui_UpdateDialog):def __init__(self, parent, content: dict):super().__init__(parent=parent)self.content = content- self.urls = []+ self.tabelViewInfos = []+ self.urls: list[str] = []self.setShadowEffect(60, (0, 10), QColor(0, 0, 0, 50))self.setMaskColor(QColor(0, 0, 0, 76))- self.VBoxLayout = QVBoxLayout()- self.VBoxLayout.setContentsMargins(18, 18, 18, 18)+ self.setupUi(self.widget)- self.widget.setLayout(self.VBoxLayout)+ self.widget.setLayout(self.verticalLayout)- self.widget.setMinimumSize(520, 520)- self.widget.setMaximumSize(820, 650)+ self.widget.setMinimumSize(520, 650)+ self.widget.setMaximumSize(680, 720)if isDarkTheme():# C = ThemeColor.DARK_3.color()@@ -62,38 +63,6 @@ class UpdateDialog(MaskDialogBase):else:self.widget.setStyleSheet(".QFrame{border-radius:10px;background-color:white}")- self.titleLabel = SubtitleLabel("检测到新版本", self.widget)- self.VBoxLayout.addWidget(self.titleLabel)-- self.logTextEdit = TextEdit(self)- self.logTextEdit.setReadOnly(True)-- self.logTextEdit.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))-- self.VBoxLayout.addWidget(self.logTextEdit)-- self.updateTimeLabel = BodyLabel(self)- self.VBoxLayout.addWidget(self.updateTimeLabel)-- self.fileListWidget = ListWidget(self)- self.fileListWidget.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum))- self.VBoxLayout.addWidget(self.fileListWidget)-- 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.addLayout(self.buttonLayout)-self.__analyzeContent()# connect signal to slot@@ -101,20 +70,28 @@ class UpdateDialog(MaskDialogBase):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(_)+ self.tabelViewInfos.append([i["name"], getReadableSize(i["size"]), str(i["download_count"])])+ self.urls.append(i["browser_download_url"])++ self.tableView.setRowCount(len(assets))++ # 添加数据+ for i, tabelViewInfo in enumerate(self.tabelViewInfos):+ for j in range(3):+ self.tableView.setItem(i, j, QTableWidgetItem(tabelViewInfo[j]))- body = self.content["body"]+ self.tableView.setHorizontalHeaderLabels(['文件名', '文件大小', '下载次数'])+ self.tableView.resizeColumnsToContents()- self.logTextEdit.setMarkdown(body)- self.updateTimeLabel.setText(f"更新时间:{self.content['published_at']}")- self.titleLabel.setText(f"检测到新版本:{self.content['tag_name']}")+ self.logTextEdit.setMarkdown(self.content["body"])+ self.updatedDateLabel.setText(f"Updated Time:{getLocalTimeFromGithubApiTime(self.content['published_at'])}")+ self.versionLabel.setText(f"Version: {self.content['tag_name']} " + ("Pre-Release" if self.content["prerelease"] else "Release"))def __onYesButtonClicked(self):- url = self.fileListWidget.currentItem().data(1)+ url = self.urls[self.tableView.currentRow()]signalBus.addTaskSignal.emit(url, cfg.downloadFolder.value, cfg.maxBlockNum.value, None, "working", False)self.close()@@ -124,7 +101,7 @@ def __showResponse(parent, content: dict):elif "ERROR" in content:InfoBar.error(title="检查更新失败", content=content["ERROR"], position=InfoBarPosition.TOP_RIGHT, parent=parent, duration=5000)else:- UpdateDialog(parent, content).exec()+ UpdateDialog(parent, content).show()def checkUpdate(parent):thread = GetUpdateThread(parent)diff --git a/app/view/setting_interface.py b/app/view/setting_interface.pyindex 10c9745b..0192708e 100644--- a/app/view/setting_interface.py+++ b/app/view/setting_interface.py@@ -312,7 +312,7 @@ Terminal=falsedef __onAboutCardClicked(self):""" check update and show information """InfoBar.info("请稍候", "正在检查更新...", position=InfoBarPosition.TOP_RIGHT, duration=1000, parent=self)- checkUpdate(self)+ checkUpdate(self.window())def __connectSignalToSlot(self):""" connect signal to slot """