add use_eval()to desktop and web

This commit is contained in:
Ilya Maximov committed 2022-03-17 23:47:11 +01:00
1 parent 08fa2382b0
commit 5cbf2698fd
5 files changed
+48 -2

No files matched your search

+16 -1
View File
@@ -193,6 +193,21 @@ pub(super) fn handler(
DevTool => webview.devtool(),
Eval(code) => webview.evaluate_script(code.as_str()).expect("failed to eval script"),
Eval(code) => webview
.evaluate_script(code.as_str())
.expect("failed to eval script"),
}
}
/// Get a closure that executes any JavaScript in the WebView context.
///
/// # Panics
///
/// The closure will cause the message processing thread to panic if the
/// provided script is not valid JavaScript code or if it returns an uncaught
/// error.
pub fn use_eval<S: std::fmt::Display>(cx: &ScopeState) -> impl Fn(S) + '_ {
let desktop = use_window(&cx);
move |script| desktop.eval(script)
}
+1 -1
View File
@@ -11,7 +11,7 @@ mod events;
mod protocol;
use desktop_context::UserWindowEvent;
pub use desktop_context::{use_window, DesktopContext};
pub use desktop_context::{use_window, use_eval, DesktopContext};
pub use wry;
pub use wry::application as tao;