The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
添加托盘,添加开机启动功能
XiaoYouChRed1caa3ecbfb
diff --git a/app/common/config.py b/app/common/config.pyindex 258ba437..4af7b820 100644--- a/app/common/config.py+++ b/app/common/config.py@@ -23,8 +23,9 @@ class Config(QConfig):dpiScale = OptionsConfigItem("MainWindow", "DpiScale", "Auto", OptionsValidator([1, 1.25, 1.5, 1.75, 2, "Auto"]), restart=True)- # software update- checkUpdateAtStartUp = ConfigItem("Update", "CheckUpdateAtStartUp", True, BoolValidator())+ # software+ checkUpdateAtStartUp = ConfigItem("Software", "CheckUpdateAtStartUp", True, BoolValidator())+ autoRun = ConfigItem("Software", "AutoRun", False, BoolValidator())YEAR = 2024diff --git a/app/components/custom_tray.py b/app/components/custom_tray.pynew file mode 100644index 00000000..629bae34--- /dev/null+++ b/app/components/custom_tray.py@@ -0,0 +1,86 @@+from PySide6.QtWidgets import QSystemTrayIcon, QApplication+from loguru import logger+from qfluentwidgets import Action, MessageBox+from qfluentwidgets.components.material import AcrylicSystemTrayMenu+++class CustomSystemTrayIcon(QSystemTrayIcon):++ def __init__(self, parent=None):+ super().__init__(parent=parent)+ self.setIcon(parent.windowIcon())+ self.setToolTip('Ghost Downloader 🥰')++ self.menu = AcrylicSystemTrayMenu(parent=parent)++ # self.view.acrylicBrush.grabImage(QRect(self.pos() + self.view.pos(), self.view.size()))+++ self.showAction = Action('🎤 显示主窗口', self.menu)+ self.showAction.triggered.connect(self.showMainWindow)+ self.menu.addAction(self.showAction)++ self.ikunAction = Action('🏀 唱跳RAP', self.menu)+ self.ikunAction.triggered.connect(self.ikun)+ self.menu.addAction(self.ikunAction)++ self.quitAction = Action('🕺 退出程序', self.menu)+ self.quitAction.triggered.connect(self.quitApplication)+ self.menu.addAction(self.quitAction)++ self.setContextMenu(self.menu)++ self.activated.connect(self.onTrayIconClick)+ self.messageClicked.connect(self.showMainWindow)++ def showMainWindow(self):+ self.parent().show()+ if self.parent().isMinimized():+ self.parent().showNormal()+ # 激活窗口,使其显示在最前面+ self.parent().activateWindow()++ def ikun(self):+ self.parent().show()+ content = """巅峰产生虚伪的拥护,黄昏见证真正的使徒 🏀++ ⠀⠰⢷⢿⠄+ ⠀⠀⠀⠀⠀⣼⣷⣄+ ⠀⠀⣤⣿⣇⣿⣿⣧⣿⡄+ ⢴⠾⠋⠀⠀⠻⣿⣷⣿⣿⡀+ ⠀⢀⣿⣿⡿⢿⠈⣿+ ⠀⠀⠀⢠⣿⡿⠁⠀⡊⠀⠙+ ⠀⠀⠀⢿⣿⠀⠀⠹⣿+ ⠀⠀⠀⠀⠹⣷⡀⠀⣿⡄+ ⠀⠀⠀⠀⣀⣼⣿⠀⢈⣧+ """+ w = MessageBox(+ title='坤家军!集合!',+ content=content,+ parent=self.parent()+ )+ w.yesButton.setText('献出心脏')+ w.cancelButton.setText('你干嘛~')+ w.exec()++ def quitApplication(self):+ self.parent().themeChangedListener.terminate()++ for i in self.parent().taskInterface.cards:+ if i.status == 'working':+ for j in i.task.workers:+ try:+ j.file.close()+ except AttributeError as e:+ logger.info(f"Task:{i.task.fileName}, users operate too quickly!, thread {i} error: {e}")+ except Exception as e:+ logger.warning(+ f"Task:{i.task.fileName}, it seems that cannot cancel thread {i} occupancy of the file, error: {e}")+ j.terminate()+ i.task.terminate()++ QApplication.quit()++ def onTrayIconClick(self, reason):+ if reason == QSystemTrayIcon.DoubleClick:+ self.showMainWindow()\ No newline at end of filediff --git a/app/components/task_card.py b/app/components/task_card.pyindex 4ee8c168..2b60506c 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -250,6 +250,11 @@ class TaskCard(CardWidget, Ui_TaskCard):self.cancelButton.setDisabled(True)self.speedLable.setText("任务已经完成")+ try: # 程序启动时不要发+ self.window().tray.showMessage(self.window().windowTitle(), f"任务 {self.fileName} 已完成!", self.window().windowIcon())+ except:+ pass+if not self.status == "finished": # 不是自动创建的已完成任务# 改变记录状态with open("./Ghost Downloader 记录文件", "r", encoding="utf-8") as f:diff --git a/app/view/main_window.py b/app/view/main_window.pyindex 790ce4b7..55a20a28 100644--- a/app/view/main_window.py+++ b/app/view/main_window.py@@ -2,20 +2,20 @@from pathlib import Pathimport darkdetect-from PySide6.QtCore import QSize, QUrl, QThread, Signal, QTimer-from PySide6.QtGui import QIcon, QDesktopServices-from PySide6.QtWebSockets import QWebSocket+from PySide6.QtCore import QSize, QThread, Signal, QTimer+from PySide6.QtGui import QIconfrom PySide6.QtWidgets import QApplicationfrom loguru import loggerfrom qfluentwidgets import FluentIcon as FIF, setTheme, Theme-from qfluentwidgets import NavigationItemPosition, MessageBox, MSFluentWindow, SplashScreen+from qfluentwidgets import NavigationItemPosition, MSFluentWindow, SplashScreenfrom .setting_interface import SettingInterfacefrom .task_interface import TaskInterface-from ..common.config import VERSION, YEAR, AUTHOR, AUTHOR_URL, cfg+from ..common.config import cfgfrom ..common.custom_socket import GhostDownloaderSocketServerfrom ..common.signal_bus import signalBusfrom ..components.add_task_dialog import AddTaskOptionDialog+from ..components.custom_tray import CustomSystemTrayIconclass ThemeChangedListener(QThread):@@ -46,7 +46,7 @@ class MainWindow(MSFluentWindow):self.themeChangedListener.themeChanged.connect(self.toggleTheme)self.themeChangedListener.start()- # createUnfinishedTask+ # 创建未完成的任务historyFile = Path("./Ghost Downloader 记录文件")# 未完成任务记录文件格式示例: [{"url": "xxx", "fileName": "xxx", "filePath": "xxx", "blockNum": x, "status": "xxx"}]if historyFile.exists():@@ -60,14 +60,23 @@ class MainWindow(MSFluentWindow):else:historyFile.touch()+ # 启动浏览器扩展服务器if cfg.enableBrowserExtension.value == True:self.browserExtensionSocket = GhostDownloaderSocketServer(self)- self.browserExtensionSocket.receiveUrl.connect(lambda x: self.taskInterface.addDownloadTask(x, cfg.downloadFolder.value, cfg.maxBlockNum.value))+ self.browserExtensionSocket.receiveUrl.connect(self.addDownloadTaskFromWebSocket)++ # 创建托盘+ self.tray = CustomSystemTrayIcon(self)+ self.tray.show()self.splashScreen.finish()+ def addDownloadTaskFromWebSocket(self, url: str):+ self.taskInterface.addDownloadTask(url, cfg.downloadFolder.value, cfg.maxBlockNum.value)+ self.tray.showMessage(self.windowTitle(), f"已捕获来自浏览器的下载任务: \n{url}", self.windowIcon())+def toggleTheme(self, callback: str):- if callback == 'Dark':+ if callback == 'Dark': # PySide6 特性,需要重试setTheme(Theme.DARK, save=False)QTimer.singleShot(100, lambda: self.windowEffect.setMicaEffect(self.winId(), True))QTimer.singleShot(200, lambda: self.windowEffect.setMicaEffect(self.winId(), True))@@ -114,21 +123,6 @@ class MainWindow(MSFluentWindow):w.exec()def closeEvent(self, event):- super().closeEvent(event)-- self.themeChangedListener.terminate()-- for i in self.taskInterface.cards:- if i.status == 'working':- for j in i.task.workers:- try:- j.file.close()- except AttributeError as e:- logger.info(f"Task:{i.task.fileName}, users operate too quickly!, thread {i} error: {e}")- except Exception as e:- logger.warning(- f"Task:{i.task.fileName}, it seems that cannot cancel thread {i} occupancy of the file, error: {e}")- j.terminate()- i.task.terminate()-- event.accept()+ # 拦截关闭事件,隐藏窗口而不是退出+ event.ignore()+ self.hide()\ No newline at end of filediff --git a/app/view/setting_interface.py b/app/view/setting_interface.pyindex b6014a0b..500d8cd2 100644--- a/app/view/setting_interface.py+++ b/app/view/setting_interface.py@@ -1,8 +1,10 @@# coding:utf-8+import sys+from PySide6.QtCore import Qt, Signal, QUrl, QResourcefrom PySide6.QtGui import QDesktopServicesfrom PySide6.QtWidgets import QWidget, QFileDialog, QVBoxLayout-from qfluentwidgets import FluentIcon as FIF+from qfluentwidgets import FluentIcon as FIF, InfoBarPositionfrom qfluentwidgets import InfoBarfrom qfluentwidgets import (SettingCardGroup, SwitchSettingCard, OptionsSettingCard, PushSettingCard,HyperlinkCard, PrimaryPushSettingCard, ScrollArea,@@ -64,7 +66,7 @@ class SettingInterface(ScrollArea):"导出浏览器插件",FIF.DICTIONARY,"安装浏览器扩展",- "需要您导出 .crx 文件后手动安装至Chromium内核的浏览器",+ "需要您导出 .crx 文件后手动安装至 Chromium 内核的浏览器",self.browserGroup)@@ -111,7 +113,7 @@ class SettingInterface(ScrollArea):# update softwareself.updateSoftwareGroup = SettingCardGroup(- "软件更新", self.scrollWidget)+ "应用", self.scrollWidget)self.updateOnStartUpCard = SwitchSettingCard(FIF.UPDATE,"在应用程序启动时检查更新",@@ -119,6 +121,13 @@ class SettingInterface(ScrollArea):configItem=cfg.checkUpdateAtStartUp,parent=self.updateSoftwareGroup)+ self.autoRunCard = SwitchSettingCard(+ FIF.VPN,+ "开机启动",+ "在系统启动时静默运行 Ghost Downloader",+ configItem=cfg.autoRun,+ parent=self.updateSoftwareGroup+ )# applicationself.aboutGroup = SettingCardGroup("关于", self.scrollWidget)@@ -184,6 +193,7 @@ class SettingInterface(ScrollArea):self.updateSoftwareGroup.addSettingCard(self.updateOnStartUpCard)+ self.updateSoftwareGroup.addSettingCard(self.autoRunCard)self.aboutGroup.addSettingCard(self.authorCard)self.aboutGroup.addSettingCard(self.feedbackCard)@@ -224,6 +234,32 @@ class SettingInterface(ScrollArea):with open(fileResolve, "wb") as f:f.write(QResource(":/res/chrome_extension.crx").data())+ def __onAutoRunCardChecked(self, value: bool):+ """ Set auto run """+ if sys.platform == "win32":+ import winreg+ if value:+ key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,+ r'Software\Microsoft\Windows\CurrentVersion\Run', 0, winreg.KEY_WRITE)+ winreg.SetValueEx(key, 'GhostDownloader', 0, winreg.REG_SZ,+ f'"{sys.argv[0]}" --silence')+ else:+ key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,+ r'Software\Microsoft\Windows\CurrentVersion\Run', 0, winreg.KEY_WRITE)+ winreg.DeleteValue(key, 'GhostDownloader')+ else:+ InfoBar.warning(+ title='注意',+ content=f"该功能仅在 Windows 平台有效.",+ orient=Qt.Horizontal,+ isClosable=True,+ position=InfoBarPosition.TOP,+ # position='Custom', # NOTE: use custom info bar manager+ duration=1000,+ parent=self.parent()+ )++def __connectSignalToSlot(self):""" connect signal to slot """cfg.appRestartSig.connect(self.__showRestartTooltip)@@ -237,8 +273,8 @@ class SettingInterface(ScrollArea):# extensionself.installExtensionCard.clicked.connect(self.__onInstallExtensionCardClicked)- # personalization- # self.themeColorCard.colorChanged.connect(setThemeColor)+ # software+ self.autoRunCard.checkedChanged.connect(self.__onAutoRunCardChecked)# aboutself.aboutCard.clicked.connect(self.checkUpdateSig)diff --git a/main.py b/main.pyindex ba83ac03..47362069 100644--- a/main.py+++ b/main.py@@ -77,6 +77,10 @@ w = MainWindow()# loading pluginsloadPlugins(w)-w.show()+try: # 静默启动+ if sys.argv[1] == "--silence":+ w.hide()+except:+ w.show()sys.exit(app.exec())