fix: window restart error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-12-07 13:49:27 +08:00
parent 7f32062dca
commit 824c440f63
2 changed files with 8 additions and 2 deletions

View File

@ -13,12 +13,14 @@ import java.nio.file.Paths;
* @author 喵♂呜 Created on 2017/10/25 21:01.
*/
public class ScriptEngine {
private final String root;
private final ClassLoader loader;
private final Object logger;
private final String root;
private final Base base;
private MiaoScriptEngine engine;
public ScriptEngine(String root, Object logger, Object instance) {
this.loader = Thread.currentThread().getContextClassLoader();
this.root = root;
this.logger = logger;
this.base = new Base(instance);
@ -38,6 +40,8 @@ public class ScriptEngine {
@SneakyThrows
public void enableEngine() {
createEngine();
ClassLoader originLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.loader);
Path bios = Paths.get(root, "bios.js");
// 如果存在自定义bios就加载自定义的
if (Files.exists(bios)) {
@ -46,6 +50,7 @@ public class ScriptEngine {
this.engine.eval("load('classpath:bios.js')");
}
engine.invokeFunction("boot", root, logger);
Thread.currentThread().setContextClassLoader(originLoader);
}
@SneakyThrows