Skip to content

Two belling fixes#12281

Merged
11 commits merged intomainfrom
dev/migrie/b/must-fix-honks
Jan 31, 2022
Merged

Two belling fixes#12281
11 commits merged intomainfrom
dev/migrie/b/must-fix-honks

Conversation

@zadjii-msft
Copy link
Member

Sorry for combining two fixes in one PR. I can separate if need be.

  • Closes Can't override bell sound? #12276:
    • "bellSound": null didn't work. This one was easier, and is atomically in bcc2ca0. Basically, we would deserialize that as an array with a single empty string in it, which we'd try to then play. I think it's more idomatic to have that deserialized as an empty array, which correctly falls back to playing the default sound.
  • Closes Pressing Media keys in terminal after changing bell sound replays the bell #12258:
    • This one is the majority of the rest of the PR. If you leave the MediaPlayer open, then the media keys will affect the Terminal. More importantly, once the bell sounds, they'd replay the bell, which is insane. So the fix is to re-create the media player when we need it. We do this per-pane for simpler lifetime tracking. I'm not worried about the overhead of creating a mediaplayer here, since we're already throttling bells.
  • Originally added in Enable changing the bell sound #11511
  • Tested manually
    • Use no.mp4 for this since that's like, 17s long
    • Checked that closing panes / the terminal while a bell was playing didn't crash
    • Playing a bunch of bells at once works
    • closing a pane stops the bell it's playing
    • once the bell stops, the media keys went back to working for Spotify
  • I work here

@ghost ghost added Area-Settings Issues related to settings and customizability, for console or terminal Area-UserInterface Issues pertaining to the user interface of the Console or Terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels Jan 28, 2022
@zadjii-msft zadjii-msft added this to the Terminal v1.13 milestone Jan 28, 2022
Comment on lines +1038 to +1042
// GH#12258: We learned that if you leave the MediaPlayer open, and
// press the media keys (like play/pause), then the OS will _replay the
// bell_. So we have to re-create the MediaPlayer each time we want to
// play the bell, to make sure a subsequent play doesn't come through
// and reactivate the old one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this kinda BODGY and we should upstream the request for this? AFAIK MediaPlayer is THE way to be playing sounds/media now and not some legacy API so it should offer a way of not having it get captured by the media overlay controls.

// We need to make sure clear out the current track
// that's being played, again, so that the system can't
// come through and replay it. In testing, we needed to
// do this, closing the MediaPlayer alone wasn't good
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is seriously BODGY too.

winrt::fire_and_forget Pane::_playBellSound(winrt::Windows::Foundation::Uri uri)
{
auto weakThis{ shared_from_this() };
std::weak_ptr<Pane> weakThis{ shared_from_this() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI there is a weak_from_this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gods I coulda swore that didn't compile


// This lambda will clean up the bell player when we're done with it.
std::weak_ptr<Pane> weakThis2{ shared_from_this() };
_mediaEndedRevoker = _bellPlayer.MediaEnded(winrt::auto_revoke, [weakThis2](auto&&, auto&&) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what series of callbacks do we get for multiple bells?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you bell while another is playing (in this pane), we'll stop the first bell and replace it with the second one, and only get MediaEnded when the last bell in that pane comes to an end.

@zadjii-msft zadjii-msft added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 31, 2022
@ghost
Copy link

ghost commented Jan 31, 2022

Hello @zadjii-msft!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit b1ace96 into main Jan 31, 2022
@ghost ghost deleted the dev/migrie/b/must-fix-honks branch January 31, 2022 13:34
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Settings Issues related to settings and customizability, for console or terminal Area-UserInterface Issues pertaining to the user interface of the Console or Terminal AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't override bell sound? Pressing Media keys in terminal after changing bell sound replays the bell

3 participants