Fix race condition in upnextdialog that hides the player.

This commit is contained in:
Ian Walton 2021-04-07 22:36:22 -04:00
parent 466098aaec
commit b67a126468

View File

@ -94,13 +94,13 @@ import '../../assets/css/flexstyles.scss';
} }
} }
function onStartNowClick() { async function onStartNowClick() {
const options = this.options; const options = this.options;
if (options) { if (options) {
const player = options.player; const player = options.player;
this.hide(); await this.hide();
playbackManager.nextTrack(player); playbackManager.nextTrack(player);
} }
@ -139,7 +139,7 @@ import '../../assets/css/flexstyles.scss';
Events.trigger(instance, 'hide'); Events.trigger(instance, 'hide');
} }
function hideComingUpNext() { async function hideComingUpNext() {
const instance = this; const instance = this;
clearCountdownTextTimeout(this); clearCountdownTextTimeout(this);
@ -159,17 +159,21 @@ import '../../assets/css/flexstyles.scss';
return; return;
} }
// trigger a reflow to force it to animate again
void elem.offsetWidth;
elem.classList.add('upNextDialog-hidden');
const fn = onHideAnimationComplete.bind(instance); const fn = onHideAnimationComplete.bind(instance);
instance._onHideAnimationComplete = fn; instance._onHideAnimationComplete = fn;
dom.addEventListener(elem, transitionEndEventName, fn, { const e = await new Promise((resolve) => {
once: true dom.addEventListener(elem, transitionEndEventName, resolve, {
once: true
});
// trigger a reflow to force it to animate again
void elem.offsetWidth;
elem.classList.add('upNextDialog-hidden');
}); });
instance._onHideAnimationComplete(e);
} }
function getTimeRemainingMs(instance) { function getTimeRemainingMs(instance) {
@ -226,8 +230,8 @@ class UpNextDialog {
startComingUpNextHideTimer(this); startComingUpNextHideTimer(this);
} }
hide() { async hide() {
hideComingUpNext.call(this); await hideComingUpNext.bind(this)();
} }
destroy() { destroy() {
hideComingUpNext.call(this); hideComingUpNext.call(this);