Skip to content

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

refactor(startup): 理清入口和 startup 的职责

XiaoYouChR3692173915ee
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index 8f0ed8b2..e4756a1a 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -50,14 +50,12 @@ def setupEnvironment():
def startApp(application, isSilent=False):
- import shutil
from PySide6.QtGui import QIcon
from app.config.cfg import cfg
- from app.config.paths import EXECUTABLE_DIR
from app.view.shell.clipboard_listener import ClipboardListener
from app.signal_bus import signalBus
from app.services.update_service import UpdateService
- from app.startup import createEngine, loadPacks, checkUpdateAtStartup
+ from app.startup import loadResources, createEngine, deleteBackupDir, loadPacks, checkUpdateAtStartup
from app.view.windows.main_window import MainWindow
def exceptionHook(exceptionType, value, tb):
@@ -78,14 +76,12 @@ def startApp(application, isSilent=False):
from app.view.shell.dock import setDockIconVisible
setDockIconVisible(cfg.shouldShowDockIcon.value, activate=False)
+ loadResources(application)
engine = createEngine(application)
coroutineRunner, taskService, featureService = engine.coroutineRunner, engine.taskService, engine.featureService
browserService, speedMeter = engine.browserService, engine.speedMeter
- appDir = EXECUTABLE_DIR.parent.parent if sys.platform == "darwin" else EXECUTABLE_DIR
- backupDir = appDir.parent / f"{appDir.name}_backup"
- if backupDir.is_dir():
- shutil.rmtree(backupDir, ignore_errors=True)
+ deleteBackupDir()
MainWindow.refreshThemeColor()
diff --git a/app/startup.py b/app/startup.py
index a2e63892..bc46d1ac 100644
--- a/app/startup.py
+++ b/app/startup.py
@@ -1,7 +1,15 @@
-"""桌面端独有的启动阶段:创建 Engine、加载翻译与 pack、启动时检查更新。"""
+"""桌面端独有的准备步骤,每步自成一体、不碰 View。各步的顺序和服务与 View 之间的接线由入口 Ghost-Downloader-3.py 决定。"""
from __future__ import annotations
+def loadResources(application):
+ from PySide6.QtCore import QResource
+ from app.config.paths import EXECUTABLE_DIR
+
+ QResource.registerResource(str(EXECUTABLE_DIR / "app" / "assets" / "resources.rcc"))
+ loadTranslators(application)
+
+
def loadTranslators(application):
from PySide6.QtCore import QLocale, QTranslator
from app.config.cfg import cfg
@@ -22,17 +30,12 @@ def loadTranslators(application):
def createEngine(application):
import sys
- from PySide6.QtCore import QFileSystemWatcher, QResource, QTimer
+ from PySide6.QtCore import QFileSystemWatcher, QTimer
from shiboken6 import isValid
- from app.config.paths import EXECUTABLE_DIR
from app.engine import Engine
from app.platform.desktop import loadCrx
from app.services.coroutine_runner import CoroutineRunner
- QResource.registerResource(str(EXECUTABLE_DIR / "app" / "assets" / "resources.rcc"))
-
- loadTranslators(application)
-
if sys.platform == "win32":
from winloop import new_event_loop
else:
@@ -46,6 +49,17 @@ def createEngine(application):
return Engine(coroutineRunner, QFileSystemWatcher(), loadCrx)
+def deleteBackupDir():
+ import shutil
+ import sys
+ from app.config.paths import EXECUTABLE_DIR
+
+ appDir = EXECUTABLE_DIR.parent.parent if sys.platform == "darwin" else EXECUTABLE_DIR
+ backupDir = appDir.parent / f"{appDir.name}_backup"
+ if backupDir.is_dir():
+ shutil.rmtree(backupDir, ignore_errors=True)
+
+
def loadPacks(featureService, coroutineRunner, speedMeter):
from app.models.pack import PackConfig, PackServices
from app.services.update_service import installPendingPacks