From 696776bec5e8768b8f91f6cf40f67450000f0168 Mon Sep 17 00:00:00 2001 From: Vithorio Polten Date: Thu, 2 May 2024 10:08:16 -0300 Subject: [PATCH] fix: improve config by splitting rendering data from config files data Splitting rendering data from config files data, we avoid a lot of potential mistakes and we can better evolve the API, information used only to display the UI components has no business being in the same object as actual config file properties --- src/confighttp.cpp | 5 +++-- src_assets/common/assets/web/config.html | 12 +++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/confighttp.cpp b/src/confighttp.cpp index f0a53becded..486cf588722 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -554,10 +554,11 @@ namespace confighttp { outputTree.push_back(std::make_pair("displays", displays)); auto vars = config::parse_config(file_handler::read_file(config::sunshine.config_file.c_str())); - + pt::ptree config_file; for (auto &[name, value] : vars) { - outputTree.put(std::move(name), std::move(value)); + config_file.put(std::move(name), std::move(value)); } + outputTree.push_back(std::make_pair("config_file", config_file)); } void diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 34f20d8acae..71cad628ed3 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -1247,10 +1247,9 @@

fetch("/api/config") .then((r) => r.json()) .then((r) => { - this.config = r; - this.platform = this.config.platform; - - this.displays = this.config.displays; + this.config = r.config_file; + this.platform = r.platform; + this.displays = r.displays; var app = document.getElementById("app"); if (this.platform === "windows") { @@ -1269,11 +1268,6 @@

}); } - // remove values we don't want in the config file - delete this.config.platform; - delete this.config.status; - delete this.config.version; - // Populate default values from tabs options this.tabs.forEach(tab => { Object.keys(tab.options).forEach(optionKey => {