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        pub const SCREENSHOT: &str = "browser.screenshot";
31    }
32
33    pub mod lxapp {
34        pub const LIST: &str = "lxapp.list";
35        pub const CURRENT: &str = "lxapp.current";
36        pub const INFO: &str = "lxapp.info";
37        pub const PAGES: &str = "lxapp.pages";
38        pub const EVAL: &str = "lxapp.eval";
39        pub const OPEN: &str = "lxapp.open";
40        pub const CLOSE: &str = "lxapp.close";
41        pub const RESTART: &str = "lxapp.restart";
42        pub const UNINSTALL: &str = "lxapp.uninstall";
43    }
44
45    pub mod app {
46        /// Capture a PNG of the host app's window. Accepts an optional
47        /// `window_id` (returned by [`WINDOWS`]) so multi-window desktop
48        /// apps can pick a specific surface; mobile platforms ignore it
49        /// since they have a single foreground window. Returns a JSON
50        /// envelope `{format, size_bytes, data_base64}`.
51        pub const SCREENSHOT: &str = "app.screenshot";
52
53        /// Enumerate the host app's top-level windows. Returns a JSON
54        /// array of `{id, title, focused, main, visible, width, height}`.
55        pub const WINDOWS: &str = "app.windows";
56    }
57
58    pub mod lxapp_page {
59        pub const CURRENT: &str = "lxapp.page.current";
60        pub const LIST: &str = "lxapp.page.list";
61        pub const INFO: &str = "lxapp.page.info";
62        pub const EVAL: &str = "lxapp.page.eval";
63        pub const QUERY: &str = "lxapp.page.query";
64        pub const CLICK: &str = "lxapp.page.click";
65        pub const TYPE: &str = "lxapp.page.type";
66        pub const FILL: &str = "lxapp.page.fill";
67        pub const PRESS: &str = "lxapp.page.press";
68        pub const BACK: &str = "lxapp.page.back";
69        pub const SCREENSHOT: &str = "lxapp.page.screenshot";
70    }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
74#[serde(rename_all = "snake_case")]
75pub enum DevtoolsPeerRole {
76    Devtool,
77    Client,
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
81#[serde(rename_all = "snake_case")]
82pub enum DevtoolsLogLevel {
83    Verbose,
84    Debug,
85    Info,
86    Warn,
87    Error,
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
91#[serde(rename_all = "snake_case")]
92pub enum DevtoolsLogSource {
93    Native,
94    WebViewConsole,
95    LxAppServiceConsole,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct DevtoolsLogMessage {
100    pub timestamp_ms: u64,
101    #[serde(alias = "tag")]
102    pub source: DevtoolsLogSource,
103    pub level: DevtoolsLogLevel,
104    pub appid: Option<String>,
105    pub path: Option<String>,
106    pub message: String,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(tag = "type", rename_all = "snake_case")]
111pub enum DevtoolsWireMessage {
112    Hello {
113        role: DevtoolsPeerRole,
114    },
115    LogBatch {
116        logs: Vec<DevtoolsLogMessage>,
117    },
118    Command {
119        command_id: String,
120        handler: String,
121        #[serde(default, skip_serializing_if = "Option::is_none")]
122        args: Option<serde_json::Value>,
123    },
124    Result {
125        command_id: String,
126        ok: bool,
127        #[serde(default, skip_serializing_if = "Option::is_none")]
128        data: Option<serde_json::Value>,
129        #[serde(default, skip_serializing_if = "Option::is_none")]
130        error: Option<String>,
131    },
132}