From d8db9101abeed7b1123af414bd1de4b60b64cd6c Mon Sep 17 00:00:00 2001 From: SegaraRai Date: Tue, 7 May 2024 23:58:20 +0900 Subject: [PATCH 1/2] fix: fix `on_closed` not called when using `start_free_threaded` --- src/capture.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index aaf0cf6..903f14b 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -332,7 +332,7 @@ pub trait GraphicsCaptureApiHandler: Sized { /// # Returns /// /// Returns `Ok(CaptureControl)` if the capture was successful, otherwise returns an error of type `GraphicsCaptureApiError`. - fn start_free_threaded + Send>( + fn start_free_threaded + Send + 'static>( settings: Settings, ) -> Result, GraphicsCaptureApiError> where @@ -342,11 +342,6 @@ pub trait GraphicsCaptureApiHandler: Sized { let (halt_sender, halt_receiver) = mpsc::channel::>(); let (callback_sender, callback_receiver) = mpsc::channel::>>(); - let item = match settings.item.try_into() { - Ok(item) => item, - Err(_) => return Err(GraphicsCaptureApiError::ItemConvertFailed), - }; - let thread_handle = thread::spawn( move || -> Result<(), GraphicsCaptureApiError> { // Initialize WinRT @@ -376,6 +371,9 @@ pub trait GraphicsCaptureApiHandler: Sized { Self::new(settings.flags).map_err(GraphicsCaptureApiError::NewHandlerError)?, )); + let item = settings.item.try_into() + .map_err(|_| GraphicsCaptureApiError::ItemConvertFailed)?; + let mut capture = GraphicsCaptureApi::new( item, callback.clone(), From 88a5b60fde5b2e8312b9536c5fc3227d3f7ca19c Mon Sep 17 00:00:00 2001 From: SegaraRai Date: Wed, 8 May 2024 00:32:58 +0900 Subject: [PATCH 2/2] chore: format --- src/capture.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index 903f14b..7061b66 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -259,10 +259,10 @@ pub trait GraphicsCaptureApiHandler: Sized { Self::new(settings.flags).map_err(GraphicsCaptureApiError::NewHandlerError)?, )); - let item = match settings.item.try_into() { - Ok(item) => item, - Err(_) => return Err(GraphicsCaptureApiError::ItemConvertFailed), - }; + let item = settings + .item + .try_into() + .map_err(|_| GraphicsCaptureApiError::ItemConvertFailed)?; let mut capture = GraphicsCaptureApi::new( item, @@ -371,7 +371,9 @@ pub trait GraphicsCaptureApiHandler: Sized { Self::new(settings.flags).map_err(GraphicsCaptureApiError::NewHandlerError)?, )); - let item = settings.item.try_into() + let item = settings + .item + .try_into() .map_err(|_| GraphicsCaptureApiError::ItemConvertFailed)?; let mut capture = GraphicsCaptureApi::new(