Skip to content

Commit 68ea653

Browse files
Ngo Iok Ui (Wu Yu Wei)lucasfernog
andauthored
Add eval method to WebviewMut (#59)
* Add eval method to WebviewMut * chore: change is a patch Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 9eb6107 commit 68ea653

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

.changes/eval.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webview": patch
3+
---
4+
5+
Add eval method to WebviewMut

src/webview.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ impl WebviewMut {
181181
Ok(unsafe { sys::webview_get_window(*webview) as *mut Window })
182182
}
183183

184+
185+
pub fn eval(&mut self, js: &str) -> Result<(), Error> {
186+
let webview = self.0.upgrade().ok_or(Error::WebviewNull)?;
187+
let c_js = CString::new(js).expect("No null bytes in parameter js");
188+
unsafe { sys::webview_eval(*webview, c_js.as_ptr()) }
189+
Ok(())
190+
}
191+
184192
pub fn dispatch<F>(&mut self, f: F) -> Result<(), Error>
185193
where
186194
F: FnOnce(&mut Webview) + Send + 'static,

0 commit comments

Comments
 (0)