web_extensions_sys/
sessions.rs

1use crate::tabs::Tab;
2use crate::windows::Window;
3use crate::EventTarget;
4use js_sys::Object;
5use wasm_bindgen::prelude::*;
6
7#[wasm_bindgen]
8extern "C" {
9    #[derive(Debug)]
10    pub type Session;
11
12    #[wasm_bindgen(method, getter, js_name = lastModified)]
13    pub fn last_modified(this: &Session) -> f64;
14
15    #[wasm_bindgen(method, getter)]
16    pub fn tab(this: &Session) -> Option<Tab>;
17
18    #[wasm_bindgen(method, getter)]
19    pub fn window(this: &Session) -> Option<Window>;
20}
21
22#[wasm_bindgen]
23extern "C" {
24    pub type Sessions;
25
26    #[wasm_bindgen(method, getter, js_name = MAX_SESSION_RESULTS)]
27    // TODO is u32 correct ?
28    pub fn max_session_results(this: &Sessions) -> u32;
29
30    #[wasm_bindgen(catch, method, js_name = forgetClosedTab)]
31    pub async fn forget_closed_tab(
32        this: &Sessions,
33        window_id: i32,
34        session_id: &str,
35    ) -> Result<JsValue, JsValue>;
36
37    #[wasm_bindgen(catch, method, js_name = forgetClosedWindow)]
38    pub async fn forget_closed_window(
39        this: &Sessions,
40        session_id: &str,
41    ) -> Result<JsValue, JsValue>;
42
43    #[wasm_bindgen(catch, method, js_name = getRecentlyClosed)]
44    pub async fn get_recently_closed(
45        this: &Sessions,
46        filter: Option<&Object>,
47    ) -> Result<JsValue, JsValue>;
48
49    #[wasm_bindgen(catch, method)]
50    pub async fn restore(this: &Sessions, session_id: &str) -> Result<JsValue, JsValue>;
51
52    #[wasm_bindgen(catch, method, js_name = getTabValue)]
53    pub async fn get_tab_value(this: &Sessions, tab_id: i32, key: &str)
54        -> Result<JsValue, JsValue>;
55
56    #[wasm_bindgen(catch, method, js_name = setTabValue)]
57    pub async fn set_tab_value(
58        this: &Sessions,
59        tab_id: i32,
60        key: &str,
61        value: &JsValue,
62    ) -> Result<JsValue, JsValue>;
63
64    #[wasm_bindgen(catch, method, js_name = removeTabValue)]
65    pub async fn remove_tab_value(
66        this: &Sessions,
67        tab_id: i32,
68        key: &str,
69    ) -> Result<JsValue, JsValue>;
70
71    #[wasm_bindgen(catch, method, js_name = getWindowValue)]
72    pub async fn get_window_value(
73        this: &Sessions,
74        window_id: i32,
75        key: &str,
76    ) -> Result<JsValue, JsValue>;
77
78    #[wasm_bindgen(catch, method, js_name = setWindowValue)]
79    pub async fn set_window_value(
80        this: &Sessions,
81        window_id: i32,
82        key: &str,
83        value: &JsValue,
84    ) -> Result<JsValue, JsValue>;
85
86    #[wasm_bindgen(catch, method, js_name = removeWindowValue)]
87    pub async fn remove_window_value(
88        this: &Sessions,
89        window_id: i32,
90        key: &str,
91    ) -> Result<JsValue, JsValue>;
92
93    #[wasm_bindgen(method, getter, js_name = onChanged)]
94    pub fn on_changed(this: &Sessions) -> EventTarget;
95}