commit f007d0d605b07e62293d291039ec702d3a55a6aa
parent 23d74bd8c54126f603c113ec66b76570ec584c98
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Thu, 18 Jul 2024 15:08:47 +0200

fix: config state listener restart

Diffstat:
Mapp/src/main/kotlin/me/rhunk/snapenhance/RemoteSharedLibraryManager.kt | 6+++++-
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/ModConfig.kt | 2+-
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt | 17+++++++++++++----
3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSharedLibraryManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/RemoteSharedLibraryManager.kt @@ -1,5 +1,6 @@ package me.rhunk.snapenhance +import android.annotation.SuppressLint import android.os.Build import me.rhunk.snapenhance.common.bridge.InternalFileHandleType import okhttp3.OkHttpClient @@ -49,6 +50,7 @@ class RemoteSharedLibraryManager( return false } + @SuppressLint("ApplySharedPref") fun init() { val libraryFile = InternalFileHandleType.SIF.resolve(remoteSideContext.androidContext) val currentVersion = remoteSideContext.sharedPreferences.getString("sif", null)?.trim() @@ -72,7 +74,9 @@ class RemoteSharedLibraryManager( remoteSideContext.sharedPreferences.edit().putString("sif", latestVersion).commit() remoteSideContext.shortToast("SIF updated to $latestVersion!") // force restart snapchat - remoteSideContext.bridgeService?.stopSelf() + runCatching { + remoteSideContext.config.configStateListener?.takeIf { it.asBinder().pingBinder() }?.onRestartRequired() + } } else { remoteSideContext.log.warn("Failed to download latest sif") } diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/ModConfig.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/ModConfig.kt @@ -113,7 +113,7 @@ class ModConfig( val oldConfig = runCatching { fileWrapper.readBytes().toString(Charsets.UTF_8) }.getOrNull() fileWrapper.writeBytes(exportToString(config = config).toByteArray(Charsets.UTF_8)) - configStateListener?.also { + configStateListener?.takeIf { it.asBinder().pingBinder() }?.also { runCatching { compareDiff(createRootConfig().apply { fromJson(gson.fromJson(oldConfig ?: return@runCatching, JsonObject::class.java)) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt @@ -180,7 +180,11 @@ class SnapEnhance { actionManager.onActivityCreate() if (safeMode) { - appContext.inAppOverlay.showStatusToast(Icons.Outlined.Cancel, "Failed to load security features! Snapchat may not work properly.", durationMs = 5000) + appContext.inAppOverlay.showStatusToast( + Icons.Outlined.Cancel, + "Failed to load security features! Snapchat may not work properly.", + durationMs = 3000 + ) } } }.also { time -> @@ -227,15 +231,20 @@ class SnapEnhance { if (safeMode) { hook(HookStage.BEFORE) { param -> if (param.arg<String>(1) != "scplugin") return@hook + param.setResult(null) appContext.log.warn("Can't load scplugin in safe mode") - Thread.sleep(Long.MAX_VALUE) + runCatching { + Thread.sleep(Long.MAX_VALUE) + }.onFailure { + appContext.log.error(it) + } + exitProcess(1) } } lateinit var unhook: () -> Unit hook(HookStage.AFTER) { param -> - val libName = param.arg<String>(1) - if (libName != "client") return@hook + if (param.arg<String>(1) != "client") return@hook unhook() appContext.log.verbose("libclient lateInit") lateInit()