|
@@ -3,6 +3,10 @@ use webview_rust_sys::Webview;
|
|
|
|
|
|
/// The plugin interface.
|
|
|
pub trait Plugin {
|
|
|
+ /// The JS script to evaluate on init.
|
|
|
+ fn init_script(&self) -> Option<String> {
|
|
|
+ None
|
|
|
+ }
|
|
|
/// Callback invoked when the webview is created.
|
|
|
#[allow(unused_variables)]
|
|
|
fn created(&self, webview: &mut Webview) {}
|
|
@@ -37,6 +41,18 @@ fn run_plugin<T: FnMut(&Box<dyn Plugin>)>(mut callback: T) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+pub(crate) fn init_script() -> String {
|
|
|
+ let mut init = String::new();
|
|
|
+
|
|
|
+ run_plugin(|plugin| {
|
|
|
+ if let Some(init_script) = plugin.init_script() {
|
|
|
+ init.push_str(&format!("(function () {{ {} }})();", init_script));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ init
|
|
|
+}
|
|
|
+
|
|
|
pub(crate) fn created(webview: &mut Webview) {
|
|
|
run_plugin(|ext| {
|
|
|
ext.created(webview);
|