mirror of
https://github.com/harivansh-afk/deskctl.git
synced 2026-04-15 03:00:45 +00:00
fix helper
This commit is contained in:
parent
3ca6c90eaf
commit
9bfada8b4b
1 changed files with 22 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ use std::os::unix::net::UnixListener;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
|
use std::thread;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
|
|
@ -60,8 +61,7 @@ pub struct FixtureWindow {
|
||||||
|
|
||||||
impl FixtureWindow {
|
impl FixtureWindow {
|
||||||
pub fn create(title: &str, app_class: &str) -> Result<Self> {
|
pub fn create(title: &str, app_class: &str) -> Result<Self> {
|
||||||
let (conn, screen_num) =
|
let (conn, screen_num) = connect_to_test_display()?;
|
||||||
x11rb::connect(None).context("Failed to connect to the integration test display")?;
|
|
||||||
let screen = &conn.setup().roots[screen_num];
|
let screen = &conn.setup().roots[screen_num];
|
||||||
let window = conn.generate_id()?;
|
let window = conn.generate_id()?;
|
||||||
|
|
||||||
|
|
@ -103,6 +103,26 @@ impl FixtureWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn connect_to_test_display() -> Result<(RustConnection, usize)> {
|
||||||
|
let max_attempts = 10;
|
||||||
|
let mut last_error = None;
|
||||||
|
|
||||||
|
for attempt in 0..max_attempts {
|
||||||
|
match x11rb::connect(None) {
|
||||||
|
Ok(connection) => return Ok(connection),
|
||||||
|
Err(error) => {
|
||||||
|
last_error = Some(anyhow!(error));
|
||||||
|
if attempt + 1 < max_attempts {
|
||||||
|
thread::sleep(std::time::Duration::from_millis(100 * (attempt + 1) as u64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(last_error.expect("x11 connection attempts should capture an error"))
|
||||||
|
.context("Failed to connect to the integration test display")
|
||||||
|
}
|
||||||
|
|
||||||
impl Drop for FixtureWindow {
|
impl Drop for FixtureWindow {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = self.conn.destroy_window(self.window);
|
let _ = self.conn.destroy_window(self.window);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue