Skip to content

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

feat(Runtime): 运行时自描述,安装改用 GitHub 直链

XiaoYouChRae467d80cc5a
diff --git a/Ghost-Downloader-3.py b/Ghost-Downloader-3.py
index 8a8f30b4..5f576a2f 100644
--- a/Ghost-Downloader-3.py
+++ b/Ghost-Downloader-3.py
@@ -91,9 +91,9 @@ def startApp(application, isSilent=False):
MainWindow.refreshThemeColor()
window = MainWindow()
- needsOobe = not cfg.hasCompletedOobe.value and not isSilent
+ shouldRunOobe = not cfg.hasCompletedOobe.value and not isSilent
- if not isSilent and not needsOobe:
+ if not isSilent and not shouldRunOobe:
from qfluentwidgets import SplashScreen
splash = SplashScreen(window.windowIcon(), window, enableShadow=False)
splash.raise_()
@@ -104,10 +104,10 @@ def startApp(application, isSilent=False):
window.setupPacks()
startEngine()
- if not isSilent and not needsOobe:
+ if not isSilent and not shouldRunOobe:
splash.finish()
- if needsOobe:
+ if shouldRunOobe:
# 首次启动:不显示主窗口,OOBE 完成后再进入
from PySide6.QtCore import QEventLoop
from app.view.windows.oobe_window import OobeWindow
diff --git a/android/Dockerfile b/android/Dockerfile
index 96bc8d6f..d0e186c3 100644
--- a/android/Dockerfile
+++ b/android/Dockerfile
@@ -101,7 +101,7 @@ RUN git clone --depth 1 -b develop "${P4A_GIT_URL}" /opt/p4a \
# replacing hzw1199's full build (~30MB). Pinned to a tag for reproducible APKs;
# bump the tag to update. See https://github.com/XiaoYouChR/Ghost-Downloader-FFmpeg
ARG FFMPEG_TARBALL=https://github.com/XiaoYouChR/Ghost-Downloader-FFmpeg/releases/download/n8.1.2-gd1/ffmpeg-android-arm64.tar.gz
-ARG NM3U8_URL=https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.5.1-beta/N_m3u8DL-RE_v0.5.1-beta_android-bionic-arm64_20251029.tar.gz
+ARG NM3U8_URL=https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.6.0-beta/N_m3u8DL-RE_v0.6.0-beta_android-bionic-arm64_20260629.tar.gz
RUN mkdir -p /opt/gd3-ffmpeg && cd /opt/gd3-ffmpeg \
&& wget -q "${FFMPEG_TARBALL}" -O /tmp/ffmpeg.tar.gz \
&& tar -xzf /tmp/ffmpeg.tar.gz -C /tmp \
diff --git a/android/run_build.sh b/android/run_build.sh
index 3bb35fb4..22b1f172 100644
--- a/android/run_build.sh
+++ b/android/run_build.sh
@@ -17,7 +17,7 @@ if [[ "${GD3_CN_MIRROR:-0}" == "1" ]]; then
--build-arg "RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup"
--build-arg "P4A_GIT_URL=https://gitee.com/mirrors/python-for-android.git"
--build-arg "FFMPEG_TARBALL=https://gh-proxy.com/https://github.com/XiaoYouChR/Ghost-Downloader-FFmpeg/releases/download/n8.1.2-gd1/ffmpeg-android-arm64.tar.gz"
- --build-arg "NM3U8_URL=https://gh-proxy.com/https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.5.1-beta/N_m3u8DL-RE_v0.5.1-beta_android-bionic-arm64_20251029.tar.gz"
+ --build-arg "NM3U8_URL=https://gh-proxy.com/https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.6.0-beta/N_m3u8DL-RE_v0.6.0-beta_android-bionic-arm64_20260629.tar.gz"
--build-arg "GD3_GRADLE_CN=1"
)
fi
diff --git a/app/models/pack.py b/app/models/pack.py
index ac42b0cf..783bb5d0 100644
--- a/app/models/pack.py
+++ b/app/models/pack.py
@@ -11,6 +11,7 @@ from app.config.cfg import cfg, ConfigItem
if TYPE_CHECKING:
from app.models.task import Task, TaskOptions
from PySide6.QtWidgets import QWidget
+ from qfluentwidgets import FluentIcon
from app.view.components.setting_card_group import CollapsibleSettingCardGroup
@@ -80,6 +81,11 @@ class PackConfig:
class BinaryRuntime:
name: str = ""
canInstall: bool = False
+ # 自描述展示信息(title 用 QT_TRANSLATE_NOOP 声明原文,展示端 translate)
+ title: str = ""
+ description: str = ""
+ icon: FluentIcon | None = None
+ isRecommended: bool = False
@property
def runtimeId(self) -> str:
diff --git a/app/services/browser_service.py b/app/services/browser_service.py
index f9afa6ef..c84c2a60 100644
--- a/app/services/browser_service.py
+++ b/app/services/browser_service.py
@@ -116,6 +116,7 @@ class BrowserService(QObject):
taskDraftRequested = Signal(list)
extensionUpdated = Signal(str)
connectionChanged = Signal()
+ protocolMismatched = Signal()
def __init__(self, parent=None):
super().__init__(parent)
@@ -410,6 +411,7 @@ class BrowserService(QObject):
if toInt(data, "protocolVersion", 0) != PROTOCOL_VERSION:
self._sendError(session, "协议版本不匹配", requestId=requestId, code=ErrorCode.PROTOCOL_MISMATCH)
session.socket.close()
+ self.protocolMismatched.emit()
return
if toStr(data, "token") != self.token:
diff --git a/app/view/windows/oobe_window.py b/app/view/windows/oobe_window.py
index 116be147..76a3826c 100644
--- a/app/view/windows/oobe_window.py
+++ b/app/view/windows/oobe_window.py
@@ -3,19 +3,18 @@ from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
-from PySide6.QtCore import Qt, QRectF, QSize, QUrl, Signal
+from PySide6.QtCore import Qt, QCoreApplication, QRectF, QSize, QUrl, Signal
from PySide6.QtGui import QColor, QDesktopServices, QIcon, QMovie, QPainter, QPainterPath, QPen
from PySide6.QtWidgets import (
- QApplication, QFileDialog, QHBoxLayout, QLabel,
- QVBoxLayout, QWidget,
+ QApplication, QFileDialog, QHBoxLayout, QLabel, QVBoxLayout, QWidget,
)
from qfluentwidgets import (
BodyLabel, CaptionLabel, CardWidget, CheckBox, ComboBox,
DrillInTransitionStackedWidget, FluentIcon, FluentWidget,
- GroupHeaderCardWidget, HorizontalPipsPager, InfoBar, InfoBarIcon,
- InfoBarPosition, PipsScrollButtonDisplayMode, PrimaryPushButton,
- PushButton, SubtitleLabel, SwitchButton, Theme, TitleLabel,
- TransparentPushButton, isDarkTheme, themeColor,
+ GroupHeaderCardWidget, HorizontalPipsPager, IconWidget, InfoBar,
+ InfoBarIcon, InfoBarPosition, PipsScrollButtonDisplayMode,
+ PrimaryPushButton, PushButton, SubtitleLabel, SwitchButton, Theme,
+ TitleLabel, TransparentPushButton, isDarkTheme, themeColor,
)
from app.config.cfg import cfg, Language
@@ -32,49 +31,11 @@ PREVIEW_GIF = ":/res/install_chrome_extension_guidance.webp"
PREVIEW_SIZE = QSize(592, 333)
STORE_COLUMN_WIDTH = 280
-# 以运行时类名为键,避免依赖 Pack 的模块导入路径
-# colors: (lightBg, lightFg, darkBg, darkFg)
-RUNTIME_PROFILES = {
- "FFmpegRuntime": {
- "title": "视频合并",
- "description": "哔哩哔哩、YouTube 等网站视频下载必备,合并音视频轨道为完整文件",
- "icon": FluentIcon.VIDEO,
- "colors": ("#E8DCFF", "#7B61FF", "#3D2E6B", "#B49AFF"),
- "defaultChecked": True,
- "order": 0,
- },
- "M3U8Runtime": {
- "title": "M3U8 / 直播下载",
- "description": "支持 HLS、DASH 等流媒体协议,可录制直播流",
- "icon": FluentIcon.MEDIA,
- "colors": ("#D4F0FF", "#0078D4", "#1A3548", "#4CC2FF"),
- "defaultChecked": True,
- "order": 1,
- },
- "YouTubeRuntime": {
- "title": "YouTube 下载",
- "description": "支持 YouTube、Twitter 等数百个视频网站",
- "icon": FluentIcon.GLOBE,
- "colors": ("#FFE0E0", "#E53935", "#4A2020", "#FF6B6B"),
- "defaultChecked": True,
- "order": 2,
- },
- "ED2kRuntime": {
- "title": "eD2k / eMule",
- "description": "支持电驴协议,适合下载经典资源",
- "icon": FluentIcon.BOOK_SHELF,
- "colors": ("#E0F0E0", "#2E7D32", "#1A3A1A", "#66BB6A"),
- "defaultChecked": False,
- "order": 3,
- },
-}
-
-
-# ─── Reusable widgets ───────────────────────────────────────────────
+NEUTRAL_CHIP_COLORS = ("#EFEFEF", "#666666", "#3D3D3D", "#AAAAAA")
+SUCCESS_CHIP_COLORS = ("#E8F5E9", "#0F7B46", "#1A3A1A", "#4ADE80")
class IconChip(QWidget):
- """圆角底色图标块,深浅主题各一套配色"""
def __init__(self, icon: FluentIcon, colors: tuple[str, str, str, str],
size: int = 40, parent=None):
@@ -99,21 +60,17 @@ class IconChip(QWidget):
self._icon.render(painter, iconRect)
-NEUTRAL_CHIP_COLORS = ("#EFEFEF", "#666666", "#3D3D3D", "#AAAAAA")
-
-
class ThemePreview(QWidget):
- """迷你窗口缩略图:假标题栏 + 内容条 + 强调色块。mode: light / dark / auto"""
def __init__(self, mode: str, parent=None):
super().__init__(parent)
self._mode = mode
self.setFixedHeight(96)
- def _drawMini(self, painter: QPainter, rect: QRectF, dark: bool) -> None:
- bg = QColor("#232323") if dark else QColor("#F5F7FA")
- titleBar = QColor("#2E2E2E") if dark else QColor("#E9EDF2")
- bar = QColor("#333333") if dark else QColor("#FFFFFF")
+ def _drawMini(self, painter: QPainter, rect: QRectF, isDark: bool) -> None:
+ bg = QColor("#232323") if isDark else QColor("#F5F7FA")
+ titleBar = QColor("#2E2E2E") if isDark else QColor("#E9EDF2")
+ bar = QColor("#333333") if isDark else QColor("#FFFFFF")
painter.fillRect(rect, bg)
painter.fillRect(QRectF(rect.x(), rect.y(), rect.width(), 14), titleBar)
@@ -141,12 +98,10 @@ class ThemePreview(QWidget):
if self._mode == "auto":
half = outer.width() / 2
- leftRect = QRectF(outer.x(), outer.y(), half, outer.height())
- rightRect = QRectF(outer.x() + half, outer.y(), half, outer.height())
- self._drawMini(painter, leftRect, dark=False)
- self._drawMini(painter, rightRect, dark=True)
+ self._drawMini(painter, QRectF(outer.x(), outer.y(), half, outer.height()), isDark=False)
+ self._drawMini(painter, QRectF(outer.x() + half, outer.y(), half, outer.height()), isDark=True)
else:
- self._drawMini(painter, outer, dark=self._mode == "dark")
+ self._drawMini(painter, outer, isDark=self._mode == "dark")
painter.setClipping(False)
painter.setPen(QPen(QColor(128, 128, 128, 60), 1))
@@ -155,24 +110,27 @@ class ThemePreview(QWidget):
class ThemeCard(CardWidget):
- """主题选择卡片,选中时描主题色边框"""
def __init__(self, theme: Theme, label: str, parent=None):
super().__init__(parent)
self.theme = theme
self._isSelected = False
+ self._initWidget(label)
+ self._initLayout()
+
+ def _initWidget(self, label: str) -> None:
self.setClickEnabled(True)
+ mode = {Theme.LIGHT: "light", Theme.DARK: "dark"}.get(self.theme, "auto")
+ self.preview = ThemePreview(mode, self)
+ self.label = BodyLabel(label, self)
+ self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ def _initLayout(self) -> None:
layout = QVBoxLayout(self)
layout.setContentsMargins(14, 14, 14, 12)
layout.setSpacing(10)
-
- mode = {Theme.LIGHT: "light", Theme.DARK: "dark"}.get(theme, "auto")
- layout.addWidget(ThemePreview(mode, self))
-
- label_ = BodyLabel(label, self)
- label_.setAlignment(Qt.AlignmentFlag.AlignCenter)
- layout.addWidget(label_)
+ layout.addWidget(self.preview)
+ layout.addWidget(self.label)
def setSelected(self, isSelected: bool) -> None:
self._isSelected = isSelected
@@ -191,38 +149,43 @@ class ThemeCard(CardWidget):
class ActionCard(CardWidget):
- """可点击操作卡片:图标 + 标题(+ 可换行说明),推荐样式带描边和右侧徽章"""
def __init__(self, icon: FluentIcon, title: str, hint: str = "",
isRecommended: bool = False, parent=None):
super().__init__(parent)
self._isRecommended = isRecommended
+ self._initWidget(icon, title, hint)
+ self._initLayout()
+
+ def _initWidget(self, icon: FluentIcon, title: str, hint: str) -> None:
self.setClickEnabled(True)
if hint:
- self.setMinimumHeight(80) # 说明文字换行时自然增高,避免裁字
+ self.setMinimumHeight(80)
else:
self.setFixedHeight(48)
+ self.iconChip = IconChip(icon, NEUTRAL_CHIP_COLORS, size=30, parent=self)
+ self.titleLabel = BodyLabel(title, self)
+ self.hintLabel = None
+ if hint:
+ self.hintLabel = CaptionLabel(hint, self)
+ self.hintLabel.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
+ self.hintLabel.setWordWrap(True)
+ self.chevron = IconWidget(FluentIcon.CHEVRON_RIGHT_MED, self)
+ self.chevron.setFixedSize(12, 12)
+ def _initLayout(self) -> None:
layout = QHBoxLayout(self)
layout.setContentsMargins(14, 8, 14, 8)
layout.setSpacing(12)
-
- layout.addWidget(IconChip(icon, NEUTRAL_CHIP_COLORS, size=30, parent=self))
+ layout.addWidget(self.iconChip)
textCol = QVBoxLayout()
textCol.setSpacing(2)
- textCol.addWidget(BodyLabel(title, self))
- if hint:
- hintLabel = CaptionLabel(hint, self)
- hintLabel.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
- hintLabel.setWordWrap(True)
- textCol.addWidget(hintLabel)
+ textCol.addWidget(self.titleLabel)
+ if self.hintLabel is not None:
+ textCol.addWidget(self.hintLabel)
layout.addLayout(textCol, 1)
-
- chevron = IconChip(FluentIcon.CHEVRON_RIGHT_MED,
- ("#00000000", "#999999", "#00000000", "#777777"),
- size=16, parent=self)
- layout.addWidget(chevron)
+ layout.addWidget(self.chevron)
def paintEvent(self, event) -> None:
super().paintEvent(event)
@@ -237,40 +200,41 @@ class ActionCard(CardWidget):
class OptionCard(CardWidget):
- """推荐设置卡片:图标 + 标题 + 说明 + 开关"""
def __init__(self, icon: FluentIcon, title: str, desc: str,
isChecked: bool = False, parent=None):
super().__init__(parent)
+ self._initWidget(icon, title, desc, isChecked)
+ self._initLayout()
+
+ def _initWidget(self, icon: FluentIcon, title: str, desc: str, isChecked: bool) -> None:
self.setFixedHeight(64)
+ self.iconChip = IconChip(icon, NEUTRAL_CHIP_COLORS, size=34, parent=self)
+ self.titleLabel = BodyLabel(title, self)
+ self.descLabel = CaptionLabel(desc, self)
+ self.descLabel.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
+ self.switch = SwitchButton(self)
+ self.switch.setOnText("")
+ self.switch.setOffText("")
+ self.switch.setChecked(isChecked)
+ def _initLayout(self) -> None:
layout = QHBoxLayout(self)
layout.setContentsMargins(18, 8, 18, 8)
layout.setSpacing(14)
-
- layout.addWidget(IconChip(icon, NEUTRAL_CHIP_COLORS, size=34, parent=self))
+ layout.addWidget(self.iconChip)
textCol = QVBoxLayout()
textCol.setSpacing(0)
- textCol.addWidget(BodyLabel(title, self))
- descLabel = CaptionLabel(desc, self)
- descLabel.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
- textCol.addWidget(descLabel)
+ textCol.addWidget(self.titleLabel)
+ textCol.addWidget(self.descLabel)
layout.addLayout(textCol, 1)
-
- self.switch = SwitchButton(self)
- self.switch.setOnText("")
- self.switch.setOffText("")
- self.switch.setChecked(isChecked)
layout.addWidget(self.switch)
def isChecked(self) -> bool:
return self.switch.isChecked()
-# ─── Individual Pages ──────────────────────────────────────────────
-
-
class PageHeader(QWidget):
def __init__(self, title: str, desc: str, parent=None):
@@ -290,70 +254,66 @@ class WelcomePage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
- layout = QVBoxLayout(self)
- layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
- layout.setSpacing(8)
+ self._initWidget()
+ self._initLayout()
+ self._bind()
- iconLabel = QLabel(self)
- iconLabel.setPixmap(QIcon(":/image/logo.png").pixmap(88, 88))
- iconLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ def _initWidget(self) -> None:
+ self.iconLabel = QLabel(self)
+ self.iconLabel.setPixmap(QIcon(":/image/logo.png").pixmap(88, 88))
+ self.iconLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- titleLabel = TitleLabel(self.tr("欢迎使用 Ghost Downloader"), self)
- titleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ self.titleLabel = TitleLabel(self.tr("欢迎使用 Ghost Downloader"), self)
+ self.titleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- subtitleLabel = BodyLabel(
+ self.subtitleLabel = BodyLabel(
self.tr("快速、智能的下载管理器。\n接下来的几步将帮助你完成基本配置。"), self
)
- subtitleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- subtitleLabel.setWordWrap(True)
+ self.subtitleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ self.subtitleLabel.setWordWrap(True)
- startButton = PrimaryPushButton(self.tr("开始配置"), self)
- startButton.setFixedWidth(200)
- startButton.clicked.connect(self.startClicked)
+ self.startButton = PrimaryPushButton(self.tr("开始配置"), self)
+ self.startButton.setFixedWidth(200)
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ layout.setSpacing(8)
layout.addStretch(3)
- layout.addWidget(iconLabel, 0, Qt.AlignmentFlag.AlignCenter)
+ layout.addWidget(self.iconLabel, 0, Qt.AlignmentFlag.AlignCenter)
layout.addSpacing(16)
- layout.addWidget(titleLabel)
- layout.addWidget(subtitleLabel)
+ layout.addWidget(self.titleLabel)
+ layout.addWidget(self.subtitleLabel)
layout.addSpacing(28)
- layout.addWidget(startButton, 0, Qt.AlignmentFlag.AlignCenter)
+ layout.addWidget(self.startButton, 0, Qt.AlignmentFlag.AlignCenter)
layout.addStretch(4)
+ def _bind(self) -> None:
+ self.startButton.clicked.connect(self.startClicked)
+
class BasicSettingsPage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
- layout = QVBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
+ self._initWidget()
+ self._initLayout()
+ self._bind()
- layout.addWidget(PageHeader(
+ def _initWidget(self) -> None:
+ self.header = PageHeader(
self.tr("基本设置"),
self.tr("选择你喜欢的外观,设置下载文件的保存位置"), self,
- ))
-
- layout.addStretch(1)
+ )
- # Theme cards
- themeRow = QHBoxLayout()
- themeRow.setSpacing(14)
self._themeCards: list[ThemeCard] = []
for theme, label in [(Theme.LIGHT, self.tr("浅色")),
(Theme.DARK, self.tr("深色")),
(Theme.AUTO, self.tr("跟随系统"))]:
- card = ThemeCard(theme, label, self)
- card.clicked.connect(lambda t=theme: self._onThemePicked(t))
- themeRow.addWidget(card)
- self._themeCards.append(card)
- self._syncThemeCards()
- layout.addLayout(themeRow)
+ self._themeCards.append(ThemeCard(theme, label, self))
+ self._refreshThemeCards()
- layout.addStretch(1)
-
- # Language + download folder
- settingsCard = GroupHeaderCardWidget(self.tr("偏好"), self)
+ self.settingsCard = GroupHeaderCardWidget(self.tr("偏好"), self)
self.langCombo = ComboBox(self)
self.langCombo.setMinimumWidth(200)
@@ -363,27 +323,45 @@ class BasicSettingsPage(QWidget):
else:
self.langCombo.addItem(lang.value.nativeLanguageName())
self.langCombo.setCurrentIndex(list(Language).index(cfg.language.value))
- self.langCombo.currentIndexChanged.connect(self._onLanguageChanged)
- settingsCard.addGroup(
+
+ self.browseButton = PushButton(self.tr("浏览..."), self)
+
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setContentsMargins(0, 0, 0, 0)
+ layout.setSpacing(0)
+ layout.addWidget(self.header)
+ layout.addStretch(1)
+
+ themeRow = QHBoxLayout()
+ themeRow.setSpacing(14)
+ for card in self._themeCards:
+ themeRow.addWidget(card)
+ layout.addLayout(themeRow)
+ layout.addStretch(1)
+
+ self.settingsCard.addGroup(
FluentIcon.LANGUAGE, self.tr("界面语言"),
self.tr("重启后生效"), self.langCombo,
)
-
- browseButton = PushButton(self.tr("浏览..."), self)
- browseButton.clicked.connect(self._onBrowseFolder)
- self._folderGroup = settingsCard.addGroup(
+ self._folderGroup = self.settingsCard.addGroup(
FluentIcon.FOLDER, self.tr("下载保存位置"),
- str(cfg.downloadFolder.value), browseButton,
+ str(cfg.downloadFolder.value), self.browseButton,
)
-
- layout.addWidget(settingsCard)
+ layout.addWidget(self.settingsCard)
layout.addStretch(1)
+ def _bind(self) -> None:
+ for card in self._themeCards:
+ card.clicked.connect(lambda t=card.theme: self._onThemePicked(t))
+ self.langCombo.currentIndexChanged.connect(self._onLanguageChanged)
+ self.browseButton.clicked.connect(self._onBrowseClicked)
+
def _onThemePicked(self, theme: Theme) -> None:
cfg.set(cfg.themeMode, theme)
- self._syncThemeCards()
+ self._refreshThemeCards()
- def _syncThemeCards(self) -> None:
+ def _refreshThemeCards(self) -> None:
current = cfg.themeMode.value
for card in self._themeCards:
card.setSelected(card.theme == current)
@@ -393,7 +371,7 @@ class BasicSettingsPage(QWidget):
if 0 <= index < len(languages):
cfg.set(cfg.language, languages[index])
- def _onBrowseFolder(self) -> None:
+ def _onBrowseClicked(self) -> None:
folder = QFileDialog.getExistingDirectory(
self, self.tr("选择下载目录"), str(cfg.downloadFolder.value)
)
@@ -408,85 +386,92 @@ class BrowserExtensionPage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self._isPaired = False
- layout = QVBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
+ self._banner: InfoBar | None = None
+ self._initWidget()
+ self._initLayout()
+ self._bind()
- layout.addWidget(PageHeader(
+ def _initWidget(self) -> None:
+ self.header = PageHeader(
self.tr("安装浏览器扩展"),
self.tr("让浏览器中的下载自动接管到 Ghost Downloader"), self,
- ))
+ )
+
+ self.previewLabel = QLabel(self)
+ self.previewLabel.setFixedSize(PREVIEW_SIZE)
+ self.previewLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ movie = QMovie(PREVIEW_GIF, parent=self)
+ if movie.isValid():
+ movie.setScaledSize(PREVIEW_SIZE)
+ self.previewLabel.setMovie(movie)
+ movie.start()
+ else:
+ self.previewLabel.setText(self.tr("安装教程动图"))
+ if isDarkTheme():
+ bg, fg = "rgba(255,255,255,0.06)", "rgba(255,255,255,0.5)"
+ else:
+ bg, fg = "rgba(0,0,0,0.04)", "rgba(0,0,0,0.4)"
+ self.previewLabel.setStyleSheet(
+ f"QLabel {{ background: {bg}; color: {fg}; border-radius: 8px; }}"
+ )
+
+ self.manualCard = ActionCard(
+ FluentIcon.DOWNLOAD, self.tr("手动安装"),
+ self.tr("随桌面端自动更新,适用于所有 Chromium 浏览器"),
+ isRecommended=True, parent=self,
+ )
+ self.storeCards: list[tuple[ActionCard, str]] = []
+ for title, url in [
+ (self.tr("Chrome 商店"), CHROME_WEBSTORE_URL),
+ (self.tr("Edge 商店"), EDGE_ADDONS_URL),
+ (self.tr("Firefox 商店"), FIREFOX_ADDONS_URL),
+ ]:
+ self.storeCards.append((ActionCard(FluentIcon.GLOBE, title, parent=self), url))
+ self.footnote = CaptionLabel(self.tr("商店版更新需等待审核,可能滞后于桌面端"), self)
+ self.footnote.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
+
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setContentsMargins(0, 0, 0, 0)
+ layout.setSpacing(0)
+ layout.addWidget(self.header)
layout.addStretch(1)
contentLayout = QHBoxLayout()
contentLayout.setSpacing(16)
- # Left: WebP tutorial + status banner
leftLayout = QVBoxLayout()
leftLayout.setSpacing(10)
- self.previewLabel = QLabel(self)
- self.previewLabel.setFixedSize(PREVIEW_SIZE)
- self.previewLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- self._initPreview()
leftLayout.addWidget(self.previewLabel)
-
- self._banner: InfoBar | None = None
self._bannerSlot = QVBoxLayout()
self._bannerSlot.setContentsMargins(0, 0, 0, 0)
leftLayout.addLayout(self._bannerSlot)
contentLayout.addLayout(leftLayout)
- # Right: install channels, manual install first (recommended)
rightWidget = QWidget(self)
rightWidget.setFixedWidth(STORE_COLUMN_WIDTH)
rightLayout = QVBoxLayout(rightWidget)
rightLayout.setContentsMargins(0, 0, 0, 0)
rightLayout.setSpacing(10)
rightLayout.addStretch(1)
-
- manualCard = ActionCard(
- FluentIcon.DOWNLOAD, self.tr("手动安装"),
- self.tr("随桌面端自动更新,适用于所有 Chromium 浏览器"),
- isRecommended=True, parent=self,
- )
- manualCard.clicked.connect(self._onManualInstall)
- rightLayout.addWidget(manualCard)
-
- for title, url in [
- (self.tr("Chrome 商店"), CHROME_WEBSTORE_URL),
- (self.tr("Edge 商店"), EDGE_ADDONS_URL),
- (self.tr("Firefox 商店"), FIREFOX_ADDONS_URL),
- ]:
- card = ActionCard(FluentIcon.GLOBE, title, parent=self)
- card.clicked.connect(lambda u=url: QDesktopServices.openUrl(QUrl(u)))
+ rightLayout.addWidget(self.manualCard)
+ for card, _ in self.storeCards:
rightLayout.addWidget(card)
-
- footnote = CaptionLabel(self.tr("商店版更新需等待审核,可能滞后于桌面端"), self)
- footnote.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
- rightLayout.addWidget(footnote)
+ rightLayout.addWidget(self.footnote)
rightLayout.addStretch(1)
-
contentLayout.addWidget(rightWidget)
+
layout.addLayout(contentLayout)
layout.addStretch(1)
- def _initPreview(self) -> None:
- movie = QMovie(PREVIEW_GIF, parent=self)
- if movie.isValid():
- movie.setScaledSize(PREVIEW_SIZE)
- self.previewLabel.setMovie(movie)
- movie.start()
- return
-
- self.previewLabel.setText(self.tr("安装教程动图"))
- if isDarkTheme():
- bg, fg = "rgba(255,255,255,0.06)", "rgba(255,255,255,0.5)"
- else:
- bg, fg = "rgba(0,0,0,0.04)", "rgba(0,0,0,0.4)"
- self.previewLabel.setStyleSheet(
- f"QLabel {{ background: {bg}; color: {fg}; border-radius: 8px; }}"
- )
+ def _bind(self) -> None:
+ from app.services.browser_service import browserService
+ self.manualCard.clicked.connect(self._onManualInstallClicked)
+ for card, url in self.storeCards:
+ card.clicked.connect(lambda u=url: QDesktopServices.openUrl(QUrl(u)))
+ browserService.connectionChanged.connect(self._onConnectionChanged)
+ browserService.protocolMismatched.connect(self._onProtocolMismatched)
def _setBanner(self, icon: InfoBarIcon, title: str) -> None:
if self._banner is not None:
@@ -509,6 +494,11 @@ class BrowserExtensionPage(QWidget):
InfoBarIcon.INFORMATION,
self.tr("正在端口 {} 上等待扩展连接").format(browserService.boundPort),
)
+ elif not cfg.isBrowserExtensionEnabled.value:
+ self._setBanner(
+ InfoBarIcon.WARNING,
+ self.tr("浏览器扩展未启用,可稍后在设置中开启"),
+ )
else:
self._setBanner(
InfoBarIcon.WARNING,
@@ -517,17 +507,31 @@ class BrowserExtensionPage(QWidget):
),
)
- def _onManualInstall(self) -> None:
+ def _onConnectionChanged(self) -> None:
+ from app.services.browser_service import browserService
+ installType, version = browserService.connectionSummary
+ if installType or version:
+ self._isPaired = True
+ if version:
+ text = self.tr("已连接扩展 v{}").format(version)
+ else:
+ text = self.tr("已连接扩展")
+ self._setBanner(InfoBarIcon.SUCCESS, text)
+ else:
+ self._isPaired = False
+ self.refreshPortStatus()
+
+ def _onManualInstallClicked(self) -> None:
from app.services.browser_service import extractBrowserExtension
from app.services.coroutine_runner import coroutineRunner
coroutineRunner.submit(
extractBrowserExtension(),
- done=self._onExtracted,
- failed=self._onExtractFailed,
+ done=self._onExtensionExtracted,
+ failed=self._onExtensionExtractFailed,
owner=self,
)
- def _onExtracted(self, path: Path) -> None:
+ def _onExtensionExtracted(self, path: Path) -> None:
from app.platform.desktop import openChromiumUrl, revealInFolder
revealInFolder(str(path))
if not openChromiumUrl("chrome://extensions"):
@@ -538,7 +542,7 @@ class BrowserExtensionPage(QWidget):
duration=5000, position=InfoBarPosition.TOP, parent=self,
)
- def _onExtractFailed(self, error) -> None:
+ def _onExtensionExtractFailed(self, error) -> None:
InfoBar.error(
self.tr("解包失败"), str(error),
duration=5000, position=InfoBarPosition.TOP, parent=self,
@@ -555,7 +559,7 @@ class BrowserExtensionPage(QWidget):
text = self.tr("配对成功")
self._setBanner(InfoBarIcon.SUCCESS, text)
- def onProtocolMismatch(self) -> None:
+ def _onProtocolMismatched(self) -> None:
self._setBanner(
InfoBarIcon.WARNING,
self.tr("协议版本不匹配,商店版可能滞后,请尝试手动安装"),
@@ -567,34 +571,36 @@ class RuntimeInstallPage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self._checkBoxes: list[tuple[CheckBox, BinaryRuntime]] = []
+ self._isMounted = False
+ self._initWidget()
+ self._initLayout()
- layout = QVBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
-
- layout.addWidget(PageHeader(
+ def _initWidget(self) -> None:
+ self.header = PageHeader(
self.tr("安装推荐组件"),
self.tr("点击下一步将自动安装勾选的组件,稍后可在设置中管理"), self,
- ))
+ )
+ self._card = GroupHeaderCardWidget(self.tr("推荐组件"), self)
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setContentsMargins(0, 0, 0, 0)
+ layout.setSpacing(0)
+ layout.addWidget(self.header)
layout.addStretch(1)
- self._card = GroupHeaderCardWidget(self.tr("推荐组件"), self)
layout.addWidget(self._card)
layout.addStretch(1)
- def populate(self) -> None:
- if self._checkBoxes:
+ def mount(self) -> None:
+ if self._isMounted:
return
+ self._isMounted = True
from app.services.feature_service import featureService
- entries = []
- for runtime in featureService.runtimes():
- profile = RUNTIME_PROFILES.get(type(runtime).__name__)
- if profile and runtime.canInstall:
- entries.append((runtime, profile))
- entries.sort(key=lambda x: x[1]["order"])
-
- for runtime, profile in entries:
+ entries = [rt for rt in featureService.runtimes() if rt.canInstall and rt.title]
+ entries.sort(key=lambda rt: not rt.isRecommended)
+
+ for runtime in entries:
trailing = QWidget(self)
trailingLayout = QHBoxLayout(trailing)
trailingLayout.setContentsMargins(0, 0, 0, 0)
@@ -602,18 +608,24 @@ class RuntimeInstallPage(QWidget):
tag = CaptionLabel(runtime.name, trailing)
tag.setTextColor(Qt.GlobalColor.gray, Qt.GlobalColor.gray)
-
- checkBox = CheckBox(trailing)
- checkBox.setChecked(profile["defaultChecked"])
-
trailingLayout.addWidget(tag)
- trailingLayout.addWidget(checkBox)
+
+ if runtime.path():
+ installedLabel = CaptionLabel(self.tr("已安装"), trailing)
+ installedLabel.setTextColor(Qt.GlobalColor.darkGreen, Qt.GlobalColor.green)
+ trailingLayout.addWidget(installedLabel)
+ else:
+ checkBox = CheckBox(trailing)
+ checkBox.setChecked(runtime.isRecommended)
+ trailingLayout.addWidget(checkBox)
+ self._checkBoxes.append((checkBox, runtime))
self._card.addGroup(
- profile["icon"], self.tr(profile["title"]),
- self.tr(profile["description"]), trailing,
+ runtime.icon,
+ QCoreApplication.translate("BinaryRuntime", runtime.title),
+ QCoreApplication.translate("BinaryRuntime", runtime.description),
+ trailing,
)
- self._checkBoxes.append((checkBox, runtime))
def selectedRuntimes(self) -> list[BinaryRuntime]:
return [rt for cb, rt in self._checkBoxes if cb.isChecked()]
@@ -623,39 +635,38 @@ class AdvancedOptionsPage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
- layout = QVBoxLayout(self)
- layout.setContentsMargins(0, 0, 0, 0)
- layout.setSpacing(0)
+ self._initWidget()
+ self._initLayout()
- layout.addWidget(PageHeader(
+ def _initWidget(self) -> None:
+ self.header = PageHeader(
self.tr("更多选项"),
self.tr("按需开启以下功能,也可以稍后在设置中修改"), self,
- ))
-
- layout.addStretch(1)
-
- listLayout = QVBoxLayout()
- listLayout.setSpacing(10)
-
+ )
+ self.categoryCard = OptionCard(
+ FluentIcon.TAG, self.tr("自动分类保存"),
+ self.tr("按文件类型自动保存到 视频、音频、文档 等子文件夹"),
+ isChecked=cfg.isCategoryEnabled.value, parent=self,
+ )
self.fileAssocCard = OptionCard(
FluentIcon.DOCUMENT, self.tr("关联文件类型"),
self.tr("双击 .torrent 等文件时自动用 Ghost Downloader 打开"),
- isChecked=False, parent=self,
+ isChecked=self._isFileAssociationEnabled(), parent=self,
)
self.urlSchemeCard = OptionCard(
FluentIcon.LINK, self.tr("注册 URL 协议"),
self.tr("允许网页通过 ghostdownloader:// 链接唤起本应用"),
- isChecked=False, parent=self,
+ isChecked=cfg.isUrlSchemeRegistered.value, parent=self,
)
self.aria2Card = OptionCard(
FluentIcon.COMMAND_PROMPT, self.tr("Aria2 RPC 兼容"),
self.tr("让支持 Aria2 的工具和网站把下载任务发给 Ghost Downloader"),
- isChecked=False, parent=self,
+ isChecked=cfg.isAria2RpcEnabled.value, parent=self,
)
self.runAtLoginCard = OptionCard(
FluentIcon.POWER_BUTTON, self.tr("开机自启"),
self.tr("登录系统时自动在后台启动,随时接管下载"),
- isChecked=False, parent=self,
+ isChecked=cfg.shouldRunAtLogin.value, parent=self,
)
self.clipboardCard = OptionCard(
FluentIcon.PASTE, self.tr("剪贴板监听"),
@@ -663,30 +674,53 @@ class AdvancedOptionsPage(QWidget):
isChecked=cfg.isClipboardListenerEnabled.value, parent=self,
)
- for card in [self.fileAssocCard, self.urlSchemeCard, self.aria2Card,
- self.runAtLoginCard, self.clipboardCard]:
- listLayout.addWidget(card)
+ def _isFileAssociationEnabled(self) -> bool:
+ from app.services.feature_service import featureService
+ return any(
+ pack.config.associateFileTypes.value
+ for pack in featureService.packs
+ if pack.config is not None and hasattr(pack.config, "associateFileTypes")
+ )
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setContentsMargins(0, 0, 0, 0)
+ layout.setSpacing(0)
+ layout.addWidget(self.header)
+ layout.addStretch(1)
+
+ listLayout = QVBoxLayout()
+ listLayout.setSpacing(8)
+ for card in [self.categoryCard, self.fileAssocCard, self.urlSchemeCard,
+ self.aria2Card, self.runAtLoginCard, self.clipboardCard]:
+ listLayout.addWidget(card)
layout.addLayout(listLayout)
layout.addStretch(1)
- def applySettings(self) -> None:
- if self.fileAssocCard.isChecked():
- from app.services.feature_service import featureService
- for pack in featureService.packs:
- config = pack.config
- if config is not None and hasattr(config, "associateFileTypes"):
- cfg.set(config.associateFileTypes, True)
- if self.urlSchemeCard.isChecked():
- cfg.set(cfg.isUrlSchemeRegistered, True)
- from app.platform.url_scheme import registerUrlScheme
- registerUrlScheme()
- if self.aria2Card.isChecked():
- cfg.set(cfg.isAria2RpcEnabled, True)
- if self.runAtLoginCard.isChecked():
- cfg.set(cfg.shouldRunAtLogin, True)
+ def save(self) -> None:
+ cfg.set(cfg.isCategoryEnabled, self.categoryCard.isChecked())
+
+ from app.services.feature_service import featureService
+ for pack in featureService.packs:
+ config = pack.config
+ if config is not None and hasattr(config, "associateFileTypes"):
+ cfg.set(config.associateFileTypes, self.fileAssocCard.isChecked())
+
+ if self.urlSchemeCard.isChecked() != cfg.isUrlSchemeRegistered.value:
+ from app.platform.url_scheme import registerUrlScheme, unregisterUrlScheme
+ if self.urlSchemeCard.isChecked():
+ registerUrlScheme()
+ else:
+ unregisterUrlScheme()
+ cfg.set(cfg.isUrlSchemeRegistered, self.urlSchemeCard.isChecked())
+
+ cfg.set(cfg.isAria2RpcEnabled, self.aria2Card.isChecked())
+
+ if self.runAtLoginCard.isChecked() != cfg.shouldRunAtLogin.value:
from app.platform.run_at_login import setRunAtLogin
- setRunAtLogin(True)
+ setRunAtLogin(self.runAtLoginCard.isChecked())
+ cfg.set(cfg.shouldRunAtLogin, self.runAtLoginCard.isChecked())
+
cfg.set(cfg.isClipboardListenerEnabled, self.clipboardCard.isChecked())
@@ -696,41 +730,41 @@ class CompletePage(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
- layout = QVBoxLayout(self)
- layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
- layout.setSpacing(8)
+ self._initWidget()
+ self._initLayout()
+ self._bind()
- checkIcon = IconChip(
- FluentIcon.ACCEPT,
- ("#E8F5E9", "#0F7B46", "#1A3A1A", "#4ADE80"),
- size=80, parent=self,
- )
+ def _initWidget(self) -> None:
+ self.checkIcon = IconChip(FluentIcon.ACCEPT, SUCCESS_CHIP_COLORS, size=80, parent=self)
- titleLabel = TitleLabel(self.tr("一切就绪"), self)
- titleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ self.titleLabel = TitleLabel(self.tr("一切就绪"), self)
+ self.titleLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- descLabel = BodyLabel(
+ self.descLabel = BodyLabel(
self.tr("Ghost Downloader 已准备好为你工作。\n你可以随时在设置中调整所有选项。"),
self,
)
- descLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
- descLabel.setWordWrap(True)
+ self.descLabel.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ self.descLabel.setWordWrap(True)
- finishButton = PrimaryPushButton(self.tr("开始使用"), self)
- finishButton.setFixedWidth(200)
- finishButton.clicked.connect(self.finishClicked)
+ self.finishButton = PrimaryPushButton(self.tr("开始使用"), self)
+ self.finishButton.setFixedWidth(200)
+ def _initLayout(self) -> None:
+ layout = QVBoxLayout(self)
+ layout.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ layout.setSpacing(8)
layout.addStretch(3)
- layout.addWidget(checkIcon, 0, Qt.AlignmentFlag.AlignCenter)
+ layout.addWidget(self.checkIcon, 0, Qt.AlignmentFlag.AlignCenter)
layout.addSpacing(16)
- layout.addWidget(titleLabel)
- layout.addWidget(descLabel)
+ layout.addWidget(self.titleLabel)
+ layout.addWidget(self.descLabel)
layout.addSpacing(28)
- layout.addWidget(finishButton, 0, Qt.AlignmentFlag.AlignCenter)
+ layout.addWidget(self.finishButton, 0, Qt.AlignmentFlag.AlignCenter)
layout.addStretch(4)
-
-# ─── OOBE Window ────────────────────────────────────────────────────
+ def _bind(self) -> None:
+ self.finishButton.clicked.connect(self.finishClicked)
class OobeWindow(FluentWidget):
@@ -741,15 +775,25 @@ class OobeWindow(FluentWidget):
def __init__(self, parent=None):
super().__init__(parent=parent)
+ self._currentIndex = 0
+ self._isFinished = False
+ self._queuedRuntimeIds: set[str] = set()
+ self._initWidget()
+ self._initLayout()
+ self._bind()
+ self._refreshNavigation()
+
+ def _initWidget(self) -> None:
from qfluentwidgets import MSFluentTitleBar
self.setTitleBar(MSFluentTitleBar(self))
self.setWindowTitle("Ghost Downloader")
self.setWindowIcon(QIcon(":/image/logo.png"))
+ self.titleBar.hBoxLayout.insertSpacing(2, 6)
+ self.titleBar.maxBtn.hide()
+ self.setFixedSize(WINDOW_SIZE)
+ desktop = QApplication.primaryScreen().availableGeometry()
+ self.move(desktop.center() - self.rect().center())
- self._currentIndex = 0
- self._isFinished = False
-
- # Pages
self.welcomePage = WelcomePage(self)
self.basicSettingsPage = BasicSettingsPage(self)
self.browserExtensionPage = BrowserExtensionPage(self)
@@ -765,7 +809,6 @@ class OobeWindow(FluentWidget):
self.stackedWidget.addWidget(self.advancedOptionsPage)
self.stackedWidget.addWidget(self.completePage)
- # Bottom bar
self.backButton = PushButton(self.tr("上一步"), self)
self.skipButton = TransparentPushButton(self.tr("跳过全部"), self)
self.nextButton = PrimaryPushButton(self.tr("下一步"), self)
@@ -776,23 +819,10 @@ class OobeWindow(FluentWidget):
self.pipsPager.setNextButtonDisplayMode(PipsScrollButtonDisplayMode.NEVER)
self.pipsPager.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
- self._initWindow()
- self._initLayout()
- self._bind()
- self._syncNavigation()
-
- def _initWindow(self) -> None:
- self.titleBar.hBoxLayout.insertSpacing(2, 6)
- self.titleBar.maxBtn.hide()
- self.setFixedSize(WINDOW_SIZE)
- desktop = QApplication.primaryScreen().availableGeometry()
- self.move(desktop.center() - self.rect().center())
-
def _initLayout(self) -> None:
mainLayout = QVBoxLayout(self)
mainLayout.setContentsMargins(36, self.titleBar.height() + 8, 36, 16)
mainLayout.setSpacing(0)
-
mainLayout.addWidget(self.stackedWidget, 1)
navLayout = QHBoxLayout()
@@ -813,13 +843,13 @@ class OobeWindow(FluentWidget):
mainLayout.addLayout(navLayout)
def _bind(self) -> None:
- self.welcomePage.startClicked.connect(self._goNext)
+ self.welcomePage.startClicked.connect(self._onNextClicked)
self.completePage.finishClicked.connect(self._finish)
- self.backButton.clicked.connect(self._goBack)
- self.nextButton.clicked.connect(self._goNext)
+ self.backButton.clicked.connect(self._onBackClicked)
+ self.nextButton.clicked.connect(self._onNextClicked)
self.skipButton.clicked.connect(self._finish)
- def _syncNavigation(self) -> None:
+ def _refreshNavigation(self) -> None:
i = self._currentIndex
isFirst = i == 0
isLast = i == self.PAGE_COUNT - 1
@@ -829,32 +859,29 @@ class OobeWindow(FluentWidget):
self.skipButton.setVisible(isFirst)
self.pipsPager.setCurrentIndex(i)
- def _goNext(self) -> None:
+ def _onNextClicked(self) -> None:
if self._currentIndex >= self.PAGE_COUNT - 1:
return
if self._currentIndex == 3:
self._installSelectedRuntimes()
if self._currentIndex == 4:
- self.advancedOptionsPage.applySettings()
+ self.advancedOptionsPage.save()
self._currentIndex += 1
self.stackedWidget.setCurrentIndex(self._currentIndex)
- self._syncNavigation()
- self._onPageEntered(self._currentIndex)
+ self._refreshNavigation()
+ if self._currentIndex == 2:
+ self.browserExtensionPage.refreshPortStatus()
+ elif self._currentIndex == 3:
+ self.runtimeInstallPage.mount()
- def _goBack(self) -> None:
+ def _onBackClicked(self) -> None:
if self._currentIndex <= 0:
return
self._currentIndex -= 1
self.stackedWidget.setCurrentIndex(self._currentIndex, isBack=True)
- self._syncNavigation()
-
- def _onPageEntered(self, index: int) -> None:
- if index == 2:
- self.browserExtensionPage.refreshPortStatus()
- elif index == 3:
- self.runtimeInstallPage.populate()
+ self._refreshNavigation()
def _installSelectedRuntimes(self) -> None:
runtimes = self.runtimeInstallPage.selectedRuntimes()
@@ -872,8 +899,9 @@ class OobeWindow(FluentWidget):
logger.error("OOBE 安装 {} 失败: {}", name, error)
for runtime in runtimes:
- if runtime.path():
+ if runtime.path() or runtime.runtimeId in self._queuedRuntimeIds:
continue
+ self._queuedRuntimeIds.add(runtime.runtimeId)
coroutineRunner.submit(
runtime.installTask(),
done=onDone,
diff --git a/features/ed2k_pack/config.py b/features/ed2k_pack/config.py
index 674800b4..f4ca96f4 100644
--- a/features/ed2k_pack/config.py
+++ b/features/ed2k_pack/config.py
@@ -4,14 +4,13 @@ import platform
import sys
from pathlib import Path
-from app.config.cfg import cfg
from app.config.paths import APP_DATA_DIR
from app.models.pack import BinaryRuntime, PackConfig
from app.platform.filesystem import findExecutable, toPosixPath
-from qfluentwidgets import ConfigItem, BoolValidator, RangeConfigItem, RangeValidator
+from PySide6.QtCore import QT_TRANSLATE_NOOP as N
+from qfluentwidgets import ConfigItem, BoolValidator, FluentIcon, RangeConfigItem, RangeValidator
-RELEASE_API = "https://api.github.com/repos/XiaoYouChR/Python-eD2k/releases/latest"
-RELEASE_HEADERS = {"accept": "application/vnd.github+json"}
+RELEASE_BASE = "https://github.com/XiaoYouChR/Python-eD2k/releases/latest/download"
class ED2kConfig(PackConfig):
@@ -65,53 +64,42 @@ ed2kConfig = ED2kConfig()
class ED2kRuntime(BinaryRuntime):
name = "goed2kd"
canInstall = True
+ title = N("BinaryRuntime", "eD2k / eMule")
+ description = N("BinaryRuntime", "支持电驴协议,适合下载经典资源")
+ icon = FluentIcon.BOOK_SHELF
+ isRecommended = False
def path(self) -> str:
return findExecutable(Path(ed2kConfig.installFolder.value), "goed2kd")
async def installTask(self):
- from app.client import buildClient
- from app.update import Release
- from http_pack.task import HttpTaskStep
+ from app.models.task import TaskOptions
+ from app.services.feature_service import featureService
from disk_pack.task import InstallTask
from .task import ED2kInstallStep
- client = buildClient(headers=RELEASE_HEADERS)
- try:
- response = await client.get(RELEASE_API)
- response.raise_for_status()
- release = Release.fromResponse(await response.json())
- finally:
- client.close()
-
assetName = _assetName()
- asset = next((a for a in release.assets if a.name == assetName), None)
- if asset is None:
- raise RuntimeError(f"未找到适配当前平台的 goed2kd: {assetName}")
- if not asset.downloadUrl or asset.size <= 0:
- raise RuntimeError("GitHub Release 返回了不完整的安装包信息")
-
+ url = f"{RELEASE_BASE}/{assetName}"
installFolder = Path(ed2kConfig.installFolder.value)
binaryName = "goed2kd.exe" if sys.platform == "win32" else "goed2kd"
binaryPath = toPosixPath(installFolder / binaryName)
+ download = await featureService.parse(
+ TaskOptions(url=url, outputFolder=installFolder)
+ )
+ downloadStep = download.steps[0]
+ downloadStep.stepIndex = 1
+ downloadStep.outputFile = binaryPath
+
task = InstallTask(
name=f"goed2kd 安装 ({assetName})",
- url=asset.downloadUrl,
+ url=url,
packId="ed2k",
- fileSize=asset.size,
+ fileSize=download.fileSize,
outputFolder=installFolder,
installFolder=str(installFolder),
)
- task.addStep(HttpTaskStep(
- stepIndex=1,
- url=asset.downloadUrl,
- fileSize=asset.size,
- headers=dict(cfg.defaultRequestHeaders.value),
- subworkerCount=cfg.preBlockNum.value,
- canUseRangeRequests=True,
- outputFile=binaryPath,
- ))
+ task.addStep(downloadStep)
task.addStep(ED2kInstallStep(stepIndex=2, binaryPath=binaryPath))
return task
diff --git a/features/ffmpeg_pack/config.py b/features/ffmpeg_pack/config.py
index 9508e18d..8f9c3fa8 100644
--- a/features/ffmpeg_pack/config.py
+++ b/features/ffmpeg_pack/config.py
@@ -5,6 +5,9 @@ import platform
import sys
from pathlib import Path
+from PySide6.QtCore import QT_TRANSLATE_NOOP as N
+from qfluentwidgets import FluentIcon
+
from app.config.cfg import ConfigItem
from app.config.paths import APP_DATA_DIR
from app.models.pack import BinaryRuntime, PackConfig
@@ -55,6 +58,10 @@ ffmpegConfig = FFmpegConfig()
class FFmpegRuntime(BinaryRuntime):
name = "FFmpeg"
canInstall = not IS_ANDROID
+ title = N("BinaryRuntime", "视频合并")
+ description = N("BinaryRuntime", "哔哩哔哩、YouTube 等网站视频下载必备,合并音视频轨道为完整文件")
+ icon = FluentIcon.VIDEO
+ isRecommended = True
def path(self) -> str:
if IS_ANDROID:
diff --git a/features/m3u8_pack/config.py b/features/m3u8_pack/config.py
index 3b3a9c25..8c6abc0e 100644
--- a/features/m3u8_pack/config.py
+++ b/features/m3u8_pack/config.py
@@ -4,9 +4,11 @@ import platform
import sys
from pathlib import Path
+from PySide6.QtCore import QT_TRANSLATE_NOOP as N
from qfluentwidgets import (
BoolValidator,
ConfigItem,
+ FluentIcon,
FolderValidator,
OptionsConfigItem,
OptionsValidator,
@@ -14,15 +16,15 @@ from qfluentwidgets import (
RangeValidator,
)
-from app.client import buildClient
from app.config.paths import APP_DATA_DIR
from app.models.pack import BinaryRuntime, PackConfig
from app.models.task import Task
from app.platform.android import IS_ANDROID, nativeLibraryDir
from app.platform.filesystem import findExecutable
-RELEASE_TAG = "v0.5.1-beta"
-RELEASE_API = f"https://api.github.com/repos/nilaoda/N_m3u8DL-RE/releases/tags/{RELEASE_TAG}"
+RELEASE_TAG = "v0.6.0-beta"
+RELEASE_DATE = "20260629"
+RELEASE_BASE = f"https://github.com/nilaoda/N_m3u8DL-RE/releases/download/{RELEASE_TAG}"
class M3U8Config(PackConfig):
@@ -149,6 +151,10 @@ m3u8Config = M3U8Config()
class M3U8Runtime(BinaryRuntime):
name = "N_m3u8DL-RE"
canInstall = not IS_ANDROID
+ title = N("BinaryRuntime", "M3U8 / 直播下载")
+ description = N("BinaryRuntime", "支持 HLS、DASH 等流媒体协议,可录制直播流")
+ icon = FluentIcon.MEDIA
+ isRecommended = True
def path(self) -> str:
if IS_ANDROID:
@@ -171,42 +177,18 @@ class M3U8Runtime(BinaryRuntime):
elif sys.platform == "darwin":
target = "osx-arm64" if machine in {"arm64", "aarch64"} else "osx-x64"
elif sys.platform == "linux":
- libcName = platform.libc_ver()[0].lower()
- if machine in {"arm64", "aarch64"}:
- target = "linux-musl-arm64" if libcName == "musl" else "linux-arm64"
- else:
- target = "linux-musl-x64" if libcName == "musl" else "linux-x64"
+ target = "linux-arm64" if machine in {"arm64", "aarch64"} else "linux-x64"
else:
raise RuntimeError(f"当前平台暂不支持一键安装 N_m3u8DL-RE: {sys.platform}")
- client = buildClient(headers={"accept": "application/vnd.github+json"})
- try:
- response = await client.get(RELEASE_API)
- response.raise_for_status()
- release = await response.json()
- finally:
- client.close()
-
- assets = release.get("assets")
- if not isinstance(assets, list):
- raise RuntimeError("GitHub Release 返回了无效的 assets 数据")
-
- asset = next((item for item in assets if target in item["name"]), None)
- if asset is None:
- raise RuntimeError(f"未找到适用于当前平台的 N_m3u8DL-RE 安装包: {target}")
-
- url = asset["browser_download_url"].strip()
- fileName = asset["name"].strip()
- fileSize = asset["size"]
- if not url or not fileName or fileSize <= 0:
- raise RuntimeError("GitHub Release 返回了不完整的安装包信息")
-
from app.services.feature_service import featureService
from app.models.task import BinaryInstallOptions
+ extension = "zip" if sys.platform == "win32" else "tar.gz"
+ assetName = f"N_m3u8DL-RE_{RELEASE_TAG}_{target}_{RELEASE_DATE}.{extension}"
binaryName = "N_m3u8DL-RE.exe" if sys.platform == "win32" else "N_m3u8DL-RE"
return await featureService.parse(BinaryInstallOptions(
- url=url,
+ url=f"{RELEASE_BASE}/{assetName}",
outputFolder=Path(m3u8Config.installFolder.value),
name=f"N_m3u8DL-RE 安装 ({target})",
executableNames=(binaryName,),
diff --git a/features/yt_dlp_pack/config.py b/features/yt_dlp_pack/config.py
index 1ae547a6..d75d1f0f 100644
--- a/features/yt_dlp_pack/config.py
+++ b/features/yt_dlp_pack/config.py
@@ -5,8 +5,9 @@ import platform
import sys
from pathlib import Path
+from PySide6.QtCore import QT_TRANSLATE_NOOP as N
from PySide6.QtWidgets import QWidget
-from qfluentwidgets import BoolValidator, ConfigItem, FolderValidator, OptionsConfigItem, OptionsValidator
+from qfluentwidgets import BoolValidator, ConfigItem, FluentIcon, FolderValidator, OptionsConfigItem, OptionsValidator
from app.config.paths import APP_DATA_DIR
from app.models.pack import BinaryRuntime, PackConfig
@@ -14,8 +15,7 @@ from app.platform.android import IS_ANDROID
from app.platform.filesystem import findExecutable
PYPI_API = "https://pypi.org/pypi/yt-dlp/json"
-QJS_RELEASE_API = "https://api.github.com/repos/quickjs-ng/quickjs/releases/latest"
-QJS_RELEASE_HEADERS = {"accept": "application/vnd.github+json"}
+QJS_RELEASE_BASE = "https://github.com/quickjs-ng/quickjs/releases/latest/download"
class YtDlpConfig(PackConfig):
@@ -92,6 +92,10 @@ ytDlpConfig = YtDlpConfig()
class YouTubeRuntime(BinaryRuntime):
name = "YouTube 运行环境"
canInstall = True
+ title = N("BinaryRuntime", "YouTube 下载")
+ description = N("BinaryRuntime", "支持 YouTube、Twitter 等数百个视频网站")
+ icon = FluentIcon.GLOBE
+ isRecommended = True
def path(self) -> str:
folder = Path(ytDlpConfig.installFolder.value)
@@ -186,15 +190,23 @@ class YouTubeRuntime(BinaryRuntime):
return task
from disk_pack.task import BinaryInstallStep
+ from app.models.task import TaskOptions
+ from app.services.feature_service import featureService
- qjsUrl, qjsSize, qjsAssetName = await self._fetchQjsAsset()
qjsBinaryName = "qjs.exe" if sys.platform == "win32" else "qjs"
+ qjsDownload = await featureService.parse(TaskOptions(
+ url=f"{QJS_RELEASE_BASE}/{_qjsAssetName()}",
+ outputFolder=installFolder,
+ ))
+ qjsStep = qjsDownload.steps[0]
+ qjsStep.stepIndex = 2
+ qjsStep.outputFile = str(installFolder / qjsBinaryName)
task = InstallTask(
name="YouTube 运行环境安装",
url=whlUrl,
packId="disk",
- fileSize=whlSize + qjsSize,
+ fileSize=whlSize + max(0, qjsDownload.fileSize),
outputFolder=installFolder,
installFolder=str(installFolder),
)
@@ -207,15 +219,7 @@ class YouTubeRuntime(BinaryRuntime):
canUseRangeRequests=True,
outputFile=str(installFolder / archiveName),
))
- task.addStep(HttpTaskStep(
- stepIndex=2,
- url=qjsUrl,
- fileSize=qjsSize,
- headers=dict(cfg.defaultRequestHeaders.value),
- subworkerCount=cfg.preBlockNum.value,
- canUseRangeRequests=True,
- outputFile=str(installFolder / qjsBinaryName),
- ))
+ task.addStep(qjsStep)
task.addStep(ExtractStep(
stepIndex=3,
archivePath=str(installFolder / archiveName),
@@ -245,24 +249,6 @@ class YouTubeRuntime(BinaryRuntime):
return entry["url"], entry.get("size") or 0
raise RuntimeError("未找到 yt-dlp wheel 安装包")
- async def _fetchQjsAsset(self) -> tuple[str, int, str]:
- from app.client import buildClient
-
- client = buildClient(timeout=15, headers=QJS_RELEASE_HEADERS)
- try:
- response = await client.get(QJS_RELEASE_API)
- response.raise_for_status()
- release = await response.json()
- finally:
- client.close()
-
- assetName = _qjsAssetName()
- for asset in release.get("assets") or []:
- if asset.get("name") == assetName:
- return asset["browser_download_url"], asset.get("size") or 0, assetName
- raise RuntimeError(f"未找到适配当前平台的 qjs: {assetName}")
-
-
def _qjsAssetName() -> str:
machine = platform.machine().lower()
if sys.platform == "win32":