From 440c35e4230efd610ba19d9a38e098f75b799b7d Mon Sep 17 00:00:00 2001 From: rhunk <101876869+rhunk@users.noreply.github.com> Date: Tue, 5 Dec 2023 18:43:41 +0100 Subject: [PATCH] feat(scripting): module.onBeforeApplicationLoad --- .../me/rhunk/snapenhance/common/scripting/JSModule.kt | 6 +++++- .../main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt index 7cd02d8ab..161da228a 100644 --- a/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt +++ b/common/src/main/kotlin/me/rhunk/snapenhance/common/scripting/JSModule.kt @@ -135,7 +135,11 @@ class JSModule( obj.get(key, obj) as? ScriptableObject ?: return@contextScope }.get(split.last(), moduleObject) as? Function ?: return@contextScope - function.call(this, moduleObject, moduleObject, args) + runCatching { + function.call(this, moduleObject, moduleObject, args) + }.onFailure { + scriptRuntime.logger.error("Error while calling function $name", it) + } } } } diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt index b845db204..b1b107187 100644 --- a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt +++ b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt @@ -142,6 +142,7 @@ class SnapEnhance { bridgeClient.registerMessagingBridge(messagingBridge) features.init() scriptRuntime.connect(bridgeClient.getScriptingInterface()) + scriptRuntime.eachModule { callFunction("module.onBeforeApplicationLoad", androidContext) } syncRemote() } }