Skip to content

Commit

Permalink
raidboss: prevent duplicate button creation (#5794)
Browse files Browse the repository at this point in the history
created only once, rather than multiple times.
  • Loading branch information
Souma-Sumire authored Sep 15, 2023
1 parent 903e7b5 commit 0cf45db
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ui/raidboss/autoplay_helper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
export default class AutoplayHelper {
private static context?: AudioContext;
private static isButtonCreated = false;

private static getContext(): AudioContext {
AutoplayHelper.context ??= new AudioContext();
return AutoplayHelper.context;
}

static CheckIfAlreadyRunning(): boolean {
// This check will only ever succeed on running Chromium passing
// --autoplay-policy=no-user-gesture-required
// as command line argument or configuring CEF the correct way.
// Once https://bugs.chromium.org/p/chromium/issues/detail?id=1106380
// is fixed this function will return false on every (up-to-date) browser
const context = new AudioContext();
const context = AutoplayHelper.getContext();
return context.state === 'running';
}

static Prompt(): void {
const context = new AudioContext();
if (AutoplayHelper.isButtonCreated) {
return;
}
const context = AutoplayHelper.getContext();
const button = document.createElement('button');
button.innerText = 'Click to enable audio';
button.classList.add('autoplay-helper-button');
Expand All @@ -21,6 +32,7 @@ export default class AutoplayHelper {
button.remove();
};
document.body.appendChild(button);
AutoplayHelper.isButtonCreated = true;
}

static CheckAndPrompt(): void {
Expand Down

0 comments on commit 0cf45db

Please sign in to comment.