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