Skip to content

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

refactor(app): 优化下载任务和 Win 10 下的主窗口显示效果

XiaoYouChR2642ef94c969
diff --git a/README.md b/README.md
index 0765df54..2260ebf7 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,9 @@
> [!NOTE]
> Due to the developer's preparation for the college entrance exam (Gaokao), project updates are temporarily suspended 😭 Join QQ group [`531928387`](https://qm.qq.com/q/PlUBdzqZCm) for latest updates
+> [!TIP]
+> If you want to use Ghost-Downloader-3 on Windows 7, please download the version `v3.5.8-Portable`.
+
<!-- PROJECT LOGO -->
<div align="center">
diff --git a/README_zh.md b/README_zh.md
index 2b062559..eb75a455 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -5,6 +5,9 @@
> [!NOTE]
> 由于开发者高三冲刺,项目更新暂停😭 可加 QQ 群获取项目最新消息: [`531928387`](https://qm.qq.com/q/PlUBdzqZCm)
+> [!TIP]
+> 如果您想在 Windows 7 上使用 Ghost-Downloader-3,请下载 `v3.5.8-Portable` 版本.
+
<!-- PROJECT LOGO -->
<div align="center">
diff --git a/app/common/download_task.py b/app/common/download_task.py
index 90ea99d9..a9af868e 100644
--- a/app/common/download_task.py
+++ b/app/common/download_task.py
@@ -219,16 +219,16 @@ class DownloadTask(QThread):
if worker.endPos <= worker.progress:
break
if chunk:
- self.file.seek(worker.process)
+ self.file.seek(worker.progress)
self.file.write(chunk)
- worker.process += 65536
+ worker.progress += 65536
cfg.globalSpeed += 65536
if cfg.speedLimitation.value:
if cfg.globalSpeed >= cfg.speedLimitation.value:
- await asyncio.sleep(1) # 在锁里面睡,只阻塞 worker, 不阻塞 supervisor
+ time.sleep(1)
- if worker.process >= worker.endPos:
- worker.process = worker.endPos
+ if worker.progress >= worker.endPos:
+ worker.progress = worker.endPos
finished = True
@@ -251,10 +251,9 @@ class DownloadTask(QThread):
async with worker.client.stream(url=self.url, headers=WorkingRangeHeaders, timeout=30,
method="GET") as res:
async for chunk in res.aiter_bytes():
-
if chunk:
- await self.file.seek(worker.progress)
- await self.file.write(chunk)
+ self.file.seek(worker.progress)
+ self.file.write(chunk)
_ = len(chunk)
worker.progress += _
cfg.globalSpeed += _
@@ -266,7 +265,7 @@ class DownloadTask(QThread):
finished = True
- except httpx.HTTPError as e:
+ except Exception as e:
logger.info(
f"Task: {self.fileName}, Thread {worker} is reconnecting to the server, Error: {repr(e)}")
@@ -279,7 +278,7 @@ class DownloadTask(QThread):
async def __supervisor(self):
"""实时统计进度并写入历史记录文件"""
- LastProgress = 0 # 可能会出现unbound error,所以将LastProcess提取为函数全局变量
+ LastProgress = 0 # 可能会出现unbound error,所以将LastProgress提取为函数全局变量
for i in self.workers:
self.progress += (i.progress - i.startPos + 1)
@@ -407,7 +406,6 @@ class DownloadTask(QThread):
await self.client.aclose()
self.file.close()
- self.ghdFile.close()
if self.fileSize: # 事实上表示 ableToParallelDownload 为 False
self.ghdFile.close()
diff --git a/app/components/task_card.py b/app/components/task_card.py
index a2aeb6ec..e44e4390 100644
--- a/app/components/task_card.py
+++ b/app/components/task_card.py
@@ -113,6 +113,8 @@ class TaskCard(CardWidget, Ui_TaskCard):
else:
self.__instantiateTask(self.url, self.filePath, self.preBlockNum, self.headers, self.fileSize)
+ self.__connectSignalToSlot()
+
if self.status == "working":
# 开始下载
self.task.start()
@@ -120,8 +122,6 @@ class TaskCard(CardWidget, Ui_TaskCard):
# self.pauseButton.setIcon(FIF.PLAY)
self.changeButtonStatus(icon=FIF.PLAY)
- self.__connectSignalToSlot()
-
def __instantiateTask(self, url: str, filePath: str, preBlockNum: int, headers: dict, fileSize: int = -1,
fileName: str = None):
autoSpeedUp = cfg.autoSpeedUp.value
@@ -189,6 +189,7 @@ class TaskCard(CardWidget, Ui_TaskCard):
return (startPos.x() - endPos.x()) ** 2 + (startPos.y() - endPos.y()) ** 2
def __onTaskInited(self, ableToParallelDownload: bool):
+ print(ableToParallelDownload)
self.fileName = self.task.fileName
self.fileSize = self.task.fileSize
self.ableToParallelDownload = ableToParallelDownload
diff --git a/app/view/main_window.py b/app/view/main_window.py
index 7ca9b41f..d0f38a92 100644
--- a/app/view/main_window.py
+++ b/app/view/main_window.py
@@ -6,7 +6,7 @@ from pathlib import Path
import darkdetect
from PySide6.QtCore import QSize, QThread, Signal, QTimer, QPropertyAnimation, QRect, QUrl
-from PySide6.QtGui import QIcon, QDragEnterEvent, QDropEvent, QKeySequence, QDesktopServices, QColor
+from PySide6.QtGui import QIcon, QDragEnterEvent, QDropEvent, QKeySequence, QDesktopServices, QColor, Qt
from PySide6.QtWidgets import QApplication, QGraphicsOpacityEffect
from loguru import logger
from qfluentwidgets import FluentIcon as FIF, setTheme, Theme, themeColor, isDarkTheme
@@ -17,13 +17,24 @@ from .task_interface import TaskInterface
from ..common.config import cfg, Headers, attachmentTypes, FEEDBACK_URL
from ..common.custom_socket import GhostDownloaderSocketServer
from ..common.methods import getLinkInfo, bringWindowToTop, addDownloadTask, showMessageBox, isBorderAccentColorOpen, \
- isGreaterEqualWin10, isLessThanWin10
+ isGreaterEqualWin10, isLessThanWin10, isGreaterEqualWin11
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
+def updateFrameless(self):
+ stayOnTop = Qt.WindowStaysOnTopHint if self.windowFlags() & Qt.WindowStaysOnTopHint else 0
+ self.setWindowFlags(Qt.FramelessWindowHint | stayOnTop)
+
+ self.windowEffect.enableBlurBehindWindow(self.winId())
+ self.windowEffect.addWindowAnimation(self.winId())
+
+ self.windowEffect.setAcrylicEffect(self.winId())
+ if isGreaterEqualWin11():
+ self.windowEffect.addShadowEffect(self.winId())
+
class CustomSplashScreen(SplashScreen):
def finish(self):
@@ -50,7 +61,6 @@ class ThemeChangedListener(QThread):
class MainWindow(MSFluentWindow):
-
def __init__(self):
super().__init__()
@@ -394,4 +404,7 @@ class MainWindow(MSFluentWindow):
bringWindowToTop(self)
self.__setUrlsAndShowAddTaskMsg(results)
except Exception as e:
- logger.warning(f"Failed to check clipboard: {e}")
\ No newline at end of file
+ logger.warning(f"Failed to check clipboard: {e}")
+
+if isGreaterEqualWin10(): # 否则 Win 10 亚克力效果失效
+ MainWindow.updateFrameless = updateFrameless