feat: config export

- activity launcher helper
This commit is contained in:
rhunk
2023-08-23 00:44:05 +02:00
parent d12a5d689e
commit ae70b29180
13 changed files with 198 additions and 109 deletions

View File

@ -191,10 +191,6 @@
"name": "Anonymous Story Viewing",
"description": "Prevents anyone from knowing you've seen their story"
},
"prevent_read_receipts": {
"name": "Prevent Read Receipts",
"description": "Prevent anyone from knowing you've opened their Snaps/Chats"
},
"hide_bitmoji_presence": {
"name": "Hide Bitmoji Presence",
"description": "Hides your Bitmoji presence from the chat"

View File

@ -8,11 +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),
STEALTH(3, "stealth.txt", "Stealth Conversations"),
ANTI_AUTO_DOWNLOAD(4, "anti_auto_download.txt", "Anti Auto Download"),
ANTI_AUTO_SAVE(5, "anti_auto_save.txt", "Anti Auto Save"),
AUTO_UPDATER_TIMESTAMP(6, "auto_updater_timestamp.txt", "Auto Updater Timestamp"),
PINNED_CONVERSATIONS(7, "pinned_conversations.txt", "Pinned Conversations");
AUTO_UPDATER_TIMESTAMP(3, "auto_updater_timestamp.txt", "Auto Updater Timestamp"),
PINNED_CONVERSATIONS(4, "pinned_conversations.txt", "Pinned Conversations");
fun resolve(context: Context): File = if (isDatabase) {
context.getDatabasePath(fileName)

View File

@ -19,10 +19,11 @@ class ModConfig {
private val file = FileLoaderWrapper(BridgeFileType.CONFIG, "{}".toByteArray(Charsets.UTF_8))
var wasPresent by Delegates.notNull<Boolean>()
val root = RootConfig()
lateinit var root: RootConfig
operator fun getValue(thisRef: Any?, property: Any?) = root
private fun load() {
root = RootConfig()
wasPresent = file.isFileExists()
if (!file.isFileExists()) {
writeConfig()
@ -44,10 +45,26 @@ class ModConfig {
root.fromJson(configObject)
}
fun writeConfig() {
fun exportToString(): String {
val configObject = root.toJson()
configObject.addProperty("_locale", locale)
file.write(configObject.toString().toByteArray(Charsets.UTF_8))
return configObject.toString()
}
fun reset() {
root = RootConfig()
writeConfig()
}
fun writeConfig() {
file.write(exportToString().toByteArray(Charsets.UTF_8))
}
fun loadFromString(string: String) {
val configObject = gson.fromJson(string, JsonObject::class.java)
locale = configObject.get("_locale")?.asString ?: LocaleWrapper.DEFAULT_LOCALE
root.fromJson(configObject)
writeConfig()
}
fun loadFromContext(context: Context) {

View File

@ -6,12 +6,9 @@ import me.rhunk.snapenhance.data.NotificationType
class MessagingTweaks : ConfigContainer() {
val anonymousStoryViewing = boolean("anonymous_story_viewing")
val preventReadReceipts = boolean("prevent_read_receipts")
val hideBitmojiPresence = boolean("hide_bitmoji_presence")
val hideTypingNotifications = boolean("hide_typing_notifications")
val unlimitedSnapViewTime = boolean("unlimited_snap_view_time")
val preventMessageSending = multiple("prevent_message_sending", *NotificationType.getOutgoingValues().map { it.key }.toTypedArray())
val messageLogger = boolean("message_logger") { addNotices(FeatureNotice.MAY_CAUSE_CRASHES) }
val autoSaveMessagesInConversations = multiple("auto_save_messages_in_conversations",
"CHAT",
"SNAP",
@ -19,7 +16,8 @@ class MessagingTweaks : ConfigContainer() {
"EXTERNAL_MEDIA",
"STICKER"
)
val preventMessageSending = multiple("prevent_message_sending", *NotificationType.getOutgoingValues().map { it.key }.toTypedArray())
val messageLogger = boolean("message_logger") { addNotices(FeatureNotice.MAY_CAUSE_CRASHES) }
val galleryMediaSendOverride = boolean("gallery_media_send_override")
val messagePreviewLength = integer("message_preview_length", defaultValue = 20)
}

View File

@ -61,12 +61,3 @@ data class MessagingFriendInfo(
val bitmojiId: String?,
val selfieId: String?
) : SerializableDataObject()
data class MessagingRule(
val id: Int,
val type: MessagingRuleType,
val socialScope: SocialScope,
val targetUuid: String,
//val mode: Mode?,
) : SerializableDataObject()

View File

@ -9,9 +9,7 @@ import me.rhunk.snapenhance.hook.Hooker
class PreventReadReceipts : Feature("PreventReadReceipts", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
override fun onActivityCreate() {
val preventReadReceipts by context.config.messaging.preventReadReceipts
val isConversationInStealthMode: (SnapUUID) -> Boolean = hook@{
if (preventReadReceipts) return@hook true
context.feature(StealthMode::class).canUseRule(it.toString())
}

View File

@ -1,19 +0,0 @@
package me.rhunk.snapenhance.features.impl.tweaks
import me.rhunk.snapenhance.bridge.types.BridgeFileType
import me.rhunk.snapenhance.features.BridgeFileFeature
import me.rhunk.snapenhance.features.FeatureLoadParams
class AntiAutoSave : BridgeFileFeature("AntiAutoSave", BridgeFileType.ANTI_AUTO_SAVE, loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
override fun onActivityCreate() {
readFile()
}
fun setConversationIgnored(userId: String, state: Boolean) {
setState(userId.hashCode().toLong().toString(16), state)
}
fun isConversationIgnored(userId: String): Boolean {
return exists(userId.hashCode().toLong().toString(16))
}
}

View File

@ -21,7 +21,6 @@ import me.rhunk.snapenhance.features.impl.spying.AnonymousStoryViewing
import me.rhunk.snapenhance.features.impl.spying.MessageLogger
import me.rhunk.snapenhance.features.impl.spying.PreventReadReceipts
import me.rhunk.snapenhance.features.impl.spying.StealthMode
import me.rhunk.snapenhance.features.impl.tweaks.AntiAutoSave
import me.rhunk.snapenhance.features.impl.tweaks.AutoSave
import me.rhunk.snapenhance.features.impl.tweaks.CameraTweaks
import me.rhunk.snapenhance.features.impl.tweaks.DisableVideoLengthRestriction
@ -76,7 +75,6 @@ class FeatureManager(private val context: ModContext) : Manager {
register(UITweaks::class)
register(ConfigurationOverride::class)
register(GalleryMediaSendOverride::class)
register(AntiAutoSave::class)
register(UnlimitedSnapViewTime::class)
register(DisableVideoLengthRestriction::class)
register(MediaQualityLevelOverride::class)