feat: 仅传输期间显示通知——空闲不发常驻通知,任务结束移除进度通知

This commit is contained in:
cbb
2026-10-12 02:24:00 +08:00
parent 2e745e0ecd
commit 8eb25c9de5
4 changed files with 13 additions and 14 deletions
+2 -2
View File
@@ -13,8 +13,8 @@ android {
applicationId = "com.smbfast.app"
minSdk = 26
targetSdk = 35
versionCode = 28
versionName = "1.22.1"
versionCode = 29
versionName = "1.23.0"
}
signingConfigs {
+2 -8
View File
@@ -2,8 +2,6 @@ package com.smbfast.app
import android.app.Application
import com.smbfast.app.smb.SmbClientPool
import com.smbfast.app.transfer.Notifier
import com.smbfast.app.transfer.Status
import com.smbfast.app.transfer.TransferManager
import com.smbfast.app.util.CrashLog
import org.bouncycastle.jce.provider.BouncyCastleProvider
@@ -23,12 +21,8 @@ class App : Application() {
Security.addProvider(BouncyCastleProvider())
}
}
// 常驻"就绪"通知(含灵动岛自检):普通通知直发,不启动前台服务——
// 避免在 FGS 被系统限制(dataSync 配额/侧载策略)时整条链路静默失效
runCatching {
val running = transferManager.items.value.filter { it.status == Status.RUNNING }
Notifier.notifyState(this, running)
}
// 通知策略:仅在下载/上传进行期间显示进度通知(TransferManager 直发),
// 空闲时不挂常驻通知
}
override fun onTerminate() {
@@ -55,14 +55,19 @@ object Notifier {
runCatching { NotificationManagerCompat.from(ctx).notify(NOTIF_ID, n) }
}
/** 按当前任务状态立即重发一条通知(设置切换岛开关/模式后调用) */
/** 按当前任务状态发通知;无传输任务时改为清除通知(仅在传输期间显示) */
fun refresh(ctx: Context) {
val running = runCatching {
(ctx.applicationContext as? com.smbfast.app.App)
?.transferManager?.items?.value
?.filter { it.status == Status.RUNNING }
}.getOrNull() ?: emptyList()
notifyState(ctx, running)
if (running.isEmpty()) cancelProgress(ctx) else notifyState(ctx, running)
}
/** 传输全部结束:移除进度通知(空闲不显示常驻通知) */
fun cancelProgress(ctx: Context) {
runCatching { NotificationManagerCompat.from(ctx).cancel(NOTIF_ID) }
}
/** 发一条独立 id 的测试通知,验证通道可见性。返回是否成功 */
@@ -79,10 +79,10 @@ class TransferManager(private val appContext: Context) {
.onFailure { com.smbfast.app.util.CrashLog.append("notify", it) }
}
} else if (hadRunning) {
// 全部结束:恢复"就绪"常驻态
// 全部结束:直接移除通知(空闲不显示常驻通知)
hadRunning = false
lastNotify = 0
runCatching { Notifier.notifyState(appContext, emptyList()) }
runCatching { Notifier.cancelProgress(appContext) }
}
}
}