Forráskód Böngészése

Add back window.apiPromise to prevent race condition.

Ian Walton 3 éve
szülő
commit
9973fd5526
2 módosított fájl, 17 hozzáadás és 10 törlés
  1. 12 8
      native/jmpInputPlugin.js
  2. 5 2
      native/nativeshell.js

+ 12 - 8
native/jmpInputPlugin.js

@@ -18,16 +18,20 @@ class jmpInputPlugin {
         this.type = 'input';
         this.id = 'jmpInputPlugin';
 
-        window.api.input.hostInput.connect((actions) => {
-            actions.forEach(action => {
-                if (remap.hasOwnProperty(action)) {
-                    action = remap[action];
-                }
-                inputManager.handleCommand(action, {});
+        (async () => {
+            const api = await window.apiPromise;
+
+            api.input.hostInput.connect((actions) => {
+                actions.forEach(action => {
+                    if (remap.hasOwnProperty(action)) {
+                        action = remap[action];
+                    }
+                    inputManager.handleCommand(action, {});
+                });
             });
-        });
 
-        window.api.system.hello("jmpInputPlugin");
+            api.system.hello("jmpInputPlugin");
+        })();
     }
 }
 

+ 5 - 2
native/nativeshell.js

@@ -108,8 +108,11 @@ async function createApi() {
 }
 
 window.NativeShell.AppHost = {
-    async init() {
-        window.api = await createApi();
+    init() {
+        window.apiPromise = createApi();
+        (async () => {
+            window.api = await window.apiPromise;
+        })();
     },
     getDefaultLayout() {
         return "desktop";