refactor: composer loader
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
@@ -91,6 +91,12 @@ class RemoteFileHandleManager(
|
||||
File(userImportFolder, name.substringAfterLast("/"))
|
||||
)
|
||||
}
|
||||
FileHandleScope.COMPOSER -> {
|
||||
return AssetFileHandle(
|
||||
context,
|
||||
"composer/${name.substringAfterLast("/")}"
|
||||
)
|
||||
}
|
||||
else -> return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,12 +193,6 @@ class RemoteScriptManager(
|
||||
}
|
||||
|
||||
override fun getScriptContent(moduleName: String): ParcelFileDescriptor? {
|
||||
if (moduleName.startsWith("composer/")) {
|
||||
return runCatching {
|
||||
context.androidContext.assets.open("composer/${moduleName.removePrefix("composer/")}")
|
||||
.toParcelFileDescriptor(context.coroutineScope)
|
||||
}.getOrNull()
|
||||
}
|
||||
return getScriptInputStream(moduleName) { it?.toParcelFileDescriptor(context.coroutineScope) }
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ enum class FileHandleScope(
|
||||
) {
|
||||
INTERNAL("internal"),
|
||||
LOCALE("locale"),
|
||||
USER_IMPORT("user_import");
|
||||
USER_IMPORT("user_import"),
|
||||
COMPOSER("composer");
|
||||
|
||||
companion object {
|
||||
fun fromValue(name: String): FileHandleScope? = entries.find { it.key == name }
|
||||
|
||||
@@ -19,6 +19,8 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.launch
|
||||
import me.rhunk.snapenhance.common.bridge.FileHandleScope
|
||||
import me.rhunk.snapenhance.common.bridge.toWrapper
|
||||
import me.rhunk.snapenhance.common.ui.AppMaterialTheme
|
||||
import me.rhunk.snapenhance.common.ui.createComposeAlertDialog
|
||||
import me.rhunk.snapenhance.common.ui.createComposeView
|
||||
@@ -193,14 +195,11 @@ class ComposerHooks: Feature("ComposerHooks", loadParams = FeatureLoadParams.INI
|
||||
context.log.error("ComposerHooks cannot be loaded without NativeLib")
|
||||
return
|
||||
}
|
||||
val loaderScript = context.scriptRuntime.scripting.getScriptContent("composer/loader.js")?.let { pfd ->
|
||||
ParcelFileDescriptor.AutoCloseInputStream(pfd).use {
|
||||
it.readBytes().toString(Charsets.UTF_8)
|
||||
}
|
||||
} ?: run {
|
||||
context.log.error("Failed to load composer loader script")
|
||||
return
|
||||
}
|
||||
val loaderScript = runCatching {
|
||||
context.fileHandlerManager.getFileHandle(FileHandleScope.COMPOSER.key, "loader.js").toWrapper().readBytes().toString(Charsets.UTF_8)
|
||||
}.onFailure {
|
||||
context.log.error("Failed to load composer loader script", it)
|
||||
}.getOrNull() ?: return
|
||||
context.native.setComposerLoader("""
|
||||
(() => { const _getImportsFunctionName = "$getImportsFunctionName"; $loaderScript })();
|
||||
""".trimIndent().trim())
|
||||
|
||||
Reference in New Issue
Block a user