diff --git a/crates/libs/windows/src/core/agile_reference.rs b/crates/libs/windows/src/core/agile_reference.rs index 1eba0baa24..f11876ab4a 100644 --- a/crates/libs/windows/src/core/agile_reference.rs +++ b/crates/libs/windows/src/core/agile_reference.rs @@ -2,27 +2,20 @@ use super::*; use bindings::*; use core::marker::PhantomData; -/// A safe wrapper around WinRT interfaces. -/// -/// Some interfaces are not marked as agile thus then don't implement [`Send`]. -/// These interfaces can be made agile through this `AgileReference`. -pub struct AgileReference { - reference: IAgileReference, - _marker: PhantomData, -} +/// A type representing an agile reference to a COM/WinRT object. +#[repr(transparent)] +#[derive(Clone, PartialEq, Eq)] +pub struct AgileReference(IAgileReference, PhantomData); impl AgileReference { - /// Creates a new wrapper around the reference - pub fn new<'a>(from_ref: &'a T) -> Result - where - &'a T: IntoParam<'a, IUnknown>, - { - unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, from_ref).map(|reference| Self { reference, _marker: Default::default() }) } + /// Creates an agile reference to the object. + pub fn new<'a, O: IntoParam<'a, IUnknown>>(object: O) -> Result { + unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, object).map(|reference| Self(reference, Default::default())) } } - /// Resolves the reference for the current thread. + /// Retrieves a proxy to the target of the `AgileReference` object that may safely be used within any thread context in which get is called. pub fn resolve(&self) -> Result { - unsafe { self.reference.Resolve() } + unsafe { self.0.Resolve() } } } diff --git a/crates/tests/agile_reference/tests/tests.rs b/crates/tests/agile_reference/tests/tests.rs index 673a135614..edcfa174ca 100644 --- a/crates/tests/agile_reference/tests/tests.rs +++ b/crates/tests/agile_reference/tests/tests.rs @@ -4,7 +4,7 @@ use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; #[test] fn test() { let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().unwrap().get().unwrap(); - let reference = AgileReference::new(&manager).unwrap(); + let reference = AgileReference::::new(&manager).unwrap(); let handle = std::thread::spawn(move || { let manager = reference.resolve().unwrap();