Fix auto update notify icon rules problem in IconAdaptationTool, IconRuleManagerTool, SystemUITool, NotifyIconRuleUpdateActivity

This commit is contained in:
2023-02-01 06:25:05 +08:00
parent 77ff08f6d7
commit ca4a594114
4 changed files with 56 additions and 53 deletions

View File

@@ -32,7 +32,6 @@ import com.fankes.coloros.notify.ui.activity.base.BaseActivity
import com.fankes.coloros.notify.utils.factory.delayedRun import com.fankes.coloros.notify.utils.factory.delayedRun
import com.fankes.coloros.notify.utils.tool.IconRuleManagerTool import com.fankes.coloros.notify.utils.tool.IconRuleManagerTool
import com.fankes.coloros.notify.utils.tool.SystemUITool import com.fankes.coloros.notify.utils.tool.SystemUITool
import com.highcapable.yukihookapi.hook.xposed.application.ModuleApplication.Companion.appContext
class NotifyIconRuleUpdateActivity : Activity() { class NotifyIconRuleUpdateActivity : Activity() {
@@ -49,7 +48,7 @@ class NotifyIconRuleUpdateActivity : Activity() {
return return
} }
/** 拉取云端数据 */ /** 拉取云端数据 */
IconRuleManagerTool.sync(appContext) { IconRuleManagerTool.sync(context = this) {
/** 刷新系统界面 */ /** 刷新系统界面 */
SystemUITool.refreshSystemUI() SystemUITool.refreshSystemUI()
/** 结束当前窗口 */ /** 结束当前窗口 */

View File

@@ -50,8 +50,8 @@ object IconAdaptationTool {
/** 推送通知的渠道名称 */ /** 推送通知的渠道名称 */
private const val NOTIFY_CHANNEL = "notifyRuleSupportId" private const val NOTIFY_CHANNEL = "notifyRuleSupportId"
/** 已过期的日期 */ /** 已过期的时间 */
private val outDateLimits = HashSet<String>() private val outTimeLimits = HashSet<String>()
/** /**
* 推送新 APP 安装适配通知 * 推送新 APP 安装适配通知
@@ -107,27 +107,20 @@ object IconAdaptationTool {
/** /**
* 自动更新通知图标优化在线规则 * 自动更新通知图标优化在线规则
*
* 一天执行一次
* @param context 实例 * @param context 实例
* @param timeSet 设定的时间 * @param timeSet 设定的时间
*/ */
fun prepareAutoUpdateIconRule(context: Context, timeSet: String) = runInSafe { fun prepareAutoUpdateIconRule(context: Context, timeSet: String) = runInSafe {
System.currentTimeMillis().also { System.currentTimeMillis().also {
if (it.stampToDate(format = "HH:mm") == timeSet && (outDateLimits.isEmpty() || outDateLimits.none { each -> val nowTime = it.stampToDate(format = "HH:mm")
each == it.stampToDate(format = "yyyy-MM-dd") if (timeSet != nowTime || outTimeLimits.any { e -> e == nowTime }) return
})) { outTimeLimits.add(nowTime)
outDateLimits.add(it.stampToDate(format = "yyyy-MM-dd")) context.startActivity(
context.startActivity( Intent().apply {
Intent().apply { component = ComponentName(MODULE_PACKAGE_NAME, "${MODULE_PACKAGE_NAME}.ui.activity.auto.NotifyIconRuleUpdateActivity")
component = ComponentName( flags = Intent.FLAG_ACTIVITY_NEW_TASK
MODULE_PACKAGE_NAME, }
"${MODULE_PACKAGE_NAME}.ui.activity.auto.NotifyIconRuleUpdateActivity" )
)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
)
}
} }
} }
} }

View File

@@ -206,7 +206,6 @@ object IconRuleManagerTool {
context.snakeOrNotify(title = "同步错误", msg = "目标地址不是有效的 JSON 数据") context.snakeOrNotify(title = "同步错误", msg = "目标地址不是有效的 JSON 数据")
params.isCompareDifferent(it) -> { params.isCompareDifferent(it) -> {
params.save(it) params.save(it)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
notifyRefresh(context) notifyRefresh(context)
callback() callback()
} }
@@ -255,7 +254,6 @@ object IconRuleManagerTool {
context.snakeOrNotify(title = "同步错误", msg = "目标地址不是有效的 JSON 数据") context.snakeOrNotify(title = "同步错误", msg = "目标地址不是有效的 JSON 数据")
params.isCompareDifferent(content) -> { params.isCompareDifferent(content) -> {
params.save(content) params.save(content)
pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
notifyRefresh(context) notifyRefresh(context)
callback() callback()
} }
@@ -354,8 +352,8 @@ object IconRuleManagerTool {
* @param context 实例 * @param context 实例
*/ */
private fun notifyRefresh(context: Context) { private fun notifyRefresh(context: Context) {
if (context !is AppCompatActivity) return if (context !is AppCompatActivity) pushNotify(context, title = "同步完成", msg = "已更新通知图标优化名单,点击查看")
SystemUITool.refreshSystemUI(context) { context.snake(msg = "通知图标优化名单已完成同步") } SystemUITool.refreshSystemUI(context) { if (context is AppCompatActivity) context.snake(msg = "已更新通知图标优化名单,点击查看") }
} }
/** /**
@@ -364,8 +362,7 @@ object IconRuleManagerTool {
* @param msg 消息内容 * @param msg 消息内容
*/ */
private fun Context.snakeOrNotify(title: String, msg: String) { private fun Context.snakeOrNotify(title: String, msg: String) {
if (this !is AppCompatActivity) if (this !is AppCompatActivity) pushNotify(context = this, title, msg)
pushNotify(context = this, title, msg)
else snake(msg) else snake(msg)
} }

View File

@@ -23,8 +23,12 @@
package com.fankes.coloros.notify.utils.tool package com.fankes.coloros.notify.utils.tool
import android.content.Context import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME import com.fankes.coloros.notify.hook.HookConst.SYSTEMUI_PACKAGE_NAME
import com.fankes.coloros.notify.utils.factory.* import com.fankes.coloros.notify.utils.factory.delayedRun
import com.fankes.coloros.notify.utils.factory.execShell
import com.fankes.coloros.notify.utils.factory.showDialog
import com.fankes.coloros.notify.utils.factory.snake
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.hook.factory.dataChannel import com.highcapable.yukihookapi.hook.factory.dataChannel
@@ -97,40 +101,50 @@ object SystemUITool {
* @param isRefreshCacheOnly 仅刷新缓存不刷新图标和通知改变 - 默认:否 * @param isRefreshCacheOnly 仅刷新缓存不刷新图标和通知改变 - 默认:否
* @param callback 成功后回调 * @param callback 成功后回调
*/ */
fun refreshSystemUI(context: Context? = null, isRefreshCacheOnly: Boolean = false, callback: () -> Unit = {}) = runInSafe { fun refreshSystemUI(context: Context? = null, isRefreshCacheOnly: Boolean = false, callback: () -> Unit = {}) {
if (YukiHookAPI.Status.isXposedModuleActive) /**
context?.showDialog { * 刷新系统界面
title = "请稍后" * @param result 回调结果
progressContent = "正在等待系统界面刷新" */
/** 是否等待成功 */ fun doRefresh(result: (Boolean) -> Unit) {
var isWaited = false context?.dataChannel(SYSTEMUI_PACKAGE_NAME)?.with {
/** 设置等待延迟 */ wait(CALL_MODULE_REFRESH_RESULT) { result(it) }
delayedRun(ms = 5000) { put(CALL_HOST_REFRESH_CACHING, isRefreshCacheOnly)
if (isWaited) return@delayedRun }
cancel() }
context.snake(msg = "预计响应超时,建议重启系统界面", actionText = "立即重启") { restartSystemUI(context) } when {
} YukiHookAPI.Status.isXposedModuleActive && context is AppCompatActivity ->
checkingActivated(context) { isValied -> context.showDialog {
when { title = "请稍后"
isValied.not() -> { progressContent = "正在等待系统界面刷新"
cancel() /** 是否等待成功 */
isWaited = true var isWaited = false
context.snake(msg = "请重启系统界面以生效模块更新", actionText = "立即重启") { restartSystemUI(context) } /** 设置等待延迟 */
} delayedRun(ms = 5000) {
else -> context.dataChannel(SYSTEMUI_PACKAGE_NAME).with { if (isWaited) return@delayedRun
wait(CALL_MODULE_REFRESH_RESULT) { cancel()
context.snake(msg = "预计响应超时,建议重启系统界面", actionText = "立即重启") { restartSystemUI(context) }
}
checkingActivated(context) { isValied ->
when {
isValied.not() -> {
cancel()
isWaited = true
context.snake(msg = "请重启系统界面以生效模块更新", actionText = "立即重启") { restartSystemUI(context) }
}
else -> doRefresh {
cancel() cancel()
isWaited = true isWaited = true
callback() callback()
if (it.not()) context.snake(msg = "刷新失败,建议重启系统界面", actionText = "立即重启") { restartSystemUI(context) } if (it.not()) context.snake(msg = "刷新失败,建议重启系统界面", actionText = "立即重启") { restartSystemUI(context) }
} }
put(CALL_HOST_REFRESH_CACHING, isRefreshCacheOnly)
} }
} }
noCancelable()
} }
noCancelable() YukiHookAPI.Status.isXposedModuleActive.not() && context is AppCompatActivity -> context.snake(msg = "模块没有激活,更改不会生效")
} else -> doRefresh { callback() }
else context?.snake(msg = "模块没有激活,更改不会生效") }
} }
/** /**