|
27 | 27 | import java.nio.charset.StandardCharsets; |
28 | 28 | import java.util.ArrayList; |
29 | 29 | import java.util.HashMap; |
30 | | -import java.util.LinkedList; |
31 | | -import java.util.List; |
32 | 30 | import java.util.Map; |
33 | 31 |
|
34 | 32 | import org.jetbrains.annotations.Nullable; |
|
37 | 35 | import co.casterlabs.rakurai.json.Rson; |
38 | 36 | import co.casterlabs.rakurai.json.element.JsonArray; |
39 | 37 | import co.casterlabs.rakurai.json.element.JsonElement; |
| 38 | +import co.casterlabs.rakurai.json.element.JsonNull; |
40 | 39 | import co.casterlabs.rakurai.json.element.JsonObject; |
41 | 40 | import co.casterlabs.rakurai.json.element.JsonString; |
42 | 41 | import dev.webview.webview_java.Webview; |
@@ -66,6 +65,15 @@ public WebviewBridge(@NonNull Webview webview) { |
66 | 65 |
|
67 | 66 | switch (type) { |
68 | 67 | case "INIT": { |
| 68 | + for (Map.Entry<String, JavascriptObject> entry : new ArrayList<>(this.objects.entrySet())) { |
| 69 | + if (!entry.getKey().contains(".")) { |
| 70 | + entry |
| 71 | + .getValue() |
| 72 | + .getInitLines(entry.getKey(), this) |
| 73 | + .forEach(this.webview::eval); |
| 74 | + } |
| 75 | + } |
| 76 | + this.emit("init", JsonNull.INSTANCE); |
69 | 77 | this.webview.eval("console.log('[Webview-Bridge]', 'Bridge init completed.');"); |
70 | 78 | return null; |
71 | 79 | } |
@@ -100,18 +108,7 @@ public WebviewBridge(@NonNull Webview webview) { |
100 | 108 | } |
101 | 109 |
|
102 | 110 | private void rebuildInitScript() { |
103 | | - List<String> linesToExecute = new LinkedList<>(); |
104 | | - linesToExecute.add(bridgeScript); |
105 | | - |
106 | | - for (Map.Entry<String, JavascriptObject> entry : new ArrayList<>(this.objects.entrySet())) { |
107 | | - if (!entry.getKey().contains(".")) { |
108 | | - linesToExecute.addAll( |
109 | | - entry.getValue().getInitLines(entry.getKey(), this) |
110 | | - ); |
111 | | - } |
112 | | - } |
113 | | - |
114 | | - this.webview.setInitScript(String.join("\n", linesToExecute)); |
| 111 | + this.webview.setInitScript(bridgeScript); |
115 | 112 | } |
116 | 113 |
|
117 | 114 | public void defineObject(@NonNull String name, @NonNull JavascriptObject obj) { |
|
0 commit comments