commit 07282e7b48b7e7f162a4512cb1b55d527725e999
parent e411c2352fdb17cf940d72007aef98b2aa4ba5a6
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Wed, 29 May 2024 22:21:21 +0200

feat(core): custom emoji font

Diffstat:
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt | 7+++++++
Mcore/src/main/kotlin/me/rhunk/snapenhance/core/ModContext.kt | 3+++
Acore/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/CustomEmojiFont.kt | 29+++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -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" } } }, diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Experimental.kt @@ -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() { @@ -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) { diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/ModContext.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/ModContext.kt @@ -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 @@ -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) ) ) } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/CustomEmojiFont.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/experiments/CustomEmojiFont.kt @@ -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() } +} + +