Skip to content

Commit 5e7d70c

Browse files
committed
fix(web): 修改 keepScreenOn 默认值及缓存清理逻辑
- 将 keepScreenOn 参数默认值从 true 改为 false- 为 keepScreenOn 方法添加默认提示文字"屏幕保持常亮" - 在清理缓存时增加 Android 14 版本判断,避免高版本系统调用 recycle 方法- 添加 Build.VERSION 判断防止在 Android 14以下版本出现兼容性问题 - 移除注释掉的 setBackgroundColor 代码行- 增加 CustomFileProvider 中对 NodeCacheManager 缓存清理的保护逻辑
1 parent f0b5da9 commit 5e7d70c

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

assists-web/src/main/java/com/ven/assists/web/ASJavascriptInterface.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class ASJavascriptInterface(val webView: WebView) {
318318
val minWidth = request.arguments?.get("minWidth")?.asInt ?: (ScreenUtils.getScreenWidth() * 0.5).toInt()
319319
val minHeight = request.arguments?.get("minHeight")?.asInt ?: (ScreenUtils.getScreenHeight() * 0.5).toInt()
320320
val initialCenter = request.arguments?.get("initialCenter")?.asBoolean ?: true
321-
val keepScreenOn = request.arguments?.get("keepScreenOn")?.asBoolean ?: true
321+
val keepScreenOn = request.arguments?.get("keepScreenOn")?.asBoolean ?: false
322322
val webWindowBinding = WebFloatingWindowBinding.inflate(LayoutInflater.from(AssistsService.instance)).apply {
323323
webView.loadUrl(url)
324324
webView.setBackgroundColor(0)

assists-web/src/main/java/com/ven/assists/web/CustomFileProvider.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.ven.assists.web
33
import android.app.Activity
44
import android.app.Application
55
import android.content.Intent
6+
import android.os.Build
67
import android.os.Bundle
78
import androidx.activity.ComponentActivity
89
import androidx.activity.result.ActivityResult
@@ -39,9 +40,12 @@ class CustomFileProvider : FileProvider() {
3940
}
4041
}
4142

42-
clearIds.forEach { NodeCacheManager.cache.remove(it) }
43-
44-
// LogUtils.dTag("NodeCacheManager", "cache size",NodeCacheManager.cache.size)
43+
clearIds.forEach {
44+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { // Android 14 以下
45+
runCatching { NodeCacheManager.cache[it]?.get()?.recycle() }
46+
}
47+
NodeCacheManager.cache.remove(it)
48+
}
4549
}
4650

4751
delay(1000)
@@ -108,6 +112,7 @@ class CustomFileProvider : FileProvider() {
108112
return result.getOrNull()
109113

110114
}
115+
111116
suspend fun requestLaunchersScan(scanOptions: ScanOptions): ScanIntentResult? {
112117
val result = runCatching {
113118
currentCompletableDeferredScan?.completeExceptionally(RuntimeException("reset"))

assists/src/main/java/com/ven/assists/AssistsCore.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ object AssistsCore {
169169
/**
170170
* 屏幕保持常亮
171171
*/
172-
fun keepScreenOn(tip: String = "") {
172+
fun keepScreenOn(tip: String = "屏幕保持常亮") {
173173
if (AssistsWindowManager.contains("keepScreenOn")) return
174174
AssistsService.instance?.let {
175175
AssistsWindowManager.add(FrameLayout(it).apply {
176-
// setBackgroundColor("#80000000".toColorInt())
176+
setBackgroundColor("#80000000".toColorInt())
177177
addView(TextView(it).apply {
178178
text = tip
179179
setTextColor("#80FF0000".toColorInt())

0 commit comments

Comments
 (0)