Compare commits
3 Commits
09342acb01
...
38e826b454
Author | SHA1 | Date |
---|---|---|
|
38e826b454 | |
|
ebb5318390 | |
|
311e73e097 |
|
@ -90,6 +90,30 @@ pub struct CloseWindowParams {
|
||||||
pub handle: String,
|
pub handle: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub enum WindowType {
|
||||||
|
Window,
|
||||||
|
Tab,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct NewWindowParams {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub window_type: WindowType,
|
||||||
|
pub focus: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct NewWindowResponse {
|
||||||
|
pub handle: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -98,6 +122,16 @@ pub struct SwitchToWindowParams {
|
||||||
pub focus: bool,
|
pub focus: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct WindowRect {
|
||||||
|
pub x: Option<i32>,
|
||||||
|
pub y: Option<i32>,
|
||||||
|
pub height: Option<u32>,
|
||||||
|
pub width: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(tag = "command", content = "params")]
|
#[serde(tag = "command", content = "params")]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
@ -114,7 +148,11 @@ pub enum Command {
|
||||||
#[serde(rename = "WebDriver:CloseWindow")]
|
#[serde(rename = "WebDriver:CloseWindow")]
|
||||||
CloseWindow(CloseWindowParams),
|
CloseWindow(CloseWindowParams),
|
||||||
#[serde(rename = "WebDriver:NewWindow")]
|
#[serde(rename = "WebDriver:NewWindow")]
|
||||||
NewWindow,
|
NewWindow(NewWindowParams),
|
||||||
#[serde(rename = "WebDriver:SwitchToWindow")]
|
#[serde(rename = "WebDriver:SwitchToWindow")]
|
||||||
SwitchToWindow(SwitchToWindowParams),
|
SwitchToWindow(SwitchToWindowParams),
|
||||||
|
#[serde(rename = "WebDriver:FullscreenWindow")]
|
||||||
|
FullscreenWindow,
|
||||||
|
#[serde(rename = "WebDriver:SetWindowRect")]
|
||||||
|
SetWindowRect(WindowRect),
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ pub use error::{CommandError, ConnectionError, ErrorResponse, MessageError};
|
||||||
use message::{
|
use message::{
|
||||||
CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse,
|
CloseWindowParams, Command, GetCurrentUrlResponse, GetTitleResponse,
|
||||||
Hello, NavigateParams, NewSessionParams, NewSessionResponse,
|
Hello, NavigateParams, NewSessionParams, NewSessionResponse,
|
||||||
SwitchToWindowParams,
|
NewWindowParams, NewWindowResponse, SwitchToWindowParams, WindowRect,
|
||||||
|
WindowType,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
@ -183,6 +184,16 @@ impl Marionette {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn fullscreen(&mut self) -> Result<(), CommandError> {
|
||||||
|
let res: serde_json::Value = self
|
||||||
|
.conn
|
||||||
|
.send_message(Command::FullscreenWindow)
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
|
debug!("Received message: {:?}", res);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_title(&mut self) -> Result<String, CommandError> {
|
pub async fn get_title(&mut self) -> Result<String, CommandError> {
|
||||||
let res: GetTitleResponse =
|
let res: GetTitleResponse =
|
||||||
self.conn.send_message(Command::GetTitle).await?.unwrap();
|
self.conn.send_message(Command::GetTitle).await?.unwrap();
|
||||||
|
@ -240,9 +251,40 @@ impl Marionette {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_window(&mut self) -> Result<String, CommandError> {
|
pub async fn new_window(
|
||||||
let res: String =
|
&mut self,
|
||||||
self.conn.send_message(Command::NewWindow).await?.unwrap();
|
window_type: WindowType,
|
||||||
|
focus: bool,
|
||||||
|
) -> Result<String, CommandError> {
|
||||||
|
let res: NewWindowResponse = self
|
||||||
|
.conn
|
||||||
|
.send_message(Command::NewWindow(NewWindowParams {
|
||||||
|
window_type,
|
||||||
|
focus,
|
||||||
|
}))
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
|
debug!("Received message: {:?}", res);
|
||||||
|
Ok(res.handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_window_rect(
|
||||||
|
&mut self,
|
||||||
|
x: Option<i32>,
|
||||||
|
y: Option<i32>,
|
||||||
|
height: Option<u32>,
|
||||||
|
width: Option<u32>,
|
||||||
|
) -> Result<WindowRect, CommandError> {
|
||||||
|
let res: WindowRect = self
|
||||||
|
.conn
|
||||||
|
.send_message(Command::SetWindowRect(WindowRect {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
}))
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
debug!("Received message: {:?}", res);
|
debug!("Received message: {:?}", res);
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,6 @@ pub struct Monitor {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
pub x: i32,
|
||||||
|
pub y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use tracing::{debug, error, info, trace, warn};
|
||||||
use crate::browser::{Browser, BrowserError};
|
use crate::browser::{Browser, BrowserError};
|
||||||
use crate::config::Configuration;
|
use crate::config::Configuration;
|
||||||
use crate::marionette::error::{CommandError, ConnectionError};
|
use crate::marionette::error::{CommandError, ConnectionError};
|
||||||
|
use crate::marionette::message::WindowType;
|
||||||
use crate::marionette::{Marionette, MarionetteConnection};
|
use crate::marionette::{Marionette, MarionetteConnection};
|
||||||
use crate::monitor::Monitor;
|
use crate::monitor::Monitor;
|
||||||
use crate::mqtt::{Message, MqttClient, MqttPublisher};
|
use crate::mqtt::{Message, MqttClient, MqttPublisher};
|
||||||
|
@ -140,10 +141,28 @@ impl Session {
|
||||||
let mut windowmap = HashMap::new();
|
let mut windowmap = HashMap::new();
|
||||||
let mut window = Some(handles.remove(handles.len() - 1));
|
let mut window = Some(handles.remove(handles.len() - 1));
|
||||||
for monitor in monitors {
|
for monitor in monitors {
|
||||||
|
debug!(
|
||||||
|
"Creating window for monitor {}: {}x{} ({}, {})",
|
||||||
|
monitor.name,
|
||||||
|
monitor.width,
|
||||||
|
monitor.height,
|
||||||
|
monitor.x,
|
||||||
|
monitor.y
|
||||||
|
);
|
||||||
if window.is_none() {
|
if window.is_none() {
|
||||||
window = Some(self.marionette.new_window().await?);
|
window = Some(
|
||||||
|
self.marionette
|
||||||
|
.new_window(WindowType::Window, false)
|
||||||
|
.await?,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
windowmap.insert(monitor.name, window.take().unwrap());
|
let w = window.take().unwrap();
|
||||||
|
self.marionette.switch_to_window(w.clone(), false).await?;
|
||||||
|
self.marionette
|
||||||
|
.set_window_rect(Some(monitor.x), Some(monitor.y), None, None)
|
||||||
|
.await?;
|
||||||
|
self.marionette.fullscreen().await?;
|
||||||
|
windowmap.insert(monitor.name, w);
|
||||||
}
|
}
|
||||||
trace!("Built window map: {:?}", windowmap);
|
trace!("Built window map: {:?}", windowmap);
|
||||||
Ok(windowmap)
|
Ok(windowmap)
|
||||||
|
@ -215,6 +234,8 @@ fn get_monitors() -> Vec<Monitor> {
|
||||||
name: m.name().unwrap().to_string(),
|
name: m.name().unwrap().to_string(),
|
||||||
width: m.width(),
|
width: m.width(),
|
||||||
height: m.height(),
|
height: m.height(),
|
||||||
|
x: m.x(),
|
||||||
|
y: m.y(),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,14 @@ impl XMonitor {
|
||||||
pub fn name(&self) -> Option<&str> {
|
pub fn name(&self) -> Option<&str> {
|
||||||
Some(&self.name)
|
Some(&self.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn x(&self) -> i32 {
|
||||||
|
self.monitor.x as i32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn y(&self) -> i32 {
|
||||||
|
self.monitor.y as i32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return information about the monitors attached to an X display
|
/// Return information about the monitors attached to an X display
|
||||||
|
|
Loading…
Reference in New Issue