From 1db43c4751a3b80ce5ee6696c9bb6cd8c8586898 Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Fri, 28 Jun 2024 23:31:42 +0200 Subject: [PATCH] adapt windows + macos error types --- src/capture/error.rs | 23 +++++++++++++++++++++++ src/capture/macos.rs | 7 ++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/capture/error.rs b/src/capture/error.rs index e9bd5eb..4d9d3e0 100644 --- a/src/capture/error.rs +++ b/src/capture/error.rs @@ -18,18 +18,29 @@ pub enum CaptureCreationError { LayerShell(#[from] LayerShellCaptureCreationError), #[cfg(all(unix, feature = "x11", not(target_os = "macos")))] X11(#[from] X11InputCaptureCreationError), + #[cfg(target_os = "macos")] + Macos(#[from] MacOSInputCaptureCreationError), + #[cfg(windows)] + Windows, } impl Display for CaptureCreationError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let reason = match self { + #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] CaptureCreationError::Libei(reason) => { format!("error creating portal backend: {reason}") } + #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] CaptureCreationError::LayerShell(reason) => { format!("error creating layer-shell backend: {reason}") } + #[cfg(all(unix, feature = "x11", not(target_os = "macos")))] CaptureCreationError::X11(e) => format!("{e}"), + #[cfg(target_os = "macos")] + CaptureCreationError::Macos(e) => format!("{e}"), + #[cfg(windows)] + CaptureCreationError::Windows => String::from(""), }; write!(f, "could not create input capture: {reason}") } @@ -115,3 +126,15 @@ impl Display for X11InputCaptureCreationError { write!(f, "X11 input capture is not yet implemented :(") } } +#[cfg(target_os = "macos")] +#[derive(Debug, Error)] +pub enum MacOSInputCaptureCreationError { + NotImplemented, +} + +#[cfg(target_os = "macos")] +impl Display for MacOSInputCaptureCreationError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "macos input capture is not yet implemented :(") + } +} diff --git a/src/capture/macos.rs b/src/capture/macos.rs index f95fbde..2ed044a 100644 --- a/src/capture/macos.rs +++ b/src/capture/macos.rs @@ -1,16 +1,17 @@ use crate::capture::InputCapture; use crate::client::{ClientEvent, ClientHandle}; use crate::event::Event; -use anyhow::{anyhow, Result}; +use anyhow::Result; use futures_core::Stream; use std::task::{Context, Poll}; use std::{io, pin::Pin}; +use crate::capture::error::MacOSInputCaptureCreationError; pub struct MacOSInputCapture; impl MacOSInputCapture { - pub fn new() -> Result { - Err(anyhow!("not yet implemented")) + pub fn new() -> std::result::Result { + Err(MacOSInputCaptureCreationError::NotImplemented) } }