diff --git a/Launcher/runtime/engine/api.js b/Launcher/runtime/engine/api.js index 743170c5..04de7ec2 100644 --- a/Launcher/runtime/engine/api.js +++ b/Launcher/runtime/engine/api.js @@ -95,11 +95,11 @@ function newTask(r) { } function newRequestTask(request) { - return newTask(function() request.request()); + FunctionalBridge.makeRequest(request,) } function startTask(task) { - CommonHelper.newThread("FX Task Thread", true, task).start(); + FunctionalBridge.startTask(task); } function openURL(url) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 883e7ad8..93dc8385 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -212,6 +212,8 @@ public void start(String... args) throws Throwable { throw new IllegalStateException("Launcher has been already started"); Launcher.modulesManager.initModules(); // Load init.js script + FunctionalBridge.worker = new RequestWorker(); + CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker); loadScript(Launcher.API_SCRIPT_FILE); loadScript(Launcher.CONFIG_SCRIPT_FILE); loadScript(Launcher.INIT_SCRIPT_FILE); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 7169ff5b..cc9499e7 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -1,11 +1,14 @@ package ru.gravit.launcher.client; +import javafx.concurrent.Task; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.LegacyLauncherRequest; +import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import ru.gravit.utils.helper.CommonHelper; import java.io.IOException; import java.nio.file.Path; @@ -14,6 +17,8 @@ public class FunctionalBridge { @LauncherAPI public static LauncherSettings settings; + @LauncherAPI + public static RequestWorker worker; @LauncherAPI public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception { @@ -45,4 +50,14 @@ public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, public interface HashedDirRunnable { SignedObjectHolder run() throws Exception; } + @LauncherAPI + public void makeJsonRequest(RequestInterface request, Runnable callback) + { + + } + @LauncherAPI + public void startTask(Task task) + { + worker.queue.offer(task); + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java new file mode 100644 index 00000000..6cfbd202 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher.client; + +import javafx.concurrent.Task; +import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.request.Request; +import ru.gravit.utils.helper.LogHelper; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +public class RequestWorker implements Runnable { + public RequestWorker() + { + queue = new LinkedBlockingQueue<>(64); + } + public BlockingQueue queue; + @Override + public void run() { + while (!Thread.interrupted()) + { + Task task = queue.poll(); + if (task != null) { + task.run(); + } + } + } +}