Skip to content

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

feat(app): 添加异常捕获和反馈功能

XiaoYouChR84b57c40125b
diff --git a/app/supports/application.py b/app/supports/application.py
index e5f57f67..0962204c 100644
--- a/app/supports/application.py
+++ b/app/supports/application.py
@@ -86,5 +86,5 @@ def exceptionHook(exception: BaseException, value, tb):
""" exception callback function """
message = '\n'.join([''.join(traceback.format_tb(tb)),
'{0}: {1}'.format(exception.__name__, value)])
- logger.opt(exception=(exception, value, tb)).error("Unhandled application exception")
+ logger.opt(exception=exception).error("Unhandled application exception")
signalBus.catchException.emit(message)
diff --git a/app/supports/utils.py b/app/supports/utils.py
index 69e00568..485d86a9 100644
--- a/app/supports/utils.py
+++ b/app/supports/utils.py
@@ -5,7 +5,7 @@ from functools import wraps
from time import sleep
from typing import Callable
-from PySide6.QtCore import QUrl, QOperatingSystemVersion
+from PySide6.QtCore import QUrl, QOperatingSystemVersion, Qt
from PySide6.QtGui import QDesktopServices, QColor
from loguru import logger
from qfluentwidgets import MessageBox, setThemeColor
@@ -245,6 +245,7 @@ def bringWindowToTop(window):
def showMessageBox(self, title: str, content: str, showYesButton=False, yesSlot=None):
"""show message box"""
w = MessageBox(title, content, self)
+ w.contentLabel.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
if not showYesButton:
w.cancelButton.setText("关闭")
w.yesButton.hide()
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index 9bc4324a..2471fde1 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -11,11 +11,11 @@ from qfluentwidgets import MSFluentWindow, SplashScreen, FluentIcon, NavigationI
from app.services.browser_service import BrowserService
from app.services.core_service import coreService
from app.services.feature_service import featureService
-from app.supports.config import cfg, DEFAULT_HEADERS, AUTHOR_URL, VERSION
+from app.supports.config import cfg, DEFAULT_HEADERS, AUTHOR_URL, VERSION, FEEDBACK_URL
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
+from app.supports.utils import getProxies, bringWindowToTop, showMessageBox
from app.view.components.add_task_dialog import AddTaskDialog
from app.view.components.release_info_dialog import ReleaseInfoDialog
from app.view.components.tray import SystemTrayIcon
@@ -62,6 +62,7 @@ class MainWindow(MSFluentWindow):
def connectSignalToSlot(self):
signalBus.showMainWindow.connect(lambda: bringWindowToTop(self))
+ signalBus.catchException.connect(self._onExceptionCaught)
cfg.enableClipboardListener.valueChanged.connect(self._syncClipboardListener)
def _syncClipboardListener(self):
@@ -100,6 +101,20 @@ class MainWindow(MSFluentWindow):
bringWindowToTop(self)
self.showAddTaskDialog(urls=urls)
+ def _onExceptionCaught(self, message: str):
+ bringWindowToTop(self)
+ showMessageBox(
+ self,
+ self.tr("程序发生异常"),
+ self.tr("点击“确定”后将复制错误信息并打开反馈页面。\n{0}").format(message),
+ showYesButton=True,
+ yesSlot=lambda: self._copyExceptionAndOpenFeedback(message),
+ )
+
+ def _copyExceptionAndOpenFeedback(self, message: str):
+ QApplication.clipboard().setText(message)
+ QDesktopServices.openUrl(QUrl(FEEDBACK_URL))
+
def getAddTaskDialog(self) -> AddTaskDialog:
if AddTaskDialog.instance is None:
instance = AddTaskDialog.initialize(self)