fix: Only update widgets of settings that were changed

Fixed crashing on exit and speeds up settings writes
This commit is contained in:
WerWolv
2024-12-20 21:23:19 +01:00
parent 9303025427
commit 5fcb737559
3 changed files with 12 additions and 7 deletions

View File

@@ -191,6 +191,17 @@ namespace hex {
const auto entry = insertOrGetEntry(subCategory->entries, unlocalizedName);
entry->widget = std::move(widget);
if (entry->widget != nullptr) {
onChange(unlocalizedCategory, unlocalizedName, [widget = entry->widget.get(), unlocalizedCategory, unlocalizedName](const SettingsValue &) {
try {
auto defaultValue = widget->store();
widget->load(ContentRegistry::Settings::impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue));
widget->onChanged();
} catch (const std::exception &e) {
log::error("Failed to load setting [{} / {}]: {}", unlocalizedCategory.get(), unlocalizedName.get(), e.what());
}
});
}
return entry->widget.get();
}
@@ -211,8 +222,6 @@ namespace hex {
}
}
}
EventAnySettingChanged::post();
}
}