mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 11:59:59 +03:00
allow deny capture / emulation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use ashpd::desktop::ResponseError;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
@@ -69,6 +70,18 @@ pub enum CaptureCreationError {
|
||||
Windows,
|
||||
}
|
||||
|
||||
impl CaptureCreationError {
|
||||
/// request was intentionally denied by the user
|
||||
pub(crate) fn cancelled_by_user(&self) -> bool {
|
||||
match self {
|
||||
CaptureCreationError::Libei(LibeiCaptureCreationError::Ashpd(
|
||||
ashpd::Error::Response(ResponseError::Cancelled),
|
||||
)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum LibeiCaptureCreationError {
|
||||
|
||||
@@ -162,6 +162,7 @@ pub async fn create(
|
||||
log::info!("using capture backend: {backend}");
|
||||
return Ok(b);
|
||||
}
|
||||
Err(e) if e.cancelled_by_user() => return Err(e),
|
||||
Err(e) => log::warn!("{backend} input capture backend unavailable: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use ashpd::{desktop::ResponseError, Error::Response};
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use reis::tokio::EiConvertEventStreamError;
|
||||
use std::io;
|
||||
@@ -75,6 +76,21 @@ pub enum EmulationCreationError {
|
||||
NoAvailableBackend,
|
||||
}
|
||||
|
||||
impl EmulationCreationError {
|
||||
/// request was intentionally denied by the user
|
||||
pub(crate) fn cancelled_by_user(&self) -> bool {
|
||||
match self {
|
||||
EmulationCreationError::Libei(LibeiEmulationCreationError::Ashpd(Response(
|
||||
ResponseError::Cancelled,
|
||||
)))
|
||||
| EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response(
|
||||
ResponseError::Cancelled,
|
||||
))) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlrootsEmulationCreationError {
|
||||
|
||||
@@ -132,6 +132,7 @@ pub async fn create(
|
||||
log::info!("using emulation backend: {backend}");
|
||||
return Ok(b);
|
||||
}
|
||||
Err(e) if e.cancelled_by_user() => return Err(e),
|
||||
Err(e) => log::warn!("{e}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ use tokio::task::JoinHandle;
|
||||
use ashpd::{
|
||||
desktop::{
|
||||
remote_desktop::{DeviceType, RemoteDesktop},
|
||||
ResponseError, Session,
|
||||
Session,
|
||||
},
|
||||
WindowIdentifier,
|
||||
};
|
||||
@@ -74,30 +74,19 @@ pub struct LibeiEmulation<'a> {
|
||||
async fn get_ei_fd<'a>() -> Result<(RemoteDesktop<'a>, Session<'a>, OwnedFd), ashpd::Error> {
|
||||
let remote_desktop = RemoteDesktop::new().await?;
|
||||
|
||||
// retry when user presses the cancel button
|
||||
let (session, _) = loop {
|
||||
log::debug!("creating session ...");
|
||||
let session = remote_desktop.create_session().await?;
|
||||
log::debug!("creating session ...");
|
||||
let session = remote_desktop.create_session().await?;
|
||||
|
||||
log::debug!("selecting devices ...");
|
||||
remote_desktop
|
||||
.select_devices(&session, DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.await?;
|
||||
log::debug!("selecting devices ...");
|
||||
remote_desktop
|
||||
.select_devices(&session, DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
match remote_desktop
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()
|
||||
{
|
||||
Ok(d) => break (session, d),
|
||||
Err(ashpd::Error::Response(ResponseError::Cancelled)) => {
|
||||
log::warn!("request cancelled!");
|
||||
continue;
|
||||
}
|
||||
e => e?,
|
||||
};
|
||||
};
|
||||
log::info!("requesting permission for input emulation");
|
||||
let _devices = remote_desktop
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
let fd = remote_desktop.connect_to_eis(&session).await?;
|
||||
Ok((remote_desktop, session, fd))
|
||||
|
||||
@@ -29,29 +29,19 @@ impl<'a> DesktopPortalEmulation<'a> {
|
||||
let proxy = RemoteDesktop::new().await?;
|
||||
|
||||
// retry when user presses the cancel button
|
||||
let (session, _) = loop {
|
||||
log::debug!("creating session ...");
|
||||
let session = proxy.create_session().await?;
|
||||
log::debug!("creating session ...");
|
||||
let session = proxy.create_session().await?;
|
||||
|
||||
log::debug!("selecting devices ...");
|
||||
proxy
|
||||
.select_devices(&session, DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.await?;
|
||||
log::debug!("selecting devices ...");
|
||||
proxy
|
||||
.select_devices(&session, DeviceType::Keyboard | DeviceType::Pointer)
|
||||
.await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
match proxy
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()
|
||||
{
|
||||
Ok(d) => break (session, d),
|
||||
Err(ashpd::Error::Response(ResponseError::Cancelled)) => {
|
||||
log::warn!("request cancelled!");
|
||||
continue;
|
||||
}
|
||||
e => e?,
|
||||
};
|
||||
};
|
||||
log::info!("requesting permission for input emulation");
|
||||
let _devices = proxy
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
log::debug!("started session");
|
||||
let session = session;
|
||||
|
||||
Reference in New Issue
Block a user