diff --git a/Cargo.lock b/Cargo.lock index 31fda7c..2a9a9d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,7 +153,7 @@ dependencies = [ [[package]] name = "windows-capture" -version = "1.0.14" +version = "1.0.15" dependencies = [ "log", "parking_lot", diff --git a/Cargo.toml b/Cargo.toml index 4bfc5d0..aeee8be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "windows-capture" -version = "1.0.14" +version = "1.0.15" authors = ["NiiightmareXD"] edition = "2021" description = "Windows Capture Simple Screen Capture for Windows 🔥" diff --git a/src/capture.rs b/src/capture.rs index 1e50343..1fdb208 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use log::error; use parking_lot::Mutex; use thiserror::Error; use windows::{ @@ -110,8 +109,6 @@ impl WindowsCapture { _item.Closed( &TypedEventHandler::::new({ move |_, _| { - error!("Graphics Capture Item Closed Impossible to Continue Capturing"); - trigger_item.lock().on_closed(); unsafe { PostQuitMessage(0) }; diff --git a/src/window.rs b/src/window.rs index e147491..53724d5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,4 +1,5 @@ use log::warn; +use thiserror::Error; use windows::{ core::HSTRING, Graphics::Capture::GraphicsCaptureItem, @@ -15,6 +16,15 @@ use windows::{ }, }; +/// Used To Handle Internal Errors +#[derive(Error, Debug)] +pub enum WindowErrors { + #[error("Failed To Find Window")] + NotFound, + #[error("Unknown Error")] + Unknown, +} + /// Represents A Windows pub struct Window { window: HWND, @@ -33,11 +43,15 @@ impl Window { } /// Create From A Window Name - pub fn from_window_name(title: &str) -> Self { + pub fn from_window_name(title: &str) -> Result> { let title = HSTRING::from(title); let window = unsafe { FindWindowW(None, &title) }; - Self { window } + if window.0 == 0 { + return Err(Box::new(WindowErrors::NotFound)); + } + + Ok(Self { window }) } /// Get Window Title