Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit a3dcb0e

Browse files
committed
fix: 优化小米设备专属功能判断
* 防止开启不存在的高级材质导致其他设备崩溃
1 parent 596f2c4 commit a3dcb0e

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import statusbar.lyric.tools.Tools.isTargetView
9191
import statusbar.lyric.tools.Tools.observableChange
9292
import statusbar.lyric.tools.Tools.shell
9393
import statusbar.lyric.tools.XiaomiUtils.isHyperOS
94+
import statusbar.lyric.tools.XiaomiUtils.isXiaomi
9495
import statusbar.lyric.view.LyricSwitchView
9596
import statusbar.lyric.view.TitleDialog
9697
import java.io.File
@@ -220,10 +221,10 @@ class SystemUILyric : BaseHook() {
220221
override fun init() {
221222
"Initializing Hook".log()
222223
Application::class.java.methodFinder().filterByName("attach").single().createHook {
223-
after { hook ->
224+
after {
224225
hook()
225226
if (!canLoad) return@after
226-
registerSuperLyric(hook.args[0] as Context)
227+
registerSuperLyric(it.args[0] as Context)
227228
}
228229
}
229230
}
@@ -235,7 +236,6 @@ class SystemUILyric : BaseHook() {
235236
if (!canLoad) return@after
236237

237238
val view = it.thisObject as TextView
238-
239239
view.post {
240240
if (view.isTargetView()) {
241241
"Running onDraw".log()
@@ -256,7 +256,7 @@ class SystemUILyric : BaseHook() {
256256
"lyricHook init".log()
257257
View::class.java.methodFinder().filterByName("onDetachedFromWindow").single().createHook {
258258
after {
259-
val view = (it.thisObject as View)
259+
val view = it.thisObject as View
260260
if (view.isTargetView()) {
261261
"Running onDetachedFromWindow".log()
262262
canLoad = true
@@ -493,15 +493,15 @@ class SystemUILyric : BaseHook() {
493493
}
494494

495495
private fun lyricLayoutInit() {
496-
goMainThread(1) {
496+
goMainThread {
497497
"lyricLayout init".log()
498498
runCatching { (lyricLayout.parent as ViewGroup).removeView(lyricLayout) }
499499
if (config.viewLocation == 0) {
500500
targetView.addView(lyricLayout, 0)
501501
} else {
502502
targetView.addView(lyricLayout)
503503
}
504-
if (isHyperOS && config.mHyperOSTexture) {
504+
if (isXiaomi && isHyperOS && config.mHyperOSTexture) {
505505
val blurRadio = config.mHyperOSTextureRadio
506506
val cornerRadius = cornerRadius(config.mHyperOSTextureCorner.toFloat())
507507
val blendModes = arrayOf(
@@ -743,10 +743,10 @@ class SystemUILyric : BaseHook() {
743743
}
744744
}
745745

746-
private fun updateConfig(delay: Long = 0L) {
746+
private fun updateConfig() {
747747
"Updating Config".log()
748748
config.update()
749-
goMainThread(delay) {
749+
goMainThread {
750750
lyricView.apply {
751751
setTextSize(
752752
TypedValue.COMPLEX_UNIT_SHIFT,

app/src/main/kotlin/statusbar/lyric/hook/module/SystemUITest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class SystemUITest : BaseHook() {
106106
val className = view::class.java.name
107107
val textContent = view.text.toString().dispose()
108108

109+
if (view.visibility != View.VISIBLE) return@after
110+
if (!view.isAttachedToWindow) return@after
109111
if (!textContent.isTimeSameInternal()) return@after
110112
if (!className.filterClassNameInternal()) return@after
111113
val parentView = view.parent as? LinearLayout ?: return@after

app/src/main/kotlin/statusbar/lyric/hook/module/xiaomi/FocusNotifyController.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import statusbar.lyric.R
3535
import statusbar.lyric.config.XposedOwnSP
3636
import statusbar.lyric.hook.module.SystemUILyric
3737
import statusbar.lyric.tools.LogTools.log
38-
import statusbar.lyric.tools.Tools
3938
import statusbar.lyric.tools.Tools.callMethod
4039
import statusbar.lyric.tools.Tools.getObjectField
40+
import statusbar.lyric.tools.Tools.goMainThread
4141
import statusbar.lyric.tools.Tools.ifNotNull
4242
import statusbar.lyric.tools.Tools.isNotNull
4343
import statusbar.lyric.tools.XiaomiUtils
@@ -142,7 +142,7 @@ class FocusNotifyController {
142142
val mIcon = focusedNotify!!.getObjectField("mIcon")
143143
val mContent = focusedNotify!!.getObjectField("mContent")
144144
if (mIcon == null || mContent == null) return
145-
Tools.goMainThread {
145+
goMainThread {
146146
focusedNotify!!.callMethod("cancelFolme")
147147
focusedNotify!!.callMethod("hideImmediately", mIcon)
148148
focusedNotify!!.callMethod("hideImmediately", mContent)
@@ -161,7 +161,7 @@ class FocusNotifyController {
161161
val mContent = focusedNotify!!.getObjectField("mContent")
162162
if (mIcon == null || mContent == null) return
163163
isHideFocusNotify = false
164-
Tools.goMainThread {
164+
goMainThread {
165165
focusedNotify!!.callMethod("cancelFolme")
166166
focusedNotify!!.callMethod("showImmediately", mIcon)
167167
focusedNotify!!.callMethod("showImmediately", mContent)

app/src/main/kotlin/statusbar/lyric/tools/Tools.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ object Tools {
152152
}
153153

154154
fun View.isTargetView(): Boolean {
155+
if (this !is TextView) return false
156+
if (this.visibility != View.VISIBLE) return false
157+
if (!this.isAttachedToWindow) return false
155158
val textViewClassName = config.textViewClassName
156159
val textViewId = config.textViewId
157160
val textSize = config.textSize
@@ -160,7 +163,6 @@ object Tools {
160163
EzXHelper.moduleRes.getString(R.string.load_class_empty).log()
161164
return false
162165
}
163-
if (this !is TextView) return false
164166
if (this.javaClass.name != textViewClassName) return false
165167
if (this.id != textViewId) return false
166168
if (this.textSize != textSize) return false
@@ -202,7 +204,7 @@ object Tools {
202204
}
203205

204206
fun goMainThread(delayed: Long = 0, callback: () -> Unit): Boolean {
205-
return Handler(Looper.getMainLooper()).postDelayed({ callback() }, delayed * 1000)
207+
return Handler(Looper.getMainLooper()).postDelayed({ callback() }, delayed)
206208
}
207209

208210
fun Context.isLandscape() = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE

0 commit comments

Comments
 (0)