Skip to content

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

refactor(app): 提取窗口置顶逻辑到单独的方法 bringWindowToTop

XiaoYouChR34b52150cc7c
diff --git a/app/common/methods.py b/app/common/methods.py
index ddf9100f..fbf2d155 100644
--- a/app/common/methods.py
+++ b/app/common/methods.py
@@ -262,4 +262,13 @@ def getLinkInfo(url:str, headers:dict, fileName:str="", verify:bool=False, proxy
fileName = f"downloaded_file{int(time_ns())}.{content_type}"
logger.debug(f"方法4获取文件名成功, 文件名:{fileName}")
- return url, fileName, fileSize
\ No newline at end of file
+ return url, fileName, fileSize
+
+
+def bringWindowToTop(window):
+ window.show()
+ if window.isMinimized():
+ window.showNormal()
+ # 激活窗口,使其显示在最前面
+ window.activateWindow()
+ window.raise_()
\ No newline at end of file
diff --git a/app/components/custom_tray.py b/app/components/custom_tray.py
index 4506a169..ba69003f 100644
--- a/app/components/custom_tray.py
+++ b/app/components/custom_tray.py
@@ -5,6 +5,8 @@ from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets.common.screen import getCurrentScreenGeometry
from qfluentwidgets.components.material import AcrylicMenu
+from app.common.methods import bringWindowToTop
+
class FixedAcrylicSystemTrayMenu(AcrylicMenu):
""" 修复背景获取偏移、位置偏移的问题 """
@@ -56,11 +58,7 @@ class CustomSystemTrayIcon(QSystemTrayIcon):
self.messageClicked.connect(self.__onShowActionTriggered)
def __onShowActionTriggered(self):
- self.parent().show()
- if self.parent().isMinimized():
- self.parent().showNormal()
- # 激活窗口,使其显示在最前面
- self.parent().activateWindow()
+ bringWindowToTop(self.parent())
def __onAllStartActionTriggered(self):
self.parent().taskInterface.allStartTasks()
diff --git a/app/view/main_window.py b/app/view/main_window.py
index a516386d..1e2e04b7 100644
--- a/app/view/main_window.py
+++ b/app/view/main_window.py
@@ -17,7 +17,7 @@ from .setting_interface import SettingInterface
from .task_interface import TaskInterface
from ..common.config import cfg, Headers, attachmentTypes
from ..common.custom_socket import GhostDownloaderSocketServer
-from ..common.methods import getLinkInfo
+from ..common.methods import getLinkInfo, bringWindowToTop
from ..common.signal_bus import signalBus
from ..components.add_task_dialog import AddTaskOptionDialog
from ..components.custom_tray import CustomSystemTrayIcon
@@ -304,10 +304,5 @@ class MainWindow(MSFluentWindow):
return
ans = '\n'.join(results)
logger.debug(f"Clipboard changed: {ans}")
- self.__bringToTop()
+ bringWindowToTop(self)
self.__setUrlsAndShowAddTaskBox(ans)
-
- def __bringToTop(self):
- self.showNormal()
- self.activateWindow()
- self.raise_()