feat(scripting): sleep

This commit is contained in:
rhunk 2023-12-27 11:55:29 +01:00
parent fe5c6306e1
commit a249d41887
3 changed files with 19 additions and 4 deletions

View File

@ -39,8 +39,8 @@ class Navigation(
navHostController,
startDestination = startDestination.route,
Modifier.padding(innerPadding),
enterTransition = { fadeIn(tween(200)) },
exitTransition = { fadeOut(tween(200)) }
enterTransition = { fadeIn(tween(100)) },
exitTransition = { fadeOut(tween(100)) }
) {
sections.forEach { (_, instance) ->
instance.navController = navHostController

View File

@ -17,8 +17,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.rhunk.snapenhance.common.scripting.type.ModuleInfo
import me.rhunk.snapenhance.common.scripting.ui.EnumScriptInterface
import me.rhunk.snapenhance.common.scripting.ui.InterfaceManager
@ -49,7 +51,7 @@ class ScriptsSection : Section() {
Card(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp),
.padding(8.dp),
elevation = CardDefaults.cardElevation()
) {
Row(
@ -179,7 +181,11 @@ class ScriptsSection : Section() {
}
LaunchedEffect(Unit) {
syncScripts()
refreshing = true
withContext(Dispatchers.IO) {
syncScripts()
refreshing = false
}
}
val pullRefreshState = rememberPullRefreshState(refreshing, onRefresh = {
@ -230,6 +236,9 @@ class ScriptsSection : Section() {
items(scriptModules.size) { index ->
ModuleItem(scriptModules[index])
}
item {
Spacer(modifier = Modifier.height(200.dp))
}
}
PullRefreshIndicator(

View File

@ -80,6 +80,12 @@ class JSModule(
field.get(obj.unwrap())
}
moduleObject.putFunction("sleep") { args ->
val time = args?.get(0) as? Number ?: return@putFunction Undefined.instance
Thread.sleep(time.toLong())
Undefined.instance
}
moduleObject.putFunction("findClass") {
val className = it?.get(0).toString()
val useModClassLoader = it?.getOrNull(1) as? Boolean ?: false