feat: suspend location updates

This commit is contained in:
rhunk
2023-12-20 23:45:12 +01:00
parent 47e9a0e0b1
commit cc94ea93b2
5 changed files with 68 additions and 1 deletions

View File

@ -453,6 +453,10 @@
}
}
},
"suspend_location_updates": {
"name": "Suspend Location Updates",
"description": "Adds a button in map settings to suspend location updates"
},
"snapchat_plus": {
"name": "Snapchat Plus",
"description": "Enables Snapchat Plus features\nSome Server-sided features may not work"
@ -1030,5 +1034,9 @@
"streaks_reminder": {
"notification_title": "Streaks",
"notification_text": "You will lose your Streak with {friend} in {hoursLeft} hours"
},
"suspend_location_updates": {
"switch_text": "Suspend Location Updates"
}
}

View File

@ -8,7 +8,8 @@ enum class BridgeFileType(val value: Int, val fileName: String, val displayName:
CONFIG(0, "config.json", "Config"),
MAPPINGS(1, "mappings.json", "Mappings"),
MESSAGE_LOGGER_DATABASE(2, "message_logger.db", "Message Logger",true),
PINNED_CONVERSATIONS(3, "pinned_conversations.txt", "Pinned Conversations");
PINNED_CONVERSATIONS(3, "pinned_conversations.txt", "Pinned Conversations"),
SUSPEND_LOCATION_STATE(4, "suspend_location_state.txt", "Suspend Location State");
fun resolve(context: Context): File = if (isDatabase) {
context.getDatabasePath(fileName)

View File

@ -8,6 +8,7 @@ class Global : ConfigContainer() {
val coordinates = mapCoordinates("coordinates", 0.0 to 0.0) { requireRestart()} // lat, long
}
val spoofLocation = container("spoofLocation", SpoofLocation())
val suspendLocationUpdates = boolean("suspend_location_updates") { requireRestart() }
val snapchatPlus = boolean("snapchat_plus") { requireRestart() }
val disableConfirmationDialogs = multiple("disable_confirmation_dialogs", "remove_friend", "block_friend", "ignore_friend", "hide_friend", "hide_conversation", "clear_conversation") { requireRestart() }
val disableMetrics = boolean("disable_metrics")

View File

@ -0,0 +1,56 @@
package me.rhunk.snapenhance.core.features.impl.global
import android.view.ViewGroup
import android.widget.Switch
import me.rhunk.snapenhance.common.bridge.types.BridgeFileType
import me.rhunk.snapenhance.core.event.events.impl.AddViewEvent
import me.rhunk.snapenhance.core.features.BridgeFileFeature
import me.rhunk.snapenhance.core.features.FeatureLoadParams
import me.rhunk.snapenhance.core.ui.ViewAppearanceHelper
import me.rhunk.snapenhance.core.util.hook.HookStage
import me.rhunk.snapenhance.core.util.hook.hook
import me.rhunk.snapenhance.core.util.ktx.getId
//TODO: bridge shared preferences
class SuspendLocationUpdates : BridgeFileFeature(
"Suspend Location Updates",
loadParams = FeatureLoadParams.INIT_SYNC or FeatureLoadParams.ACTIVITY_CREATE_SYNC,
bridgeFileType = BridgeFileType.SUSPEND_LOCATION_STATE
) {
private val isEnabled get() = context.config.global.suspendLocationUpdates.get()
override fun init() {
if (!isEnabled) return
reload()
context.classCache.unifiedGrpcService.hook("bidiStreamingCall", HookStage.BEFORE) { param ->
val uri = param.arg<String>(0)
if (uri == "/snapchat.valis.Valis/Communicate" && exists("true")) {
param.setResult(null)
}
}
}
override fun onActivityCreate() {
if (!isEnabled) return
val locationSharingSettingsContainerId = context.resources.getId("location_sharing_settings_container")
val recyclerViewContainerId = context.resources.getId("recycler_view_container")
context.event.subscribe(AddViewEvent::class) { event ->
if (event.parent.id == locationSharingSettingsContainerId && event.view.id == recyclerViewContainerId) {
(event.view as ViewGroup).addView(Switch(event.view.context).apply {
isChecked = exists("true")
ViewAppearanceHelper.applyTheme(this)
text = this@SuspendLocationUpdates.context.translation["suspend_location_updates.switch_text"]
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
setOnCheckedChangeListener { _, isChecked ->
setState("true", isChecked)
}
})
}
}
}
}

View File

@ -115,6 +115,7 @@ class FeatureManager(
FideliusIndicator::class,
EditTextOverride::class,
PreventForcedLogout::class,
SuspendLocationUpdates::class,
)
initializeFeatures()