Skip to content

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

Fixes #295, Fixes #403

XiaoYouChR41d3a90ca17b
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index 3ab3f712..a3066227 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -1,17 +1,45 @@
import os
import sys
+import traceback
+from time import localtime, strftime, time
+from loguru import logger
from PySide6.QtCore import QStandardPaths
-from qfluentwidgets import qconfig
-
-from app.supports.application import SingletonApplication
-from app.supports.config import cfg
-
# import orjson
# sys.modules['json'] = orjson
+exceptionSignalBus = None
+
+def exceptionHook(exceptionType, value, tb):
+ exceptionInfo = (exceptionType, value, tb)
+ message = "".join(traceback.format_exception(*exceptionInfo)).rstrip()
+ logger.opt(exception=exceptionInfo).error("Unhandled application exception")
+
+ if exceptionSignalBus is not None:
+ try:
+ exceptionSignalBus.catchException.emit(message)
+ except Exception as error:
+ logger.opt(exception=error).warning("Failed to emit application exception signal")
+
+ if "__compiled__" not in globals():
+ sys.__excepthook__(*exceptionInfo)
+
appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
+logger.add(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log", rotation="512 KB", enqueue=True)
+sys.excepthook = exceptionHook
+
+from qfluentwidgets import qconfig
+from app.supports.application import SingletonApplication
+from app.supports.config import VERSION, cfg
+from app.supports.signal_bus import signalBus as exceptionSignalBus
+
+logger.info(
+ "Ghost Downloader v{} is launched at {}",
+ VERSION,
+ strftime("%Y-%m-%d %H:%M:%S", localtime(time())),
+)
+
qconfig.load(f"{appLocalDataLocation}/GhostDownloader/UserConfig.json", cfg)
if cfg.get(cfg.dpiScale) != 0:
@@ -21,7 +49,6 @@ if cfg.get(cfg.dpiScale) != 0:
application = SingletonApplication(sys.argv, "gd3")
# --- Start Program ---
-from loguru import logger
import warnings
from PySide6.QtCore import QTranslator
diff --git a/app/supports/application.py b/app/supports/application.py
index 85057295..0ca075d0 100644
--- a/app/supports/application.py
+++ b/app/supports/application.py
@@ -1,13 +1,11 @@
from signal import signal, SIGINT
import sys
-import traceback
-from time import localtime, strftime, time
-from PySide6.QtCore import QSharedMemory, QEvent, QStandardPaths
+from PySide6.QtCore import QSharedMemory, QEvent
from PySide6.QtWidgets import QApplication
from loguru import logger
-from app.supports.config import VERSION, cfg
+from app.supports.config import cfg
from app.supports.signal_bus import signalBus
if sys.platform == "darwin":
@@ -25,11 +23,6 @@ class SingletonApplication(QApplication):
super().__init__(argv)
self.key = key
- appLocalDataLocation = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.GenericDataLocation)
- logger.add(f"{appLocalDataLocation}/GhostDownloader/GhostDownloader.log", rotation="512 KB", enqueue=True)
- logger.info(
- f"Ghost Downloader v{VERSION} is Launched at {strftime('%Y-%m-%d %H:%M:%S', localtime(time()))}")
-
# cleanup (only needed for unix)
try:
cleanupMemory = QSharedMemory(key)
@@ -68,9 +61,6 @@ class SingletonApplication(QApplication):
logger.opt(exception=e).error("Failed to recover from shared memory error")
raise RuntimeError(self.memory.errorString())
- if "__compiled__" in globals(): # 编译后的错误捕捉
- sys.excepthook = exceptionHook
-
try:
signal(SIGINT, self._handleInterruptSignal)
except Exception as e:
@@ -123,10 +113,3 @@ class SingletonApplication(QApplication):
signalBus.showMainWindow.emit()
return super().event(e)
-
-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).error("Unhandled application exception")
- signalBus.catchException.emit(message)
diff --git a/app/view/windows/main_window.py b/app/view/windows/main_window.py
index 00ca8642..fef9e3a2 100644
--- a/app/view/windows/main_window.py
+++ b/app/view/windows/main_window.py
@@ -204,7 +204,12 @@ class MainWindow(MSFluentWindow):
if not url:
continue
- parsed = urlparse(url)
+ try:
+ parsed = urlparse(url)
+ except ValueError as error:
+ logger.warning("跳过无效剪贴板链接 {}: {}", url, error)
+ continue
+
if not parsed.scheme or not parsed.netloc or parsed.geturl() != url:
continue