fix config always assumed changed

This commit is contained in:
2025-05-07 00:48:06 +02:00
parent bfc3fbc6e1
commit 171b130a29
4 changed files with 52 additions and 44 deletions

View File

@@ -205,18 +205,16 @@ export class Controller {
})
}
downloadConfig() :Promise<void> {
async downloadConfig(): Promise<void> {
controller.progressview.addIndeterminate("get_config", "Downloading Config")
return fetch(PUBLIC_URL + "/get_config")
.then(response => response.json())
.then(loaded => {
var currentConfig = loaded as PlantControllerConfig;
controller.setInitialConfig(currentConfig);
controller.setConfig(currentConfig);
//sync json view initially
this.configChanged();
controller.progressview.removeProgress("get_config")
})
const response = await fetch(PUBLIC_URL + "/get_config");
const loaded = await response.json();
var currentConfig = loaded as PlantControllerConfig;
controller.setInitialConfig(currentConfig);
controller.setConfig(currentConfig);
//sync json view initially
controller.configChanged();
controller.progressview.removeProgress("get_config");
}
setInitialConfig(currentConfig: PlantControllerConfig) {
this.initialConfig = currentConfig
@@ -262,6 +260,7 @@ export class Controller {
var pretty = JSON.stringify(current, undefined, 0);
controller.submitView.setJson(pretty);
if (deepEqual(current, controller.initialConfig)) {
document.title = "PlantCtrl"
} else {
@@ -471,36 +470,42 @@ export class Controller {
const controller = new Controller();
controller.progressview.removeProgress("rebooting");
controller.progressview.addProgress("initial", 0, "read timezones");
controller.populateTimezones().then(_ => {
controller.progressview.addProgress("initial", 10, "read rtc");
controller.updateRTCData().then(_ => {
controller.progressview.addProgress("initial", 20, "read battery");
controller.updateBatteryData().then(_ => {
controller.progressview.addProgress("initial", 40, "read config");
controller.downloadConfig().then(_ => {
controller.progressview.addProgress("initial", 50, "read version");
controller.version().then(_ => {
controller.progressview.addProgress("initial", 70, "read filelist");
controller.updateFileList().then(_ => {
controller.progressview.addProgress("initial", 90, "read backupinfo");
controller.getBackupInfo().then(_ => {
controller.loadLogLocaleConfig().then(_ => {
controller.loadTankInfo().then(_ => {
controller.progressview.removeProgress("initial")
})
})
})
})
})
});
});
});
const tasks = [
{ task: controller.populateTimezones, displayString: "Populating Timezones" },
{ task: controller.updateRTCData, displayString: "Updating RTC Data" },
{ task: controller.updateBatteryData, displayString: "Updating Battery Data" },
{ task: controller.downloadConfig, displayString: "Downloading Configuration" },
{ task: controller.version, displayString: "Fetching Version Information" },
{ task: controller.updateFileList, displayString: "Updating File List" },
{ task: controller.getBackupInfo, displayString: "Fetching Backup Information" },
{ task: controller.loadLogLocaleConfig, displayString: "Loading Log Localization Config" },
{ task: controller.loadTankInfo, displayString: "Loading Tank Information" },
];
async function executeTasksSequentially() {
let current = 0;
for (const { task, displayString } of tasks) {
current++;
let ratio = current / tasks.length;
controller.progressview.addProgress("initial", ratio * 100, displayString);
try {
await task();
} catch (error) {
console.error(`Error executing task '${displayString}':`, error);
// Optionally, you can decide whether to continue or break on errors
break;
}
}
}
executeTasksSequentially().then(r => {
controller.progressview.removeProgress("initial")
});
//controller.measure_moisture();
controller.progressview.removeProgress("rebooting");