瀏覽代碼

fix desktop renderer on windows

Evan Almloff 1 年之前
父節點
當前提交
b14aaca7b2
共有 2 個文件被更改,包括 23 次插入10 次删除
  1. 22 9
      packages/desktop/build.rs
  2. 1 1
      packages/desktop/src/webview.rs

+ 22 - 9
packages/desktop/build.rs

@@ -2,6 +2,17 @@ use dioxus_interpreter_js::binary_protocol::SLEDGEHAMMER_JS;
 
 use std::io::Write;
 
+const EDITS_PATH: &str = {
+    #[cfg(any(target_os = "android", target_os = "windows"))]
+    {
+        "http://dioxus.index.html/edits"
+    }
+    #[cfg(not(any(target_os = "android", target_os = "windows")))]
+    {
+        "dioxus://index.html/edits"
+    }
+};
+
 fn main() {
     let prevent_file_upload = r#"// Prevent file inputs from opening the file dialog on click
     let inputs = document.querySelectorAll("input");
@@ -26,21 +37,23 @@ fn main() {
         }
       }
     }"#;
-    let polling_request = r#"// Poll for requests
-    window.interpreter.wait_for_request = () => {
-      fetch(new Request("dioxus://index.html/edits"))
-          .then(response => {
+    let polling_request = format!(
+        r#"// Poll for requests
+    window.interpreter.wait_for_request = () => {{
+      fetch(new Request("{EDITS_PATH}"))
+          .then(response => {{
               response.arrayBuffer()
-                  .then(bytes => {
+                  .then(bytes => {{
                       run_from_bytes(bytes);
                       window.interpreter.wait_for_request();
-                  });
-          })
-    }"#;
+                  }});
+          }})
+    }}"#
+    );
     let mut interpreter = SLEDGEHAMMER_JS
         .replace("/*POST_HANDLE_EDITS*/", prevent_file_upload)
         .replace("export", "")
-        + polling_request;
+        + &polling_request;
     while let Some(import_start) = interpreter.find("import") {
         let import_end = interpreter[import_start..]
             .find(|c| c == ';' || c == '\n')

+ 1 - 1
packages/desktop/src/webview.rs

@@ -7,7 +7,7 @@ pub use wry::application as tao;
 use wry::application::window::Window;
 use wry::webview::{WebContext, WebView, WebViewBuilder};
 
-pub fn build(
+pub(crate) fn build(
     cfg: &mut Config,
     event_loop: &EventLoopWindowTarget<UserWindowEvent>,
     proxy: EventLoopProxy<UserWindowEvent>,