mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-29 21:10:20 +02:00
add: status dialogs
This commit is contained in:
parent
fe0b82c75b
commit
39769f8940
@ -11,6 +11,8 @@ import me.rhunk.snapenhance.bridge.client.ServiceBridgeClient
|
|||||||
import me.rhunk.snapenhance.data.SnapClassCache
|
import me.rhunk.snapenhance.data.SnapClassCache
|
||||||
import me.rhunk.snapenhance.hook.HookStage
|
import me.rhunk.snapenhance.hook.HookStage
|
||||||
import me.rhunk.snapenhance.hook.Hooker
|
import me.rhunk.snapenhance.hook.Hooker
|
||||||
|
import kotlin.time.ExperimentalTime
|
||||||
|
import kotlin.time.measureTime
|
||||||
|
|
||||||
class SnapEnhance {
|
class SnapEnhance {
|
||||||
companion object {
|
companion object {
|
||||||
@ -22,7 +24,6 @@ class SnapEnhance {
|
|||||||
private val appContext = ModContext()
|
private val appContext = ModContext()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
Hooker.hook(Application::class.java, "attach", HookStage.BEFORE) { param ->
|
Hooker.hook(Application::class.java, "attach", HookStage.BEFORE) { param ->
|
||||||
appContext.androidContext = param.arg<Context>(0).also {
|
appContext.androidContext = param.arg<Context>(0).also {
|
||||||
classLoader = it.classLoader
|
classLoader = it.classLoader
|
||||||
@ -51,7 +52,7 @@ class SnapEnhance {
|
|||||||
if (!activity.packageName.equals(Constants.SNAPCHAT_PACKAGE_NAME)) return@hook
|
if (!activity.packageName.equals(Constants.SNAPCHAT_PACKAGE_NAME)) return@hook
|
||||||
val isMainActivityNotNull = appContext.mainActivity != null
|
val isMainActivityNotNull = appContext.mainActivity != null
|
||||||
appContext.mainActivity = activity
|
appContext.mainActivity = activity
|
||||||
if (isMainActivityNotNull) return@hook
|
if (isMainActivityNotNull || !appContext.mappings.areMappingsLoaded) return@hook
|
||||||
onActivityCreate()
|
onActivityCreate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,15 +66,20 @@ class SnapEnhance {
|
|||||||
return ServiceBridgeClient()
|
return ServiceBridgeClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTime::class)
|
||||||
private fun init() {
|
private fun init() {
|
||||||
val time = System.currentTimeMillis()
|
measureTime {
|
||||||
with(appContext) {
|
with(appContext) {
|
||||||
translation.init()
|
translation.init()
|
||||||
config.init()
|
config.init()
|
||||||
mappings.init()
|
mappings.init()
|
||||||
features.init()
|
//if mappings aren't loaded, we can't initialize features
|
||||||
|
if (!mappings.areMappingsLoaded) return
|
||||||
|
features.init()
|
||||||
|
}
|
||||||
|
}.also { time ->
|
||||||
|
Logger.debug("initialized in $time")
|
||||||
}
|
}
|
||||||
Logger.debug("initialized in ${System.currentTimeMillis() - time} ms")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onActivityCreate() {
|
private fun onActivityCreate() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.rhunk.snapenhance.features.impl.tweaks
|
package me.rhunk.snapenhance.features.impl.tweaks
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import me.rhunk.snapenhance.config.ConfigProperty
|
import me.rhunk.snapenhance.config.ConfigProperty
|
||||||
import me.rhunk.snapenhance.data.ContentType
|
import me.rhunk.snapenhance.data.ContentType
|
||||||
import me.rhunk.snapenhance.data.MessageSender
|
import me.rhunk.snapenhance.data.MessageSender
|
||||||
@ -11,7 +12,6 @@ import me.rhunk.snapenhance.hook.Hooker
|
|||||||
import me.rhunk.snapenhance.util.protobuf.ProtoReader
|
import me.rhunk.snapenhance.util.protobuf.ProtoReader
|
||||||
|
|
||||||
class GalleryMediaSendOverride : Feature("Gallery Media Send Override", loadParams = FeatureLoadParams.INIT_SYNC) {
|
class GalleryMediaSendOverride : Feature("Gallery Media Send Override", loadParams = FeatureLoadParams.INIT_SYNC) {
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
Hooker.hook(context.classCache.conversationManager, "sendMessageWithContent", HookStage.BEFORE) { param ->
|
Hooker.hook(context.classCache.conversationManager, "sendMessageWithContent", HookStage.BEFORE) { param ->
|
||||||
val localMessageContent = MessageContent(param.arg(1))
|
val localMessageContent = MessageContent(param.arg(1))
|
||||||
@ -20,8 +20,20 @@ class GalleryMediaSendOverride : Feature("Gallery Media Send Override", loadPara
|
|||||||
//story replies
|
//story replies
|
||||||
val messageProtoReader = ProtoReader(localMessageContent.content)
|
val messageProtoReader = ProtoReader(localMessageContent.content)
|
||||||
if (messageProtoReader.exists(7)) return@hook
|
if (messageProtoReader.exists(7)) return@hook
|
||||||
|
val overrideType = context.config.state(ConfigProperty.GALLERY_MEDIA_SEND_OVERRIDE)
|
||||||
|
|
||||||
when (val overrideType = context.config.state(ConfigProperty.GALLERY_MEDIA_SEND_OVERRIDE)) {
|
if (overrideType != "OFF" && messageProtoReader.readPath(3)?.getCount(3) != 1) {
|
||||||
|
context.runOnUiThread {
|
||||||
|
AlertDialog.Builder(context.mainActivity!!)
|
||||||
|
.setMessage("You can only send one media at a time")
|
||||||
|
.setPositiveButton("OK", null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
param.setResult(null)
|
||||||
|
return@hook
|
||||||
|
}
|
||||||
|
|
||||||
|
when (overrideType) {
|
||||||
"SNAP", "LIVE_SNAP" -> {
|
"SNAP", "LIVE_SNAP" -> {
|
||||||
localMessageContent.contentType = ContentType.SNAP
|
localMessageContent.contentType = ContentType.SNAP
|
||||||
localMessageContent.content = MessageSender.redSnapProto(overrideType == "LIVE_SNAP")
|
localMessageContent.content = MessageSender.redSnapProto(overrideType == "LIVE_SNAP")
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package me.rhunk.snapenhance.manager.impl
|
package me.rhunk.snapenhance.manager.impl
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.joinAll
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import me.rhunk.snapenhance.Constants
|
import me.rhunk.snapenhance.Constants
|
||||||
@ -22,6 +24,7 @@ import me.rhunk.snapenhance.mapping.impl.PlusSubscriptionMapper
|
|||||||
import me.rhunk.snapenhance.util.getObjectField
|
import me.rhunk.snapenhance.util.getObjectField
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
class MappingManager(private val context: ModContext) : Manager {
|
class MappingManager(private val context: ModContext) : Manager {
|
||||||
@ -36,6 +39,8 @@ class MappingManager(private val context: ModContext) : Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val mappings = ConcurrentHashMap<String, Any>()
|
private val mappings = ConcurrentHashMap<String, Any>()
|
||||||
|
val areMappingsLoaded: Boolean
|
||||||
|
get() = mappings.isNotEmpty()
|
||||||
private var snapBuildNumber = 0
|
private var snapBuildNumber = 0
|
||||||
|
|
||||||
@Suppress("deprecation")
|
@Suppress("deprecation")
|
||||||
@ -59,12 +64,35 @@ class MappingManager(private val context: ModContext) : Manager {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
runCatching {
|
context.runOnUiThread {
|
||||||
refresh()
|
val statusDialogBuilder = AlertDialog.Builder(context.mainActivity)
|
||||||
}.onSuccess {
|
.setMessage("Generating mappings, please wait...")
|
||||||
context.shortToast("Generated mappings for build $snapBuildNumber")
|
.setCancelable(false)
|
||||||
}.onFailure {
|
.setView(android.widget.ProgressBar(context.mainActivity).apply {
|
||||||
context.crash("Failed to generate mappings ${it.message}", it)
|
setPadding(0, 20, 0, 20)
|
||||||
|
})
|
||||||
|
|
||||||
|
val loadingDialog = statusDialogBuilder.show()
|
||||||
|
|
||||||
|
thread(start = true) {
|
||||||
|
runCatching {
|
||||||
|
refresh()
|
||||||
|
}.onSuccess {
|
||||||
|
context.shortToast("Generated mappings for build $snapBuildNumber")
|
||||||
|
context.softRestartApp()
|
||||||
|
}.onFailure {
|
||||||
|
Logger.error("Failed to generate mappings", it)
|
||||||
|
context.runOnUiThread {
|
||||||
|
loadingDialog.dismiss()
|
||||||
|
statusDialogBuilder.setView(null)
|
||||||
|
statusDialogBuilder.setMessage("Failed to generate mappings: $it")
|
||||||
|
statusDialogBuilder.setNegativeButton("Close") { _, _ ->
|
||||||
|
context.mainActivity!!.finish()
|
||||||
|
}
|
||||||
|
statusDialogBuilder.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +135,7 @@ class MappingManager(private val context: ModContext) : Manager {
|
|||||||
}
|
}
|
||||||
}.also { jobs.add(it) }
|
}.also { jobs.add(it) }
|
||||||
}
|
}
|
||||||
jobs.forEach { it.join() }
|
jobs.joinAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST", "DEPRECATION")
|
@Suppress("UNCHECKED_CAST", "DEPRECATION")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user