1
0
mirror of synced 2025-01-10 21:41:53 +01:00

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

@ -258,7 +258,6 @@ namespace hex {
EVENT_DEF(EventSearchBoxClicked, u32);
EVENT_DEF(EventViewOpened, View*);
EVENT_DEF(EventFirstLaunch);
EVENT_DEF(EventAnySettingChanged);
EVENT_DEF(EventFileDragged, bool);
EVENT_DEF(EventFileDropped, std::fs::path);

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();
}
}

View File

@ -26,7 +26,7 @@ namespace hex::plugin::builtin {
this->getWindowOpenState() = true;
});
EventAnySettingChanged::subscribe(this, [] {
EventImHexStartupFinished::subscribe(this, []{
for (const auto &[unlocalizedCategory, unlocalizedDescription, subCategories] : ContentRegistry::Settings::impl::getSettings()) {
for (const auto &[unlocalizedSubCategory, entries] : subCategories) {
for (const auto &[unlocalizedName, widget] : entries) {
@ -41,13 +41,10 @@ namespace hex::plugin::builtin {
}
}
});
EventImHexStartupFinished::subscribe(this, []{ EventAnySettingChanged::post(); });
}
ViewSettings::~ViewSettings() {
RequestOpenWindow::unsubscribe(this);
EventAnySettingChanged::unsubscribe(this);
EventImHexStartupFinished::unsubscribe(this);
}