Update JackServerSettingsDialog.tsx
Trying again + Fire & Forget.
This commit is contained in:
@@ -38,7 +38,7 @@ import DialogContent from '@mui/material/DialogContent';
|
|||||||
import MenuItem from '@mui/material/MenuItem';
|
import MenuItem from '@mui/material/MenuItem';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { PiPedalModel, PiPedalModelFactory } from './PiPedalModel';
|
import { PiPedalModel, PiPedalModelFactory } from './PiPedalModel';
|
||||||
import IconButtonEx from './IconButtonEx';
|
import IconButtonEx from '@mui/icons-material/Refresh';
|
||||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||||
import Checkbox from '@mui/material/Checkbox';
|
import Checkbox from '@mui/material/Checkbox';
|
||||||
import FormControlLabel from '@mui/material/FormControlLabel';
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
||||||
@@ -387,8 +387,9 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Persist the current settings to permanent storage. */
|
/** Persist the current settings to permanent storage. */
|
||||||
saveSettings(settings?: JackServerSettings) {
|
saveSettings(settings?: JackServerSettings): void {
|
||||||
const s = (settings ?? this.state.jackServerSettings).clone();
|
const s = (settings ?? this.state.jackServerSettings).clone();
|
||||||
|
// Fire and forget. Errors will be handled by PiPedalModel's internal error handling (e.g., showAlert).
|
||||||
this.model.setJackServerSettings(s);
|
this.model.setJackServerSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,9 +402,10 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Apply the provided settings to the audio system. */
|
/** Apply the provided settings to the audio system. */
|
||||||
applySettings(settings?: JackServerSettings) {
|
applySettings(settings?: JackServerSettings): void {
|
||||||
const s = (settings ?? this.state.jackServerSettings).clone();
|
const s = (settings ?? this.state.jackServerSettings).clone();
|
||||||
s.valid = true;
|
s.valid = true;
|
||||||
|
// Fire and forget. Errors will be handled by PiPedalModel's internal error handling.
|
||||||
this.model.applyJackServerSettings(s);
|
this.model.applyJackServerSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,6 +434,7 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
releaseDevices() {
|
releaseDevices() {
|
||||||
const dummy = new JackServerSettings();
|
const dummy = new JackServerSettings();
|
||||||
dummy.useDummyAudioDevice();
|
dummy.useDummyAudioDevice();
|
||||||
|
// Fire and forget.
|
||||||
this.model.applyJackServerSettings(dummy);
|
this.model.applyJackServerSettings(dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,8 +532,6 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
super.componentWillUnmount();
|
super.componentWillUnmount();
|
||||||
this.mounted = false;
|
this.mounted = false;
|
||||||
this.stopStatusTimer();
|
this.stopStatusTimer();
|
||||||
// Removed the saveSettings call from here.
|
|
||||||
// Persistence should only happen on explicit OK/PROCEED.
|
|
||||||
if (this.originalJackServerSettings) {
|
if (this.originalJackServerSettings) {
|
||||||
// Revert any unapplied changes when the dialog is unmounted
|
// Revert any unapplied changes when the dialog is unmounted
|
||||||
this.applySettings(this.originalJackServerSettings);
|
this.applySettings(this.originalJackServerSettings);
|
||||||
@@ -602,7 +603,7 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
|
|
||||||
handleApply() {
|
handleApply() {
|
||||||
if (this.state.okEnabled) {
|
if (this.state.okEnabled) {
|
||||||
this.applySettings();
|
this.applySettings(); // Fire and forget
|
||||||
this.startStatusTimer();
|
this.startStatusTimer();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -612,9 +613,9 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
|
|
||||||
const proceedWithOk = () => {
|
const proceedWithOk = () => {
|
||||||
this.ignoreClose = true; // Indicate that the closing is intentional
|
this.ignoreClose = true; // Indicate that the closing is intentional
|
||||||
this.releaseDevices(); // Release devices
|
this.releaseDevices(); // Fire and forget
|
||||||
this.applySettings(); // Apply current settings
|
this.applySettings(); // Fire and forget
|
||||||
this.saveSettings(); // Save settings permanently
|
this.saveSettings(); // Fire and forget
|
||||||
this.originalJackServerSettings = undefined;
|
this.originalJackServerSettings = undefined;
|
||||||
if (this.props.onApply) {
|
if (this.props.onApply) {
|
||||||
this.props.onApply(this.state.jackServerSettings.clone());
|
this.props.onApply(this.state.jackServerSettings.clone());
|
||||||
@@ -638,9 +639,9 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
}
|
}
|
||||||
this.setState({ showDeviceWarning: false, dontShowWarningAgain: false }, () => {
|
this.setState({ showDeviceWarning: false, dontShowWarningAgain: false }, () => {
|
||||||
this.ignoreClose = true;
|
this.ignoreClose = true;
|
||||||
this.releaseDevices();
|
this.releaseDevices(); // Fire and forget
|
||||||
this.applySettings();
|
this.applySettings(); // Fire and forget
|
||||||
this.saveSettings();
|
this.saveSettings(); // Fire and forget
|
||||||
this.originalJackServerSettings = undefined;
|
this.originalJackServerSettings = undefined;
|
||||||
if (this.props.onApply) {
|
if (this.props.onApply) {
|
||||||
this.props.onApply(this.state.jackServerSettings.clone());
|
this.props.onApply(this.state.jackServerSettings.clone());
|
||||||
@@ -692,13 +693,10 @@ const JackServerSettingsDialog = withStyles(
|
|||||||
if (this.ignoreClose) {
|
if (this.ignoreClose) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.releaseDevices();
|
this.releaseDevices(); // Fire and forget
|
||||||
if (this.originalJackServerSettings) {
|
if (this.originalJackServerSettings) {
|
||||||
// Revert any applied settings
|
// Revert any applied settings
|
||||||
this.applySettings(this.originalJackServerSettings);
|
this.applySettings(this.originalJackServerSettings); // Fire and forget
|
||||||
// IMPORTANT: Removed the saveSettings call here.
|
|
||||||
// If the user cancels, we only want to revert the active settings,
|
|
||||||
// not overwrite the permanently saved settings with the old ones.
|
|
||||||
this.originalJackServerSettings = undefined;
|
this.originalJackServerSettings = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user