fix: Handling of unchanged shortcut keys

This commit is contained in:
WerWolv
2025-08-09 14:23:36 +02:00
parent 93a71120d4
commit dbc5819bc4
3 changed files with 9 additions and 3 deletions

View File

@@ -46,7 +46,7 @@ namespace hex {
try {
callback(getSetting(category, name, {}));
} catch (const std::exception &e) {
log::error("Failed to load setting [{}/{}]: {}", category, name, e.what());
log::error("Failed to load setting [{} / {}]: {}", category, name, e.what());
}
}
}
@@ -216,12 +216,13 @@ namespace hex {
entry->widget = std::move(widget);
if (entry->widget != nullptr) {
onChange(unlocalizedCategory, unlocalizedName, [widget = entry->widget.get(), unlocalizedCategory, unlocalizedName](const SettingsValue &) {
auto defaultValue = widget->store();
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());
ContentRegistry::Settings::impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue) = defaultValue;
}
});

View File

@@ -336,6 +336,9 @@ namespace hex::plugin::builtin {
void load(const nlohmann::json &data) override {
std::set<Key> keys;
if (data.empty())
return;
for (const auto &key : data.get<std::vector<u32>>())
keys.insert(Key(scanCodeToKey(key)));

View File

@@ -32,11 +32,13 @@ namespace hex::plugin::builtin {
for (const auto &[unlocalizedCategory, unlocalizedDescription, subCategories] : ContentRegistry::Settings::impl::getSettings()) {
for (const auto &[unlocalizedSubCategory, entries] : subCategories) {
for (const auto &[unlocalizedName, widget] : entries) {
auto defaultValue = widget->store();
try {
auto defaultValue = widget->store();
widget->load(ContentRegistry::Settings::impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue));
} catch (const std::exception &e) {
log::error("Failed to load setting [{} / {}]: {}", unlocalizedCategory.get(), unlocalizedName.get(), e.what());
ContentRegistry::Settings::impl::getSetting(unlocalizedCategory, unlocalizedName, defaultValue) = defaultValue;
}
}
}