The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(android): 下载完成本地通知
XiaoYouChReb800e97698e
diff --git a/android/build_apk.sh b/android/build_apk.shindex d94a577e..179e91dd 100644--- a/android/build_apk.sh+++ b/android/build_apk.sh@@ -32,7 +32,7 @@ touch "$BUILD_MARKER"# jh2 有 recipe 交叉编译、gd3ffmpeg 走预置 jniLibs; 跳过 orjson(stdlib shim 兜)/desktop-notifier/uvloop 等。# deploy patch 把 GD3_EXTRA_REQ 追加到 requirements、GD3_EXTRA_PERM 到 permissions。export GD3_EXTRA_REQ="${GD3_EXTRA_REQ:-,pyjnius,niquests,urllib3-future,charset-normalizer,idna,h11,wassima,jh2,PySide6-Fluent-Widgets,PySideSix-Frameless-Window,darkdetect,loguru,qrcode,pypng,m3u8,mpegdash,aioftp,gd3ffmpeg}"-export GD3_EXTRA_PERM="${GD3_EXTRA_PERM:-,MANAGE_EXTERNAL_STORAGE,FOREGROUND_SERVICE,FOREGROUND_SERVICE_DATA_SYNC,REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}"+export GD3_EXTRA_PERM="${GD3_EXTRA_PERM:-,MANAGE_EXTERNAL_STORAGE,POST_NOTIFICATIONS,FOREGROUND_SERVICE,FOREGROUND_SERVICE_DATA_SYNC,REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}"# 启动器图标改指仓库 logo.png(deploy 默认 PySide6 python logo)export GD3_ICON="${GD3_ICON:-$REPO/app/assets/logo.png}"# adaptive icon(消 API26+ 白边)+ presplash(冷启动图), 资源由 make_launch_assets.py 从 logo.png 派生diff --git a/android/main.py b/android/main.pyindex 5ff99ed7..4fe8e399 100644--- a/android/main.py+++ b/android/main.py@@ -118,6 +118,7 @@ application.installTranslator(translator)coreService.start()from app.supports.android_keepalive import keepAlive, requestIgnoreBatteryOptimizations+from app.supports.android_notification import requestNotificationPermissionmainWindow = MobileMainWindow()featureService.load(mainWindow)@@ -127,6 +128,7 @@ mainWindow.updateThemeColor()mainWindow.show()setupTouchScrolling(mainWindow)+requestNotificationPermission() # Android 13+ 运行时弹 POST_NOTIFICATIONS, 否则通知被静默丢弃requestIgnoreBatteryOptimizations() # 跳电池优化豁免, 逃 Doze 后台限制(已豁免则静默)# 浏览器扩展服务开启即须保活(随时接受扩展连接), 与下载各占一个保活理由, 引用计数互不踩cfg.enableBrowserExtension.valueChanged.connect(lambda enabled: keepAlive.setReason("browser", bool(enabled)))diff --git a/app/supports/android_notification.py b/app/supports/android_notification.pyindex e8c3f54b..85ccdc42 100644--- a/app/supports/android_notification.py+++ b/app/supports/android_notification.py@@ -1,5 +1,7 @@"""Android 本地通知 —— NotificationManager 投递, 完成 toast 与常驻通知共用 postNotification。须主线程调。"""+_CHANNEL = "gd3_downloads"+def _reopenAppIntent(activity):from jnius import autoclass@@ -42,3 +44,20 @@ def postNotification(channelId: str, channelName: str, notifId: int, title: str,builder.setOnlyAlertOnce(True) # 每秒刷, 只首次提醒builder.setContentIntent(_reopenAppIntent(activity))manager.notify(notifId, builder.build()) # 同 notifId 再投即更新+++def notifyDownloadComplete(notifyKey: str, title: str, text: str) -> None:+ postNotification(_CHANNEL, "下载", hash(notifyKey) & 0x7FFFFFFF, title, text,+ ongoing=False, lowImportance=False)+++def requestNotificationPermission() -> None:+ from jnius import autoclass++ if autoclass("android.os.Build$VERSION").SDK_INT < 33: # POST_NOTIFICATIONS 仅 13+ 需运行时授权+ return+ PackageManager = autoclass("android.content.pm.PackageManager")+ activity = autoclass("org.kivy.android.PythonActivity").mActivity+ permission = "android.permission.POST_NOTIFICATIONS"+ if activity.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED:+ activity.requestPermissions([permission], 0)diff --git a/app/view/mobile/task_page.py b/app/view/mobile/task_page.pyindex 2c1ad088..05377e42 100644--- a/app/view/mobile/task_page.py+++ b/app/view/mobile/task_page.py@@ -6,6 +6,7 @@ from qfluentwidgets import FluentIcon, PrimaryToolButton, ToolButtonfrom app.bases.models import Taskfrom app.services.feature_service import featureService+from app.supports.android_notification import notifyDownloadCompletefrom app.view.components.cards import TaskCardfrom app.view.mobile.cards import MobileCardMixin, MobileFtpMixinfrom app.view.pages.task_page import TaskPage@@ -95,6 +96,12 @@ class MobileTaskPage(TaskPage):self._cardClassCache[taskType] = mobileClassreturn mobileClass+ def _onCardFinished(self):+ super()._onCardFinished() # 基类: 桌面通知(Android 静默)+ 筛选/计划刷新+ sender = self.sender()+ if isinstance(sender, TaskCard):+ notifyDownloadComplete(sender.task.taskId, self.tr("下载完成"), sender.task.title)+def _mountCard(self, task: Task) -> TaskCard:card = self._mobileCardClass(task)(task, self.container)card.finished.connect(self._onCardFinished)