feat: add notification-access setting item with jump
This commit is contained in:
@@ -10,6 +10,15 @@ import top.yeij.hearth.webapp.WebApp
|
||||
import top.yeij.hearth.webapp.WebAppContainer
|
||||
import top.yeij.hearth.webapp.WebAppRepository
|
||||
|
||||
// 通知使用权访问接口:由 MainActivity 实现,JsBridge 通过它检查/申请授权,
|
||||
// 保持 JsBridge 可 JVM 单测(不直接依赖 Context/NotificationManagerCompat)
|
||||
// Notification-access provider implemented by MainActivity; JsBridge uses it to
|
||||
// check/request access, keeping JsBridge JVM-testable (no direct Context dependency)
|
||||
interface NotificationAccessProvider {
|
||||
fun isGranted(): Boolean
|
||||
fun requestAccess()
|
||||
}
|
||||
|
||||
class JsBridge(
|
||||
private val deviceWidthPx: Int,
|
||||
private val deviceHeightPx: Int,
|
||||
@@ -23,6 +32,9 @@ class JsBridge(
|
||||
// 主线程执行器:View 操作必须切到主线程;null(单测)时同步执行
|
||||
// Main-thread executor: view ops must run on main; null (unit tests) runs inline
|
||||
private val postToMainThread: ((() -> Unit) -> Unit)? = null,
|
||||
// 通知使用权访问接口(检查/申请授权),供设置页授权项使用
|
||||
// Notification-access provider (check/request) for the settings permission item
|
||||
private val notificationAccess: NotificationAccessProvider? = null,
|
||||
) {
|
||||
private val gson = com.google.gson.Gson()
|
||||
|
||||
@@ -185,6 +197,19 @@ class JsBridge(
|
||||
return gson.toJson(cards)
|
||||
}
|
||||
|
||||
// 返回通知使用权是否已授权(未接入返回 false)
|
||||
// Return whether notification access is granted (false when not wired)
|
||||
@android.webkit.JavascriptInterface
|
||||
fun getNotificationAccess(): Boolean = notificationAccess?.isGranted() ?: false
|
||||
|
||||
// 跳转系统「通知使用权」设置页,让用户为媒体卡授权
|
||||
// Jump to the system notification-access settings page for media-card grant
|
||||
@android.webkit.JavascriptInterface
|
||||
fun requestNotificationAccess() {
|
||||
Log.d("HearthBridge", "requestNotificationAccess called")
|
||||
notificationAccess?.requestAccess()
|
||||
}
|
||||
|
||||
// 注册媒体会话监听,回调推送给 H5(info 为 null 时推 "null")
|
||||
// Register media session listener; push callbacks to H5 (push "null" when info is null)
|
||||
fun setMediaListener(source: MediaSessionSource, webView: android.webkit.WebView) {
|
||||
|
||||
Reference in New Issue
Block a user