From 992fd6b2fc68b1b8990ea5824ff93bf8eceb3012 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Wed, 1 Jan 2025 21:31:46 -0500 Subject: [PATCH] Now loading UI and audio settings separately. --- htdocs/lib/AudioEngine.js | 4 ++++ htdocs/lib/UI.js | 32 ++++++++++++++++++++++---------- htdocs/openwebrx.js | 15 +++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/htdocs/lib/AudioEngine.js b/htdocs/lib/AudioEngine.js index 9b075d5f..d8399ede 100644 --- a/htdocs/lib/AudioEngine.js +++ b/htdocs/lib/AudioEngine.js @@ -196,6 +196,10 @@ AudioEngine.prototype.isAllowed = function() { return this.audioContext.state === 'running'; }; +AudioEngine.prototype.isStarted = function() { + return this.started; +}; + AudioEngine.prototype.reportStats = function() { if (this.audioNode.port) { this.audioNode.port.postMessage(JSON.stringify({cmd:'getStats'})); diff --git a/htdocs/lib/UI.js b/htdocs/lib/UI.js index 19caa0a3..56de0f7e 100644 --- a/htdocs/lib/UI.js +++ b/htdocs/lib/UI.js @@ -37,6 +37,21 @@ UI.loadSettings = function() { this.setNR(LS.has('nr_threshold')? LS.loadInt('nr_threshold') : false); this.toggleNR(LS.has('nr_enabled')? LS.loadBool('nr_enabled') : false); + // Toggle UI sections + for (section in this.sections) { + var id = 'openwebrx-section-' + section; + var el = document.getElementById(id); + if (el) this.toggleSection(el, + LS.has(id)? LS.loadBool(id) : this.sections[section] + ); + } +}; + +// Load audio settings from local storage. +UI.loadAudioSettings = function() { + // Must have running audio engine + if (!audioEngine.isStarted()) return; + // Get volume and mute var volume = LS.has('volume')? LS.loadInt('volume') : 100; var muted = LS.has('volumeMuted')? LS.loadInt('volumeMuted') : -1; @@ -55,16 +70,7 @@ UI.loadSettings = function() { this.toggleMute(false); } } - - // Toggle UI sections - for (section in this.sections) { - var id = 'openwebrx-section-' + section; - var el = document.getElementById(id); - if (el) this.toggleSection(el, - LS.has(id)? LS.loadBool(id) : this.sections[section] - ); - } -}; +} // // Modulation Controls @@ -151,6 +157,9 @@ UI.tuneBookmark = function(b) { // Set audio volume in 0..150 range. UI.setVolume = function(x) { + // Must have running audio engine + if (!audioEngine.isStarted()) return; + x = Math.min(150, Math.max(0, Math.round(parseFloat(x)))); if (this.volume != x) { this.volume = x; @@ -166,6 +175,9 @@ UI.setVolume = function(x) { // Toggle audio muting. UI.toggleMute = function(on) { + // Must have running audio engine + if (!audioEngine.isStarted()) return; + // If no argument given, toggle mute var toggle = typeof(on) === 'undefined'; var $muteButton = $('.openwebrx-mute-button'); diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index 30679df0..1ee5627e 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -978,6 +978,13 @@ function on_ws_recv(evt) { Utils.setVesselUrl(config['vessel_url']); } + // Load user interface settings + UI.loadSettings(); + Chat.loadSettings(); + + // Initialize keyboard shortcuts + Shortcuts.init(document.body); + break; case "secondary_config": var s = json['value']; @@ -1208,12 +1215,8 @@ function onAudioStart(apiType){ toggle_panel("openwebrx-panel-log", !!was_error); }, 2000); - // Load user interface settings from local storage - UI.loadSettings(); - Chat.loadSettings(); - - // Initialize keyboard shortcuts - Shortcuts.init(document.body); + // Load audio settings from local storage + UI.loadAudioSettings(); } var reconnect_timeout = false;