浏览代码

fix(tauri) race condition on onTauriInit and no-server mode (#257)

Lucas Fernandes Nogueira 5 年之前
父节点
当前提交
ddd0e2c3eb
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      tauri/src/app/runner.rs

+ 8 - 0
tauri/src/app/runner.rs

@@ -85,7 +85,15 @@ pub(crate) fn run(application: &mut crate::App) {
         webview.eval("
           if (window.onTauriInit !== void 0) {
             window.onTauriInit()
+            window.onTauriInit = void 0
           }
+          Object.defineProperty(window, 'onTauriInit', {
+            set: function(val) {
+              if (typeof(val) === 'function') {
+                val()
+              }
+            }
+          })
         ").expect("failed to evaluate window.onTauriInit");
       } else if !crate::endpoints::handle(webview, arg) {
         application.run_invoke_handler(webview, arg);