Skip to content

Commit 27e7308

Browse files
committed
Fix save connection handling and cleanup unused code
1 parent f3fd4c4 commit 27e7308

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

src/components/tabs/ConfigurationTab.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ import FC from "../../js/fc";
519519
import MSP from "../../js/msp";
520520
import MSPCodes from "../../js/msp/MSPCodes";
521521
import { mspHelper } from "../../js/msp/MSPHelper";
522+
import { reinitializeConnection } from "../../js/serial_backend";
523+
import { gui_log } from "../../js/gui_log";
522524
import { i18n } from "../../js/localization";
523525
import { sensorTypes } from "../../js/sensor_types"; // Import for dropdown lists
524526
import { have_sensor } from "../../js/sensor_helpers";
@@ -883,6 +885,7 @@ export default defineComponent({
883885
const saveConfig = async () => {
884886
try {
885887
console.log("Saving configuration...");
888+
gui_log("Saving...");
886889
887890
FC.PID_ADVANCED_CONFIG.gyro_sync_denom = pidAdvancedConfig.gyro_sync_denom;
888891
FC.PID_ADVANCED_CONFIG.pid_process_denom = pidAdvancedConfig.pid_process_denom;
@@ -973,13 +976,17 @@ export default defineComponent({
973976
);
974977
}
975978
976-
GUI.log(i18n.getMessage("configurationSaved"));
979+
gui_log(i18n.getMessage("configurationSaved"));
977980
978981
// Save to EEPROM and Reboot
979-
mspHelper.writeConfiguration(true);
982+
mspHelper.writeConfiguration(false, () => {
983+
GUI.tab_switch_cleanup(() => {
984+
reinitializeConnection();
985+
});
986+
});
980987
} catch (e) {
981988
console.error("Failed to save configuration", e);
982-
GUI.log(i18n.getMessage("configurationSaveFailed"));
989+
gui_log(i18n.getMessage("configurationSaveFailed"));
983990
}
984991
};
985992

src/js/main.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import CliAutoComplete from "./CliAutoComplete.js";
1313
import DarkTheme, { setDarkTheme } from "./DarkTheme.js";
1414
import { isExpertModeEnabled } from "./utils/isExpertModeEnabled.js";
1515
import { updateTabList } from "./utils/updateTabList.js";
16-
import { mountVueTab } from "./vue_tab_mounter.js";
16+
import { mountVueTab, unmountVueTab } from "./vue_tab_mounter.js";
1717
import * as THREE from "three";
1818
import NotificationManager from "./utils/notifications.js";
1919

@@ -27,11 +27,7 @@ import("./msp/debug/msp_debug_tools.js")
2727
console.warn("Failed to load MSP debug tools:", err);
2828
});
2929

30-
if (typeof String.prototype.replaceAll === "undefined") {
31-
String.prototype.replaceAll = function (match, replace) {
32-
return this.replace(new RegExp(match, "g"), () => replace);
33-
};
34-
}
30+
3531

3632
$(document).ready(function () {
3733
appReady();
@@ -216,6 +212,7 @@ function startProcess() {
216212

217213
// detach listeners and remove element data
218214
const content = $("#content");
215+
unmountVueTab();
219216
content.empty();
220217

221218
// display loading screen

src/js/msp/MSPHelper.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import huffmanDecodeBuf from "../huffman";
1414
import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree";
1515
import { updateTabList } from "../utils/updateTabList";
1616
import { showErrorDialog } from "../utils/showErrorDialog";
17-
import GUI, { TABS } from "../gui";
17+
import GUI from "../gui";
1818
import { OSD } from "../tabs/osd";
19-
import { reinitializeConnection } from "../serial_backend";
2019

2120
// Used for LED_STRIP
2221
const ledDirectionLetters = ["n", "e", "s", "w", "u", "d"]; // in LSB bit order
@@ -2944,7 +2943,7 @@ MspHelper.prototype.writeConfiguration = function (reboot, callback) {
29442943
console.log("Configuration saved to EEPROM");
29452944
if (reboot) {
29462945
GUI.tab_switch_cleanup(function () {
2947-
return reinitializeConnection();
2946+
return GUI.reinitializeConnection();
29482947
});
29492948
}
29502949
if (callback) {

src/js/serial_backend.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ function connectDisconnect() {
128128
return;
129129
}
130130

131-
// When rebooting, adhere to the auto-connect setting
132-
if (!PortHandler.portPicker.autoConnect && Date.now() - rebootTimestamp < REBOOT_GRACE_PERIOD_MS) {
133-
console.log(`${logHead} Rebooting, not connecting`);
134-
return;
135-
}
131+
136132

137133
const portName = selectedPort === "manual" ? PortHandler.portPicker.portOverride : selectedPort;
138134

@@ -608,6 +604,7 @@ function finishOpen() {
608604
onConnect();
609605

610606
GUI.selectDefaultTabWhenConnected();
607+
rebootTimestamp = 0;
611608
}
612609

613610
function connectCli() {
@@ -808,6 +805,9 @@ export function reinitializeConnection() {
808805
// Send reboot command to the flight controller
809806
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
810807

808+
// Force connection invalid to ensure reboot dialog waits for reconnection
809+
CONFIGURATOR.connectionValid = false;
810+
811811
if (currentPort.startsWith("bluetooth")) {
812812
if (!PortHandler.portPicker.autoConnect) {
813813
return setTimeout(function () {
@@ -816,14 +816,6 @@ export function reinitializeConnection() {
816816
}
817817
}
818818

819-
// Show reboot progress modal except for cli and presets tab
820-
if (["cli", "presets"].includes(GUI.active_tab)) {
821-
console.log(`${logHead} Rebooting in ${GUI.active_tab} tab, skipping reboot dialog`);
822-
gui_log(i18n.getMessage("deviceRebooting"));
823-
gui_log(i18n.getMessage("deviceReady"));
824-
825-
return;
826-
}
827819
// Show reboot progress modal
828820
showRebootDialog();
829821
}
@@ -926,3 +918,5 @@ function showRebootDialog() {
926918
return dialog;
927919
}
928920
}
921+
922+
GUI.reinitializeConnection = reinitializeConnection;

src/js/vue_tab_mounter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function mountVueTab(tabName, contentReadyCallback) {
6363
currentTabApp.provide("betaflightModel", window.vm);
6464
}
6565

66+
// Set active tab for legacy compatibility
67+
GUI.active_tab = tabName;
68+
6669
// Mount to content
6770
currentTabApp.mount(contentEl);
6871

0 commit comments

Comments
 (0)