fix: Settings being overwritten sometimes on crash
This commit is contained in:
parent
f587710d1c
commit
dd5ddbcc0f
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user