Skip to main content

lingxia_devtool_protocol/
lib.rs

1use serde::{Deserialize, Serialize};
2
3pub mod handlers {
4    pub const ECHO: &str = "echo";
5
6    pub mod browser {
7        pub const OPEN: &str = "browser.open";
8        pub const TABS: &str = "browser.tabs";
9        pub const CURRENT: &str = "browser.current";
10        pub const ACTIVATE: &str = "browser.activate";
11        pub const CLOSE: &str = "browser.close";
12        pub const RELOAD: &str = "browser.reload";
13        pub const BACK: &str = "browser.back";
14        pub const FORWARD: &str = "browser.forward";
15        pub const EVAL: &str = "browser.eval";
16        pub const QUERY: &str = "browser.query";
17        pub const WAIT: &str = "browser.wait";
18        pub const WAIT_URL: &str = "browser.wait_url";
19        pub const WAIT_NAVIGATION: &str = "browser.wait_navigation";
20        pub const CLICK: &str = "browser.click";
21        pub const TYPE: &str = "browser.type";
22        pub const FILL: &str = "browser.fill";
23        pub const PRESS: &str = "browser.press";
24        pub const SCROLL: &str = "browser.scroll";
25        pub const SCROLL_TO: &str = "browser.scroll_to";
26        pub const COOKIES_LIST: &str = "browser.cookies.list";
27        pub const COOKIES_SET: &str = "browser.cookies.set";
28        pub const COOKIES_DELETE: &str = "browser.cookies.delete";
29        pub const COOKIES_CLEAR: &str = "browser.cookies.clear";
30    }
31
32    pub mod lxapp {
33        pub const LIST: &str = "lxapp.list";
34        pub const CURRENT: &str = "lxapp.current";
35        pub const INFO: &str = "lxapp.info";
36        pub const PAGES: &str = "lxapp.pages";
37        pub const EVAL: &str = "lxapp.eval";
38        pub const OPEN: &str = "lxapp.open";
39        pub const CLOSE: &str = "lxapp.close";
40        pub const RESTART: &str = "lxapp.restart";
41        pub const UNINSTALL: &str = "lxapp.uninstall";
42    }
43
44    pub mod lxapp_page {
45        pub const CURRENT: &str = "lxapp.page.current";
46        pub const LIST: &str = "lxapp.page.list";
47        pub const INFO: &str = "lxapp.page.info";
48        pub const EVAL: &str = "lxapp.page.eval";
49        pub const QUERY: &str = "lxapp.page.query";
50        pub const CLICK: &str = "lxapp.page.click";
51        pub const TYPE: &str = "lxapp.page.type";
52        pub const FILL: &str = "lxapp.page.fill";
53        pub const PRESS: &str = "lxapp.page.press";
54        pub const BACK: &str = "lxapp.page.back";
55    }
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
59#[serde(rename_all = "snake_case")]
60pub enum DevtoolsPeerRole {
61    Devtool,
62    Client,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
66#[serde(rename_all = "snake_case")]
67pub enum DevtoolsLogLevel {
68    Verbose,
69    Debug,
70    Info,
71    Warn,
72    Error,
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
76#[serde(rename_all = "snake_case")]
77pub enum DevtoolsLogSource {
78    Native,
79    WebViewConsole,
80    LxAppServiceConsole,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct DevtoolsLogMessage {
85    pub timestamp_ms: u64,
86    #[serde(alias = "tag")]
87    pub source: DevtoolsLogSource,
88    pub level: DevtoolsLogLevel,
89    pub appid: Option<String>,
90    pub path: Option<String>,
91    pub message: String,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(tag = "type", rename_all = "snake_case")]
96pub enum DevtoolsWireMessage {
97    Hello {
98        role: DevtoolsPeerRole,
99    },
100    LogBatch {
101        logs: Vec<DevtoolsLogMessage>,
102    },
103    Command {
104        command_id: String,
105        handler: String,
106        #[serde(default, skip_serializing_if = "Option::is_none")]
107        args: Option<serde_json::Value>,
108    },
109    Result {
110        command_id: String,
111        ok: bool,
112        #[serde(default, skip_serializing_if = "Option::is_none")]
113        data: Option<serde_json::Value>,
114        #[serde(default, skip_serializing_if = "Option::is_none")]
115        error: Option<String>,
116    },
117}