Skip to content

Commit

Permalink
Better Error Handling 🔥
Browse files Browse the repository at this point in the history
	modified:   Cargo.lock
	modified:   Cargo.toml
	deleted:    Python/WindowsCapture/main.py
	deleted:    Python/windows-capture-native/.gitignore
	deleted:    Python/windows-capture-native/src/lib.rs
	modified:   README.md
	modified:   examples/basic.rs
	modified:   rust-toolchain.toml
	modified:   src/capture.rs
	modified:   src/d3d11.rs
	modified:   src/frame.rs
	modified:   src/graphics_capture_api.rs
	modified:   src/lib.rs
	modified:   src/monitor.rs
	modified:   src/settings.rs
	modified:   src/window.rs
	new file:   windows-capture-python/.gitignore
	renamed:    Python/windows-capture-native/Cargo.lock -> windows-capture-python/Cargo.lock
	renamed:    Python/windows-capture-native/Cargo.toml -> windows-capture-python/Cargo.toml
	renamed:    Python/windows-capture-native/LICENCE -> windows-capture-python/LICENCE
	renamed:    Python/windows-capture-native/pyproject.toml -> windows-capture-python/pyproject.toml
	new file:   windows-capture-python/src/lib.rs
	new file:   windows-capture-python/windows_capture/__init__.py
	new file:   windows-capture-python/windows_capture/windows_capture.cp311-win_amd64.pyd
  • Loading branch information
NiiightmareXD committed Nov 9, 2023
1 parent 4a98d50 commit ec09649
Show file tree
Hide file tree
Showing 24 changed files with 629 additions and 351 deletions.
25 changes: 22 additions & 3 deletions Cargo.lock

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

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "windows-capture"
version = "1.0.23"
version = "1.0.24"
authors = ["NiiightmareXD"]
edition = "2021"
description = "Fastest Windows Screen Capture Library For Rust 🔥"
Expand Down Expand Up @@ -42,9 +42,13 @@ windows = { version = "0.51.1", features = [
"Win32_System_Com",
] }

[workspace]
members = ["Python/windows-capture-native"]
[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
targets = ["x86_64-pc-windows-msvc"]

[[example]]
name = "basic"
doc-scrape-examples = false

[workspace]
members = ["windows-capture-python"]
67 changes: 0 additions & 67 deletions Python/WindowsCapture/main.py

This file was deleted.

1 change: 0 additions & 1 deletion Python/windows-capture-native/.gitignore

This file was deleted.

131 changes: 0 additions & 131 deletions Python/windows-capture-native/src/lib.rs

This file was deleted.

57 changes: 37 additions & 20 deletions 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.22"
windows-capture = "1.0.24"
```
or run this command

Expand All @@ -27,39 +27,53 @@ cargo add windows-capture
## Usage

```rust
use std::error::Error;

use windows_capture::{
capture::WindowsCaptureHandler, frame::Frame, settings::WindowsCaptureSettings, window::Window,
capture::WindowsCaptureHandler,
frame::Frame,
graphics_capture_api::InternalCaptureControl,
settings::{ColorFormat, WindowsCaptureSettings},
window::Window,
};

// Struct To Implement Methods For
struct Capture;

impl WindowsCaptureHandler for Capture {
type Flags = String; // To Get The Message (Or A Variable Or ...) From The Settings
type Flags = String; // To Get The Message From The Settings

fn new(message: Self::Flags) -> Self {
// Function That Will Be Called To Create The Struct The Flags Can Be Passed
// From Settings
// Function That Will Be Called To Create The Struct The Flags Can Be Passed
// From Settings
fn new(message: Self::Flags) -> Result<Self, Box<dyn Error + Send + Sync>> {
println!("Got The Message: {message}");

Self {}
Ok(Self {})
}

fn on_frame_arrived(&mut self, mut frame: Frame) {
// Called Every Time A New Frame Is Available
println!("Got A New Frame");
// Called Every Time A New Frame Is Available
fn on_frame_arrived(
&mut self,
mut frame: Frame,
capture_control: InternalCaptureControl,
) -> Result<(), Box<dyn Error + Send + Sync>> {
println!("New Frame Arrived");

// Save The Frame As An Image To Specified Path
frame.save_as_image("image.png").unwrap();
frame.save_as_image("image.png")?;

// Gracefully Stop The Capture Thread
capture_control.stop();

// Call To Stop The Capture Thread, You Might Receive A Few More Frames
// Before It Stops
self.stop();
Ok(())
}

fn on_closed(&mut self) {
// Called When The Capture Item Closes Usually When The Window Closes,
// Capture Will End After This Function Ends
println!("Capture Item Closed");
// Called When The Capture Item Closes Usually When The Window Closes, Capture
// Will End After This Function Ends
fn on_closed(&mut self) -> Result<(), Box<dyn Error + Send + Sync>> {
println!("Capture Session Closed");

Ok(())
}
}

Expand All @@ -72,13 +86,16 @@ fn main() {
foreground_window,
// Capture Cursor
Some(true),
// Draw Border
// Draw Borders
Some(false),
// This Will Be Passed To The New Function
// Kind Of Pixel Format For Frame To Have
ColorFormat::Rgba8,
// Will Be Passed To The New Function
"It Works".to_string(),
)
.unwrap();

// Every Error From on_closed and on_frame_arrived Will End Up Here
Capture::start(settings).unwrap();
}
```
Expand Down
Loading

0 comments on commit ec09649

Please sign in to comment.