api: Fix various crashes on bad settings data. (#186)

getSetting now returns a straight nlohmann::json instead of an optional.
If the data isn't present, it will return a json null.

All accesses to the settings will first check that the data has the
expected type.
This commit is contained in:
Robin Lambertz
2021-03-06 12:40:29 +01:00
committed by GitHub
parent 32cfaac1e2
commit 4f98149fa7
6 changed files with 11 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ namespace hex::plugin::builtin {
void registerSettings() {
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) {
static int selection = setting;
static int selection = setting.is_number() ? static_cast<int>(setting) : 0;
const char* themes[] = {
"hex.builtin.setting.interface.color.dark"_lang,