/// Removes a transform with the given ID.
Removes a transform with the given ID.
Removes a transform with the given ID .
async fn remove_policy_transform(
        &mut self,
        policy_id: PolicyId,
    ) -> policy_base::response::Response {
        // Find the target this policy ID is on.
        let target = self.state.find_policy_target(policy_id).ok_or_else(|| {
            PolicyError::InvalidArgument(
                PolicyType::Audio,
                ARG_POLICY_ID.into(),
                format!("{:?}", policy_id).into(),
            )
        })?;
        // Found a policy.
        let audio_info =
            self.fetch_audio_info().await.map_err(|_| policy_base::response::Error::Unexpected)?;
        // Calculate the current external volume level.
        let stream = audio_info
            .streams
            .iter()
            .find(|stream| stream.stream_type == target)
            .ok_or(policy_base::response::Error::Unexpected)?;
        let external_volume = self.calculate_external_volume(target, stream.user_volume_level);
        // Attempt to remove the policy.
        self.state.remove_policy(policy_id).ok_or_else(|| {
            PolicyError::InvalidArgument(
                PolicyType::Audio,
                ARG_POLICY_ID.into(),
                format!("{:?}", policy_id).into(),
            )
        })?;
        // Persist the policy state.
        self.client_proxy.write_policy(self.state.clone().into(), false).await?;
        // Put the transform into effect, updating internal/external volume levels as needed.
        self.apply_policy_transforms(target, audio_info, external_volume).await?;
        Ok(policy_base::response::Payload::Audio(Response::Policy(policy_id)))
    }
async fn remove_policy_transform ( & mut self , policy_id : PolicyId , ) -> policy_base :: response :: Response { // Find the target this policy ID is on. let target = self . state . find_policy_target ( policy_id ) . ok_or_else ( | | { PolicyError :: InvalidArgument ( PolicyType :: Audio , ARG_POLICY_ID . into ( ) , format ! ( " " policy_id ) . into ( ) , ) } ) ? ; // Found a policy. let audio_info = self . fetch_audio_info ( ) . await . map_err ( | _ | policy_base :: response :: Error :: Unexpected ) ? ; // Calculate the current external volume level. let stream = audio_info . streams . iter ( ) . find ( | stream | stream . stream_type == target ) . ok_or ( policy_base :: response :: Error :: Unexpected ) ? ; let external_volume = self . calculate_external_volume ( target , stream . user_volume_level ) ; // Attempt to remove the policy. self . state . remove_policy ( policy_id ) . ok_or_else ( | | { PolicyError :: InvalidArgument ( PolicyType :: Audio , ARG_POLICY_ID . into ( ) , format ! ( " " policy_id ) . into ( ) , ) } ) ? ; // Persist the policy state. self . client_proxy . write_policy ( self . state . clone ( ) . into ( ) , false ) . await ? ; // Put the transform into effect, updating internal/external volume levels as needed. self . apply_policy_transforms ( target , audio_info , external_volume ) . await ? ; Ok ( policy_base :: response :: Payload :: Audio ( Response :: Policy ( policy_id ) ) ) }
Removes a transform with the given ID.
Removes a transform with the given ID .
&mut self
policy_id
PolicyId