From 8feb8752628cce5bd7758569ed53127705d13ce7 Mon Sep 17 00:00:00 2001 From: Julien Loir <6706489+Namaneo@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:23:39 +0200 Subject: [PATCH] Eheh --- ui/sources/services/audio.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ui/sources/services/audio.js b/ui/sources/services/audio.js index ae8a158..4093b2d 100644 --- a/ui/sources/services/audio.js +++ b/ui/sources/services/audio.js @@ -1,7 +1,7 @@ // Reworked from: https://github.com/chrisd1100/libmatoya/blob/main/src/unix/web/matoya.js export default class Audio { - static #context = new AudioContext(); + static #context = null; static #state = { /** @type {boolean} */ @@ -43,12 +43,6 @@ export default class Audio { static unlock() { window.addEventListener('blur', () => this.#context = null); - window.addEventListener('focus', () => { - this.#context = new AudioContext(); - this.#state.sample_rate = 0; - this.#state.channels = 0; - }); - const unlock = () => this.#context.state == 'suspended' && this.#context.resume(); window.addEventListener('keydown', unlock); window.addEventListener('mousedown', unlock); @@ -63,6 +57,9 @@ export default class Audio { static #update(sampleRate, channels) { const state = this.#state; + if (!this.#context) + this.#context = new AudioContext(); + if (state.sample_rate == sampleRate && state.channels == channels) return;