commit 6c87e72d94e2280e068b219586aa8225c1bab596
parent 248100b8b9c9a373e7575be4a0166d6a003099ea
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 12 Jun 2024 16:20:24 +0200

fix(bridge): auto bridge restart on SnapEnhance update

Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>

Diffstat:
Mcommon/src/main/aidl/me/rhunk/snapenhance/bridge/BridgeInterface.aidl | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/bridge/BridgeClient.kt | 8++++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/FriendFeedInfoMenu.kt | 4++--
3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/common/src/main/aidl/me/rhunk/snapenhance/bridge/BridgeInterface.aidl b/common/src/main/aidl/me/rhunk/snapenhance/bridge/BridgeInterface.aidl @@ -15,7 +15,7 @@ import me.rhunk.snapenhance.bridge.location.LocationManager; interface BridgeInterface { /** - * Get the application APK path (assets for the conversation exporter) + * Get the SnapEnhance APK path (used in LSPatch updater and for auto bridge restart) */ String getApplicationApkPath(); diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/BridgeClient.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/BridgeClient.kt @@ -42,6 +42,7 @@ class BridgeClient( private lateinit var service: BridgeInterface private val onConnectedCallbacks = mutableListOf<suspend () -> Unit>() + private var cacheSnapEnhanceApkPath: String? = null fun addOnConnectedCallback(callback: suspend () -> Unit) { synchronized(onConnectedCallbacks) { @@ -123,6 +124,13 @@ class BridgeClient( } } } + cacheSnapEnhanceApkPath = this.service.applicationApkPath.also { + if (cacheSnapEnhanceApkPath != null && cacheSnapEnhanceApkPath != it) { + context.log.verbose("Restarting Snapchat due to SnapEnhance update") + context.softRestartApp() + return + } + } resumeContinuation(true) } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/FriendFeedInfoMenu.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ui/menu/impl/FriendFeedInfoMenu.kt @@ -414,8 +414,8 @@ class FriendFeedInfoMenu : AbstractMenu() { state = !ruleFeature.getState(conversationId) ruleFeature.setState(conversationId, state) context.inAppOverlay.showStatusToast( - if (ruleFeature.getState(conversationId)) Icons.Default.CheckCircleOutline else Icons.Default.NotInterested, - context.translation.format("rules.toasts.${if (ruleFeature.getState(conversationId)) "enabled" else "disabled"}", "ruleName" to context.translation[ruleFeature.ruleType.translateOptionKey(ruleState.key)]), + if (state) Icons.Default.CheckCircleOutline else Icons.Default.NotInterested, + context.translation.format("rules.toasts.${if (state) "enabled" else "disabled"}", "ruleName" to context.translation[ruleFeature.ruleType.translateOptionKey(ruleState.key)]), durationMs = 1500 ) context.mainActivity?.triggerRootCloseTouchEvent()