Skip to content

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

feat(ui): 添加应用日志文件夹打开功能

XiaoYouChR45f0851c15dd
diff --git a/app/supports/utils.py b/app/supports/utils.py
index bf2fd9f8..c2b3691c 100644
--- a/app/supports/utils.py
+++ b/app/supports/utils.py
@@ -6,10 +6,10 @@ from pathlib import Path
from time import sleep
from typing import Callable
-from PySide6.QtCore import QUrl, Qt, QProcess
+from PySide6.QtCore import QUrl, Qt, QProcess, QStandardPaths
from PySide6.QtGui import QDesktopServices
from loguru import logger
-from qfluentwidgets import MessageBox
+from qfluentwidgets import MessageBox, ToolButton, FluentIcon
from app.bases.models import Task
from app.supports.config import cfg
@@ -33,6 +33,11 @@ def openFolder(path):
raise FileNotFoundError(path)
+def openAppLogFolder():
+ appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
+ openFolder(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log")
+
+
def getSystemProxy():
if sys.platform == "win32":
try:
@@ -243,7 +248,15 @@ def bringWindowToTop(window):
window.raise_()
-def showMessageBox(self, title: str, content: str, showYesButton=False, yesSlot=None):
+def showMessageBox(
+ self,
+ title: str,
+ content: str,
+ showYesButton=False,
+ yesSlot=None,
+ actionIcon: FluentIcon | None = None,
+ actionSlot=None,
+):
"""show message box"""
w = MessageBox(title, content, self)
w.contentLabel.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
@@ -252,5 +265,10 @@ def showMessageBox(self, title: str, content: str, showYesButton=False, yesSlot=
w.yesButton.hide()
w.buttonLayout.insertStretch(0, 1)
+ if actionIcon and actionSlot is not None:
+ actionButton = ToolButton(actionIcon, w)
+ actionButton.clicked.connect(actionSlot)
+ w.buttonLayout.insertWidget(3, actionButton)
+
if w.exec() and yesSlot is not None:
yesSlot()
diff --git a/app/view/pages/setting_page.py b/app/view/pages/setting_page.py
index 8cdd2532..14ef05db 100644
--- a/app/view/pages/setting_page.py
+++ b/app/view/pages/setting_page.py
@@ -8,10 +8,11 @@ from PySide6.QtGui import QDesktopServices
from PySide6.QtWidgets import QWidget, QVBoxLayout, QFileDialog
from qfluentwidgets import SettingCardGroup, RangeSettingCard, FluentIcon, SwitchSettingCard, PushSettingCard, \
HyperlinkButton, ComboBoxSettingCard, HyperlinkCard, PrimaryPushSettingCard, InfoBar, FlyoutView, Flyout, \
- InfoBarPosition
+ InfoBarPosition, ToolButton, ToolTipFilter
from app.supports.config import cfg, FIREFOX_ADDONS_URL, EDGE_ADDONS_URL, CHROME_ADDONS_URL, AUTHOR_URL, AUTHOR, YEAR, \
VERSION, FEEDBACK_URL
+from app.supports.utils import openAppLogFolder
from app.view.components.setting_cards import SpinBoxSettingCard, SelectFolderSettingCard, ProxySettingCard
if TYPE_CHECKING:
@@ -238,6 +239,11 @@ class SettingPage(ScrollArea):
self.aboutGroup,
)
self.aboutGroup.addSettingCard(self.feedbackCard)
+ self.openLogButton = ToolButton(FluentIcon.DOCUMENT, self.feedbackCard)
+ self.openLogButton.setToolTip(self.tr("查看日志"))
+ self.openLogButton.installEventFilter(ToolTipFilter(self.openLogButton))
+ self.feedbackCard.hBoxLayout.insertSpacing(6, 8)
+ self.feedbackCard.hBoxLayout.insertWidget(7, self.openLogButton, 0, Qt.AlignmentFlag.AlignRight)
self.aboutCard = PrimaryPushSettingCard(
self.tr("检查更新"),
FluentIcon.INFO,
@@ -264,6 +270,7 @@ class SettingPage(ScrollArea):
self.feedbackCard.clicked.connect(
lambda: QDesktopServices.openUrl(QUrl(FEEDBACK_URL))
)
+ self.openLogButton.clicked.connect(openAppLogFolder)
def _showRestartTooltip(self):
InfoBar.success(
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index 9c24a2e7..9412decf 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -20,7 +20,7 @@ from app.supports.config import cfg, DEFAULT_HEADERS, AUTHOR_URL, VERSION, FEEDB
from app.supports.recorder import taskRecorder
from app.supports.signal_bus import signalBus
from app.supports.update import fetchLatestRelease, hasNewerRelease, releaseVersion, selectCurrentPlatformAsset
-from app.supports.utils import getProxies, bringWindowToTop, showMessageBox, ensureUniqueTaskTarget
+from app.supports.utils import getProxies, bringWindowToTop, showMessageBox, ensureUniqueTaskTarget, openAppLogFolder
from app.view.components.add_task_dialog import AddTaskDialog
from app.view.components.labels import IconBodyLabel
from app.view.components.release_info_dialog import ReleaseInfoDialog
@@ -30,7 +30,8 @@ from app.view.pages.task_page import TaskPage
if TYPE_CHECKING:
from typing import Literal
- from PySide6.QtGui import QClipboard, QSize
+ from PySide6.QtGui import QClipboard
+ from PySide6.QtCore import QSize
class CustomSplashScreen(SplashScreen):
@@ -230,9 +231,11 @@ class MainWindow(MSFluentWindow):
showMessageBox(
self,
self.tr("程序发生异常"),
- self.tr("点击“确定”后将复制错误信息并打开反馈页面。\n{0}").format(message),
+ self.tr("点击“确定”后将复制错误信息并打开反馈页面。\n点击“文档”图标以打开程序日志。\n{0}").format(message),
showYesButton=True,
yesSlot=lambda: self._copyExceptionAndOpenFeedback(message),
+ actionIcon=FluentIcon.DOCUMENT,
+ actionSlot=openAppLogFolder,
)
def _copyExceptionAndOpenFeedback(self, message: str):