Update JackServerSettingsDialog.tsx

Simplified code to one function instead of having the same code twice. Making sure close event does not revert a second time.
This commit is contained in:
Extremesecrecy
2025-07-27 11:35:52 -07:00
parent 10a2ae96b8
commit 42c03a9c19
+20 -22
View File
@@ -561,6 +561,18 @@ const JackServerSettingsDialog = withStyles(
this.startStatusTimer(); this.startStatusTimer();
} }
}; };
applyAndPersistSettings(s: JackServerSettings) {
// Accept the new settings so handleClose doesn't revert them
this.originalJackServerSettings = undefined;
// Apply the new settings immediately and persist them.
this.model.applyJackServerSettings(s);
this.model.setJackServerSettings(s);
this.startStatusTimer();
if (this.props.onApply) {
this.props.onApply(s);
}
}
handleOk() { handleOk() {
if (!this.state.okEnabled) return; if (!this.state.okEnabled) return;
if (this.state.jackServerSettings.alsaInputDevice !== this.state.jackServerSettings.alsaOutputDevice if (this.state.jackServerSettings.alsaInputDevice !== this.state.jackServerSettings.alsaOutputDevice
@@ -568,17 +580,9 @@ const JackServerSettingsDialog = withStyles(
this.setState({ showDeviceWarning: true }); this.setState({ showDeviceWarning: true });
return; return;
} }
let s = this.state.jackServerSettings.clone(); let s = this.state.jackServerSettings.clone();
s.valid = true; s.valid = true;
// Accept the new settings so handleClose doesn't revert this.applyAndPersistSettings(s);
this.originalJackServerSettings = undefined;
// Apply the new settings immediately and persist them.
this.model.applyJackServerSettings(s);
this.model.setJackServerSettings(s);
if (this.props.onApply) {
this.props.onApply(s);
}
}; };
@@ -591,14 +595,7 @@ const JackServerSettingsDialog = withStyles(
this.setState({ showDeviceWarning: false, dontShowWarningAgain: false }, () => { this.setState({ showDeviceWarning: false, dontShowWarningAgain: false }, () => {
let s = this.state.jackServerSettings.clone(); let s = this.state.jackServerSettings.clone();
s.valid = true; s.valid = true;
// Accept the new settings so the dialog won't revert them on close this.applyAndPersistSettings(s);
this.originalJackServerSettings = undefined;
// Apply and persist the settings just like the OK handler
this.model.applyJackServerSettings(s);
this.model.setJackServerSettings(s);
if (this.props.onApply) {
this.props.onApply(s);
}
}); });
} }
handleWarningCancel() { handleWarningCancel() {
@@ -641,11 +638,12 @@ const JackServerSettingsDialog = withStyles(
const handleClose = () => { const handleClose = () => {
if (this.originalJackServerSettings) { if (this.originalJackServerSettings) {
// Revert any applied settings by restoring the // Revert the temporary settings. The dialog is being closed
// persisted configuration and re-applying it. // without OK, so restore the previous configuration.
this.model.applyJackServerSettings(this.originalJackServerSettings); this.model.applyJackServerSettings(this.originalJackServerSettings);
this.model.setJackServerSettings(this.originalJackServerSettings); this.model.setJackServerSettings(this.originalJackServerSettings);
// Prevent componentWillUnmount from reverting again.
this.originalJackServerSettings = undefined;
} }
onClose(); onClose();
}; };