Skip to content

Commit

Permalink
Added Method To Check For Support 🎉
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   README.md
	modified:   src/graphics_capture_api.rs
	modified:   src/lib.rs
  • Loading branch information
NiiightmareXD committed Oct 28, 2023
1 parent f200b66 commit 8bb1665
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windows-capture"
version = "1.0.20"
version = "1.0.21"
authors = ["NiiightmareXD"]
edition = "2021"
description = "Simple Windows Screen Capture Library For Rust And Python 🔥"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Add this library to your `Cargo.toml`:

```toml
[dependencies]
windows-capture = "1.0.20"
windows-capture = "1.0.21"
```
or run this command

Expand Down
32 changes: 28 additions & 4 deletions src/graphics_capture_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum WindowsCaptureError {
CaptureClosed,
}

/// Internal Capture Struct
/// Struct To Use For Graphics Capture Api
pub struct GraphicsCaptureApi {
_item: GraphicsCaptureItem,
_d3d_device: ID3D11Device,
Expand All @@ -65,7 +65,7 @@ pub struct GraphicsCaptureApi {
}

impl GraphicsCaptureApi {
/// Create A New Internal Capture Item
/// Create A New Graphics Capture Api Struct
pub fn new<T: WindowsCaptureHandler + std::marker::Send + 'static>(
item: GraphicsCaptureItem,
callback: T,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl GraphicsCaptureApi {
})
}

/// Start Internal Capture
/// Start Capture
pub fn start_capture(
&mut self,
capture_cursor: Option<bool>,
Expand Down Expand Up @@ -319,7 +319,7 @@ impl GraphicsCaptureApi {
Ok(())
}

/// Stop Internal Capture
/// Stop Capture
pub fn stop_capture(&mut self) {
self.closed = true;

Expand All @@ -331,6 +331,30 @@ impl GraphicsCaptureApi {
session.Close().expect("Failed to Close Capture Session");
}
}

/// Check If Windows Graphics Capture Api Is Supported
pub fn is_supported() -> Result<bool, Box<dyn std::error::Error>> {
Ok(ApiInformation::IsApiContractPresentByMajor(
&HSTRING::from("Windows.Foundation.UniversalApiContract"),
8,
)?)
}

/// Check If You Can Toggle The Cursor On Or Off
pub fn is_cursor_toggle_supported() -> Result<bool, Box<dyn std::error::Error>> {
Ok(ApiInformation::IsPropertyPresent(
&HSTRING::from("Windows.Graphics.Capture.GraphicsCaptureSession"),
&HSTRING::from("IsCursorCaptureEnabled"),
)?)
}

/// Check If You Can Toggle The Border On Or Off
pub fn is_border_toggle_supported() -> Result<bool, Box<dyn std::error::Error>> {
Ok(ApiInformation::IsPropertyPresent(
&HSTRING::from("Windows.Graphics.Capture.GraphicsCaptureSession"),
&HSTRING::from("IsBorderRequired"),
)?)
}
}

impl Drop for GraphicsCaptureApi {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! ```toml
//! [dependencies]
//! windows-capture = "1.0.20"
//! windows-capture = "1.0.21"
//! ```
//! or run this command
//!
Expand Down

0 comments on commit 8bb1665

Please sign in to comment.