Skip to content

Commit

Permalink
feat(core): custom emoji font
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed May 29, 2024
1 parent e411c23 commit 07282e7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/src/main/assets/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@
"disable_bitmoji": {
"name": "Disable Bitmoji",
"description": "Disables Friends Profile Bitmoji"
},
"custom_emoji_font": {
"name": "Custom Emoji Font",
"description": "Allows you to use a custom emoji font. Only works with .ttf fonts"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Fingerprint
import androidx.compose.material.icons.filled.Memory
import me.rhunk.snapenhance.common.config.ConfigContainer
import me.rhunk.snapenhance.common.config.ConfigFlag
import me.rhunk.snapenhance.common.config.FeatureNotice

class Experimental : ConfigContainer() {
Expand All @@ -17,6 +18,12 @@ class Experimental : ConfigContainer() {
class NativeHooks : ConfigContainer(hasGlobalState = true) {
val composerHooks = container("composer_hooks", ComposerHooksConfig()) { requireRestart() }
val disableBitmoji = boolean("disable_bitmoji")
val customEmojiFont = string("custom_emoji_font") {
requireRestart()
addNotices(FeatureNotice.UNSTABLE)
addFlags(ConfigFlag.USER_IMPORT)
filenameFilter = { it.endsWith(".ttf") }
}
}

class E2EEConfig : ConfigContainer(hasGlobalState = true) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/me/rhunk/snapenhance/core/ModContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import me.rhunk.snapenhance.core.event.EventBus
import me.rhunk.snapenhance.core.event.EventDispatcher
import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.FeatureManager
import me.rhunk.snapenhance.core.features.impl.experiments.getCustomEmojiFontPath
import me.rhunk.snapenhance.core.logger.CoreLogger
import me.rhunk.snapenhance.core.messaging.CoreMessagingBridge
import me.rhunk.snapenhance.core.messaging.MessageSender
Expand Down Expand Up @@ -148,11 +149,13 @@ class ModContext(
}

fun reloadNativeConfig() {
if (config.experimental.nativeHooks.globalState != true) return
native.loadNativeConfig(
NativeConfig(
disableBitmoji = config.experimental.nativeHooks.disableBitmoji.get(),
disableMetrics = config.global.disableMetrics.get(),
composerHooks = config.experimental.nativeHooks.composerHooks.globalState == true,
customEmojiFontPath = getCustomEmojiFontPath(this)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.rhunk.snapenhance.core.features.impl.experiments

import me.rhunk.snapenhance.common.bridge.FileHandleScope
import me.rhunk.snapenhance.core.ModContext
import me.rhunk.snapenhance.core.util.ktx.getFileHandleLocalPath


private var cacheFontPath: String? = null

fun getCustomEmojiFontPath(
context: ModContext
): String? {
val customFileName = context.config.experimental.nativeHooks.customEmojiFont.getNullable() ?: return null
if (cacheFontPath == null) {
cacheFontPath = runCatching {
context.bridgeClient.getFileHandlerManager().getFileHandleLocalPath(
context,
FileHandleScope.USER_IMPORT,
customFileName,
"custom_emoji_font"
)
}.onFailure {
context.log.error("Failed to get custom emoji font", it)
}.getOrNull() ?: ""
}
return cacheFontPath?.takeIf { it.isNotEmpty() }
}


0 comments on commit 07282e7

Please sign in to comment.