fix: config state listener restart
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user