Limit the number of times the range-calibration-failed modal will be shown

This commit is contained in:
Mathias Malmqvist
2025-11-22 22:15:40 +01:00
parent 4693e5a08f
commit 060b24a9f8

View File

@@ -24,6 +24,7 @@ const app = {
last_disable_btn: 0, last_disable_btn: 0,
shownRangeCalibrationWarning: false, shownRangeCalibrationWarning: false,
failedCalibrationCount: 0,
// Calibration method preference // Calibration method preference
centerCalibrationMethod: 'four-step', // 'quick' or 'four-step' centerCalibrationMethod: 'four-step', // 'quick' or 'four-step'
@@ -366,6 +367,7 @@ async function disconnect() {
} }
app.gj = 0; app.gj = 0;
app.disable_btn = 0; app.disable_btn = 0;
app.shownRangeCalibrationWarning = false;
update_disable_btn(); update_disable_btn();
await controller.disconnect(); await controller.disconnect();
@@ -793,8 +795,13 @@ function detectFailedRangeCalibration(changes) {
const hasOpenModals = document.querySelectorAll('.modal.show').length > 0; const hasOpenModals = document.querySelectorAll('.modal.show').length > 0;
if (failedCalibration && !app.shownRangeCalibrationWarning && !hasOpenModals) { if (failedCalibration && !app.shownRangeCalibrationWarning && !hasOpenModals) {
app.failedCalibrationCount++;
localStorage.setItem('failedCalibrationCount', app.failedCalibrationCount.toString());
app.shownRangeCalibrationWarning = true; app.shownRangeCalibrationWarning = true;
show_popup(l("Range calibration appears to have failed. Please try again and make sure you rotate the sticks.")); if (app.failedCalibrationCount <= 6) { // keep it from getting annoying
show_popup(l("Range calibration appears to have failed. Please try again and make sure you rotate the sticks."));
}
} }
} }
@@ -1280,6 +1287,11 @@ function initCalibrationMethod() {
app.rangeCalibrationMethod = savedRangeMethod; app.rangeCalibrationMethod = savedRangeMethod;
} }
const savedFailedCalibrationCount = localStorage.getItem('failedCalibrationCount');
if (savedFailedCalibrationCount) {
app.failedCalibrationCount = parseInt(savedFailedCalibrationCount, 10);
}
updateCalibrationMethodUI(); updateCalibrationMethodUI();
} }
window.nvslock = nvslock; window.nvslock = nvslock;