Repository: servo/servo
File: components/script/dom/gamepad/gamepadhapticactuator.rs (Rust)

Code before:
            self.global().task_manager().gamepad_task_source().queue(
                task!(preempt_promise: move || {
                    let promise = trusted_promise.root();
                    let message = DOMString::from("preempted");
                    promise.resolve_native(&message, CanGc::note());
                }),
            );
        }

        if !self.effects.contains(&type_) {
            playing_effect_promise.reject_error(Error::NotSupported(None), can_gc);
            return playing_effect_promise;
        }

        *self.playing_effect_promise.borrow_mut() = Some(playing_effect_promise.clone());
        self.effect_sequence_id.set(self.sequence_id.get());

        let context = Trusted::new(self);
        let listener = HapticEffectListener {
            task_source: self.global().task_manager().gamepad_task_source().into(),
            context,
        };

        let callback = GenericCallback::new(move |message| match message {
            Ok(msg) => listener.handle_completed(msg),
            Err(err) => warn!("Error receiving a GamepadMsg: {:?}", err),
        })
        .expect("Could not create generic callback");

        // Note: The spec says we SHOULD also pass a playEffectTimestamp for more precise playback timing
        // when start_delay is non-zero, but this is left more as a footnote without much elaboration.
        // <https://www.w3.org/TR/gamepad/#dfn-issue-a-haptic-effect>

        let params = DualRumbleEffectParams {
            duration: params.duration as f64,
            start_delay: params.startDelay as f64,
            strong_magnitude: *params.strongMagnitude,
            weak_magnitude: *params.weakMagnitude,
        };
        let event = EmbedderMsg::PlayGamepadHapticEffect(
            document.webview_id(),
            self.gamepad_index as usize,
            embedder_traits::GamepadHapticEffectType::DualRumble(params),
            callback,
        );
        self.global().as_window().send_to_embedder(event);

        playing_effect_promise
    }

    /// <https://www.w3.org/TR/gamepad/#dom-gamepadhapticactuator-reset>

Review comment (suggestion):
```suggestion
            Err(error) => warn!("Error receiving a GamepadMsg: {error:?}"),
```

Code after:
            self.global().task_manager().gamepad_task_source().queue(
                task!(preempt_promise: move || {
                    let promise = trusted_promise.root();
                    let message = DOMString::from("preempted");
                    promise.resolve_native(&message, CanGc::note());
                }),
            );
        }

        if !self.effects.contains(&type_) {
            playing_effect_promise.reject_error(Error::NotSupported(None), can_gc);
            return playing_effect_promise;
        }

        *self.playing_effect_promise.borrow_mut() = Some(playing_effect_promise.clone());
        self.effect_sequence_id.set(self.sequence_id.get());

        let context = Trusted::new(self);
        let listener = HapticEffectListener {
            task_source: self.global().task_manager().gamepad_task_source().into(),
            context,
        };

        let callback = GenericCallback::new(move |message| match message {
            Ok(msg) => listener.handle_completed(msg),
            Err(error) => warn!("Error receiving a GamepadMsg: {error:?}"),
        })
        .expect("Could not create generic callback");

        // Note: The spec says we SHOULD also pass a playEffectTimestamp for more precise playback timing
        // when start_delay is non-zero, but this is left more as a footnote without much elaboration.
        // <https://www.w3.org/TR/gamepad/#dfn-issue-a-haptic-effect>

        let params = DualRumbleEffectParams {
            duration: params.duration as f64,
            start_delay: params.startDelay as f64,
            strong_magnitude: *params.strongMagnitude,
            weak_magnitude: *params.weakMagnitude,
        };
        let event = EmbedderMsg::PlayGamepadHapticEffect(
            document.webview_id(),
            self.gamepad_index as usize,
            embedder_traits::GamepadHapticEffectType::DualRumble(params),
            callback,
        );
        self.global().as_window().send_to_embedder(event);

        playing_effect_promise
    }

    /// <https://www.w3.org/TR/gamepad/#dom-gamepadhapticactuator-reset>