chrome_sys/runtime/
mod.rs

1pub mod on_connect;
2pub mod on_message;
3pub mod port;
4pub mod scripting;
5
6use js_sys::Object;
7use port::Port;
8use wasm_bindgen::prelude::*;
9
10#[wasm_bindgen]
11extern "C" {
12    #[wasm_bindgen(extends = Object)]
13    #[derive(Debug)]
14    /// chrome.runtime.connect()
15    ///
16    /// ⧉ [Chrome Documentation](https://developer.chrome.com/docs/extensions/reference/api/runtime#method-connect)
17    ///
18    pub type ConnectInfo;
19
20    #[wasm_bindgen(method, setter, js_name = "name")]
21    pub fn set_name(this: &ConnectInfo, value: String);
22
23    /// chrome.runtime.connect()
24    ///
25    /// ⧉ [Chrome Documentation](https://developer.chrome.com/docs/extensions/reference/api/runtime#method-connect)
26    ///
27    #[wasm_bindgen(js_namespace = ["chrome", "runtime"], js_name="connect")]
28    pub fn connect(info: ConnectInfo) -> Port;
29
30}
31
32impl ConnectInfo {
33    pub fn new(name: &str) -> Self {
34        let this: Self = wasm_bindgen::JsCast::unchecked_into(Object::new());
35
36        this.set_name(name.into());
37        this
38    }
39}