From 6fd045f7ebee0ca06febd560f1b3c0be1ba6bd41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=84=95=E6=99=A8HChen?= <123531821+HChenX@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:55:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A6=82=E7=8E=87=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=8A=B6=E6=80=81=E6=A0=8F=E6=AD=8C=E8=AF=8D=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#546)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lyric/hook/module/SystemUILyric.kt | 103 +++++++++--------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt b/app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt index c6a5a77e..cb2e60a6 100644 --- a/app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt +++ b/app/src/main/kotlin/statusbar/lyric/hook/module/SystemUILyric.kt @@ -82,7 +82,6 @@ import statusbar.lyric.tools.LyricViewTools.randomAnima import statusbar.lyric.tools.LyricViewTools.showView import statusbar.lyric.tools.SystemMediaSessionListener import statusbar.lyric.tools.Tools.callMethod -import statusbar.lyric.tools.Tools.checkBroadcastReceiverState import statusbar.lyric.tools.Tools.existField import statusbar.lyric.tools.Tools.existMethod import statusbar.lyric.tools.Tools.getObjectField @@ -164,7 +163,8 @@ class SystemUILyric : BaseHook() { private var canHideFocusNotify = false private var isOS2FocusNotifyShowing = false private var isOS1FocusNotifyShowing = false // OS1 不要支持隐藏焦点通知 - val isReally by lazy { this@SystemUILyric::clockView.isInitialized } + val isReady: Boolean get() = this@SystemUILyric::clockView.isInitialized + // val isReally by lazy { this@SystemUILyric::clockView.isInitialized } private var theoreticalWidth: Int = 0 private lateinit var point: Point @@ -239,7 +239,7 @@ class SystemUILyric : BaseHook() { "Init Hook".log() Application::class.java.methodFinder().filterByName("attach").first().createHook { after { hook -> - registerReceiverIfNeed(hook.args[0] as Context) + registerReceiver(hook.args[0] as Context) } } @@ -762,70 +762,67 @@ class SystemUILyric : BaseHook() { updateConfig(1) } - private var mLyricReceiver: LyricReceiver? = null private var mUpdateConfig: UpdateConfig = UpdateConfig() private var mScreenLockReceiver: ScreenLockReceiver = ScreenLockReceiver() @SuppressLint("UnspecifiedRegisterReceiverFlag") - private fun registerReceiverIfNeed(context: Context) { - "Register Receiver".log() - if (mLyricReceiver == null || !checkBroadcastReceiverState(context, mLyricReceiver)) { - mLyricReceiver = LyricReceiver(object : LyricListener() { - override fun onUpdate(lyricData: LyricData) { - if (!isReally) return - val lyric = lyricData.lyric - lastLyric = lyric - playingApp = lyricData.extraData.packageName - changeLyricStateIfInFullScreenMode() - - if (isHiding) return - if (timeoutRestoreHandler.hasMessages(TIMEOUT_RESTORE)) { - timeoutRestoreHandler.removeMessages(TIMEOUT_RESTORE) - timeoutRestoreHandler.sendEmptyMessageDelayed(TIMEOUT_RESTORE, 10000L) - } else timeoutRestoreHandler.sendEmptyMessageDelayed(TIMEOUT_RESTORE, 10000L) - hideFocusNotifyIfNeed() - changeIcon(lyricData.extraData) - changeLyric(lastLyric, lyricData.extraData.delay) - titleShowHandler.sendEmptyMessage(TITLE_SHOWING) - } + private fun registerReceiver(context: Context) { + val mLyricReceiver = LyricReceiver(object : LyricListener() { + override fun onUpdate(lyricData: LyricData) { + if (!isReady) return + val lyric = lyricData.lyric + lastLyric = lyric + playingApp = lyricData.extraData.packageName + changeLyricStateIfInFullScreenMode() + + if (isHiding) return + if (timeoutRestoreHandler.hasMessages(TIMEOUT_RESTORE)) { + timeoutRestoreHandler.removeMessages(TIMEOUT_RESTORE) + timeoutRestoreHandler.sendEmptyMessageDelayed(TIMEOUT_RESTORE, 10000L) + } else timeoutRestoreHandler.sendEmptyMessageDelayed(TIMEOUT_RESTORE, 10000L) + hideFocusNotifyIfNeed() + changeIcon(lyricData.extraData) + changeLyric(lastLyric, lyricData.extraData.delay) + titleShowHandler.sendEmptyMessage(TITLE_SHOWING) + } - override fun onStop(lyricData: LyricData) { - if (!isReally) return - if (playingApp.isNotEmpty()) { - if (lyricData.extraData.packageName.isNotEmpty() && - playingApp != lyricData.extraData.packageName - ) return - } - playingApp = "" - lastLyric = "" - hideLyric() - showFocusNotifyIfNeed() - if (timeoutRestoreHandler.hasMessages(TIMEOUT_RESTORE)) { - timeoutRestoreHandler.removeMessages(TIMEOUT_RESTORE) - } + override fun onStop(lyricData: LyricData) { + if (!isReady) return + if (playingApp.isNotEmpty()) { + if (lyricData.extraData.packageName.isNotEmpty() && + playingApp != lyricData.extraData.packageName + ) return + } + playingApp = "" + lastLyric = "" + hideLyric() + showFocusNotifyIfNeed() + if (timeoutRestoreHandler.hasMessages(TIMEOUT_RESTORE)) { + timeoutRestoreHandler.removeMessages(TIMEOUT_RESTORE) } - }) - registerLyricListener(context, BuildConfig.API_VERSION, mLyricReceiver!!) - } - - if (!checkBroadcastReceiverState(context, mUpdateConfig)) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - context.registerReceiver(UpdateConfig(), IntentFilter("updateConfig"), Context.RECEIVER_EXPORTED) - } else { - context.registerReceiver(UpdateConfig(), IntentFilter("updateConfig")) } + }) + registerLyricListener(context, BuildConfig.API_VERSION, mLyricReceiver) - if (config.hideLyricWhenLockScreen && !checkBroadcastReceiverState(context, mScreenLockReceiver)) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver(mUpdateConfig, IntentFilter("updateConfig"), Context.RECEIVER_EXPORTED) + } else { + context.registerReceiver(mUpdateConfig, IntentFilter("updateConfig")) + } + + if (config.hideLyricWhenLockScreen) { val screenLockFilter = IntentFilter().apply { addAction(Intent.ACTION_SCREEN_OFF) addAction(Intent.ACTION_USER_PRESENT) } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - context.registerReceiver(ScreenLockReceiver(), screenLockFilter, Context.RECEIVER_EXPORTED) + context.registerReceiver(mScreenLockReceiver, screenLockFilter, Context.RECEIVER_EXPORTED) } else { - context.registerReceiver(ScreenLockReceiver(), screenLockFilter) + context.registerReceiver(mScreenLockReceiver, screenLockFilter) } } + + "Register Receiver".log() } private fun changeLyric(lyric: String, delay: Int) { @@ -1059,7 +1056,7 @@ class SystemUILyric : BaseHook() { val newConfig = hookParam.args[0] as Configuration // themeMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE || newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - if (isReally) + if (isReady) changeLyricStateIfInFullScreenMode() } } @@ -1112,7 +1109,7 @@ class SystemUILyric : BaseHook() { override fun onReceive(context: Context, intent: Intent) { when (intent.getStringExtra("type")) { "normal" -> { - if (!isReally) return + if (!isReady) return updateConfig() }