add eval to DesktopContext
This commit is contained in:
1 file changed
+9
@@ -119,6 +119,11 @@ impl DesktopContext {
|
|||||||
pub fn devtool(&self) {
|
pub fn devtool(&self) {
|
||||||
let _ = self.proxy.send_event(DevTool);
|
let _ = self.proxy.send_event(DevTool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// run (evaluate) a script in the WebView context
|
||||||
|
pub fn eval(&self, script: impl std::fmt::Display) {
|
||||||
|
let _ = self.proxy.send_event(Eval(script.to_string()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -144,6 +149,8 @@ pub enum UserWindowEvent {
|
|||||||
SetDecorations(bool),
|
SetDecorations(bool),
|
||||||
|
|
||||||
DevTool,
|
DevTool,
|
||||||
|
|
||||||
|
Eval(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn handler(
|
pub(super) fn handler(
|
||||||
@@ -185,5 +192,7 @@ pub(super) fn handler(
|
|||||||
SetDecorations(state) => window.set_decorations(state),
|
SetDecorations(state) => window.set_decorations(state),
|
||||||
|
|
||||||
DevTool => webview.devtool(),
|
DevTool => webview.devtool(),
|
||||||
|
|
||||||
|
Eval(code) => webview.evaluate_script(code.as_str()).expect("failed to eval script"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user