Now loading UI and audio settings separately.

This commit is contained in:
Marat Fayzullin 2025-01-01 21:31:46 -05:00
parent 284a283d34
commit 992fd6b2fc
3 changed files with 35 additions and 16 deletions

View File

@ -196,6 +196,10 @@ AudioEngine.prototype.isAllowed = function() {
return this.audioContext.state === 'running'; return this.audioContext.state === 'running';
}; };
AudioEngine.prototype.isStarted = function() {
return this.started;
};
AudioEngine.prototype.reportStats = function() { AudioEngine.prototype.reportStats = function() {
if (this.audioNode.port) { if (this.audioNode.port) {
this.audioNode.port.postMessage(JSON.stringify({cmd:'getStats'})); this.audioNode.port.postMessage(JSON.stringify({cmd:'getStats'}));

View File

@ -37,6 +37,21 @@ UI.loadSettings = function() {
this.setNR(LS.has('nr_threshold')? LS.loadInt('nr_threshold') : false); this.setNR(LS.has('nr_threshold')? LS.loadInt('nr_threshold') : false);
this.toggleNR(LS.has('nr_enabled')? LS.loadBool('nr_enabled') : 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 // Get volume and mute
var volume = LS.has('volume')? LS.loadInt('volume') : 100; var volume = LS.has('volume')? LS.loadInt('volume') : 100;
var muted = LS.has('volumeMuted')? LS.loadInt('volumeMuted') : -1; var muted = LS.has('volumeMuted')? LS.loadInt('volumeMuted') : -1;
@ -55,16 +70,7 @@ UI.loadSettings = function() {
this.toggleMute(false); 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 // Modulation Controls
@ -151,6 +157,9 @@ UI.tuneBookmark = function(b) {
// Set audio volume in 0..150 range. // Set audio volume in 0..150 range.
UI.setVolume = function(x) { UI.setVolume = function(x) {
// Must have running audio engine
if (!audioEngine.isStarted()) return;
x = Math.min(150, Math.max(0, Math.round(parseFloat(x)))); x = Math.min(150, Math.max(0, Math.round(parseFloat(x))));
if (this.volume != x) { if (this.volume != x) {
this.volume = x; this.volume = x;
@ -166,6 +175,9 @@ UI.setVolume = function(x) {
// Toggle audio muting. // Toggle audio muting.
UI.toggleMute = function(on) { UI.toggleMute = function(on) {
// Must have running audio engine
if (!audioEngine.isStarted()) return;
// If no argument given, toggle mute // If no argument given, toggle mute
var toggle = typeof(on) === 'undefined'; var toggle = typeof(on) === 'undefined';
var $muteButton = $('.openwebrx-mute-button'); var $muteButton = $('.openwebrx-mute-button');

View File

@ -978,6 +978,13 @@ function on_ws_recv(evt) {
Utils.setVesselUrl(config['vessel_url']); Utils.setVesselUrl(config['vessel_url']);
} }
// Load user interface settings
UI.loadSettings();
Chat.loadSettings();
// Initialize keyboard shortcuts
Shortcuts.init(document.body);
break; break;
case "secondary_config": case "secondary_config":
var s = json['value']; var s = json['value'];
@ -1208,12 +1215,8 @@ function onAudioStart(apiType){
toggle_panel("openwebrx-panel-log", !!was_error); toggle_panel("openwebrx-panel-log", !!was_error);
}, 2000); }, 2000);
// Load user interface settings from local storage // Load audio settings from local storage
UI.loadSettings(); UI.loadAudioSettings();
Chat.loadSettings();
// Initialize keyboard shortcuts
Shortcuts.init(document.body);
} }
var reconnect_timeout = false; var reconnect_timeout = false;