Skip to content

Commit

Permalink
fix: improve config by splitting rendering data from config files data
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Hazer committed May 2, 2024
1 parent 607eae1 commit 696776b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions src_assets/common/assets/web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1247,10 +1247,9 @@ <h2 class="accordion-header">
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") {
Expand All @@ -1269,11 +1268,6 @@ <h2 class="accordion-header">
});
}

// 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 => {
Expand Down

0 comments on commit 696776b

Please sign in to comment.