pub fn with_rpc_handler<F>(mut self, handler: F) -> Self
  where
    F: Fn(RpcRequest) -> Option<RpcResponse> + 'static,
  {
    let js = r#"
            (function() {
                function Rpc() {
                    const self = this;
                    this._promises = {};

                    // Private internal function called on error
                    this._error = (id, error) => {
                        if(this._promises[id]){
                            this._promises[id].reject(error);
                            delete this._promises[id];
                        }
                    }

                    // Private internal function called on result
                    this._result = (id, result) => {
                        if(this._promises[id]){
                            this._promises[id].resolve(result);
                            delete this._promises[id];
                        }
                    }

                    // Call remote method and expect a reply from the handler
                    this.call = function(method) {
                        const id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", id, method, params};
                        const promise = new Promise((resolve, reject) => {
                            self._promises[id] = {resolve, reject};
                        });
                        window.external.invoke(JSON.stringify(payload));
                        return promise;
                    }

                    // Send a notification without an `id` so no reply is expected.
                    this.notify = function(method) {
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", method, params};
                        window.external.invoke(JSON.stringify(payload));
                        return Promise.resolve();
                    }
                }
                window.external = window.external || {};
                window.external.rpc = new Rpc();
                window.rpc = window.external.rpc;
            })();
            "#;

    self.initialization_scripts.push(js.to_string());
    self.rpc_handler = Some(Box::new(handler));
    self
  }
/// Set the RPC handler to Communicate between the host Rust code and Javascript on webview.
///
/// The communication is done via [JSON-RPC](https://www.jsonrpc.org). Users can use this to register an incoming
/// request handler and reply with responses that are passed back to Javascript. On the Javascript
/// side the client is exposed via `window.rpc` with two public methods:
///
/// 1. The `call()` function accepts a method name and parameters and expects a reply.
/// 2. The `notify()` function accepts a method name and parameters but does not expect a reply.
///
/// Both functions return promises but `notify()` resolves immediately.
Set the RPC handler to Communicate between the host Rust code and Javascript on webview.
The communication is done via [JSON-RPC]. Users can use this to register an incoming
request handler and reply with responses that are passed back to Javascript. On the Javascript
side the client is exposed via `window.rpc` with two public methods.

1. The `call()` function accepts a method name and parameters and expects a reply.
2. The `notify()` function accepts a method name and parameters but does not expect a reply.

Both functions return promises but `notify()` resolves immediately.
Set the RPC handler to Communicate between the host Rust code and Javascript on webview . The communication is done via [ JSON - RPC ] . Users can use this to register an incoming request handler and reply with responses that are passed back to Javascript . On the Javascript side the client is exposed via ` window . rpc ` with two public methods . 1 . The ` call () ` function accepts a method name and parameters and expects a reply . 2 . The ` notify () ` function accepts a method name and parameters but does not expect a reply . Both functions return promises but ` notify () ` resolves immediately .
pub fn with_rpc_handler<F>(mut self, handler: F) -> Self
  where
    F: Fn(RpcRequest) -> Option<RpcResponse> + 'static,
  {
    let js = r#"
            (function() {
                function Rpc() {
                    const self = this;
                    this._promises = {};
                    // Private internal function called on error
                    this._error = (id, error) => {
                        if(this._promises[id]){
                            this._promises[id].reject(error);
                            delete this._promises[id];
                        }
                    }
                    // Private internal function called on result
                    this._result = (id, result) => {
                        if(this._promises[id]){
                            this._promises[id].resolve(result);
                            delete this._promises[id];
                        }
                    }
                    // Call remote method and expect a reply from the handler
                    this.call = function(method) {
                        const id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", id, method, params};
                        const promise = new Promise((resolve, reject) => {
                            self._promises[id] = {resolve, reject};
                        });
                        window.external.invoke(JSON.stringify(payload));
                        return promise;
                    }
                    // Send a notification without an `id` so no reply is expected.
                    this.notify = function(method) {
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", method, params};
                        window.external.invoke(JSON.stringify(payload));
                        return Promise.resolve();
                    }
                }
                window.external = window.external || {};
                window.external.rpc = new Rpc();
                window.rpc = window.external.rpc;
            })();
            "#;
    self.initialization_scripts.push(js.to_string());
    self.rpc_handler = Some(Box::new(handler));
    self
  }
pub fn with_rpc_handler < F > ( mut self , handler : F ) -> Self where F : Fn ( RpcRequest ) -> Option < RpcResponse > + ' static , { let js = r#"
            (function() {
                function Rpc() {
                    const self = this;
                    this._promises = {};

                    // Private internal function called on error
                    this._error = (id, error) => {
                        if(this._promises[id]){
                            this._promises[id].reject(error);
                            delete this._promises[id];
                        }
                    }

                    // Private internal function called on result
                    this._result = (id, result) => {
                        if(this._promises[id]){
                            this._promises[id].resolve(result);
                            delete this._promises[id];
                        }
                    }

                    // Call remote method and expect a reply from the handler
                    this.call = function(method) {
                        const id = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", id, method, params};
                        const promise = new Promise((resolve, reject) => {
                            self._promises[id] = {resolve, reject};
                        });
                        window.external.invoke(JSON.stringify(payload));
                        return promise;
                    }

                    // Send a notification without an `id` so no reply is expected.
                    this.notify = function(method) {
                        const params = Array.prototype.slice.call(arguments, 1);
                        const payload = {jsonrpc: "2.0", method, params};
                        window.external.invoke(JSON.stringify(payload));
                        return Promise.resolve();
                    }
                }
                window.external = window.external || {};
                window.external.rpc = new Rpc();
                window.rpc = window.external.rpc;
            })();
            "# ; self . initialization_scripts . push ( js . to_string ( ) ) ; self . rpc_handler = Some ( Box :: new ( handler ) ) ; self }
Set the RPC handler to Communicate between the host Rust code and Javascript on webview.
Set the RPC handler to Communicate between the host Rust code and Javascript on webview .
mut self
handler
F
mut self
handler
F