1
0
mirror of synced 2025-02-17 18:59:21 +01:00

fix: Settings being overwritten sometimes on crash

This commit is contained in:
WerWolv 2024-03-26 19:49:03 +01:00
parent f587710d1c
commit dd5ddbcc0f
2 changed files with 11 additions and 7 deletions

View File

@ -58,6 +58,7 @@ namespace hex {
}
#if defined(OS_WEB)
void load() {
char *data = (char *) MAIN_THREAD_EM_ASM_INT({
let data = localStorage.getItem("config");
@ -73,7 +74,11 @@ namespace hex {
for (const auto &[category, rest] : *impl::s_onChangeCallbacks) {
for (const auto &[name, callbacks] : rest) {
for (const auto &[id, callback] : callbacks) {
callback(getSetting(category, name, {}));
try {
callback(getSetting(category, name, {}));
} catch (const std::exception &e) {
log::error("Failed to load setting [{}/{}]: {}", category, name, e.what());
}
}
}
}
@ -112,7 +117,11 @@ namespace hex {
for (const auto &[category, rest] : *impl::s_onChangeCallbacks) {
for (const auto &[name, callbacks] : rest) {
for (const auto &[id, callback] : callbacks) {
callback(getSetting(category, name, {}));
try {
callback(getSetting(category, name, {}));
} catch (const std::exception &e) {
log::error("Failed to load setting [{}/{}]: {}", category, name, e.what());
}
}
}
}

View File

@ -226,13 +226,8 @@ namespace hex::init {
// Try to load settings from file
ContentRegistry::Settings::impl::load();
} catch (std::exception &e) {
// If that fails, create a new settings file
log::error("Failed to load configuration! {}", e.what());
ContentRegistry::Settings::impl::clear();
ContentRegistry::Settings::impl::store();
return false;
}