fix: config state listener restart

This commit is contained in:
rhunk
2024-07-18 15:08:47 +02:00
parent 23d74bd8c5
commit f007d0d605
3 changed files with 19 additions and 6 deletions

View File

@@ -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")
}

View File

@@ -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))

View File

@@ -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()