Skip to content

Commit

Permalink
fix(settings): Fix Settings is undefined on first app load.
Browse files Browse the repository at this point in the history
  • Loading branch information
sampie777 committed Dec 16, 2021
1 parent f369b71 commit cf813aa
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions source/scripts/settings/settingsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,23 @@ class SettingsProvider {

static get(key: string): string | undefined {
if (!Db.settings.isConnected()) {
// @ts-ignore
return Settings[key];
return undefined;
}

const value = Db.settings.realm()
.objects<Setting>(SettingSchema.name)
.filtered(`key = "${key}"`);

if (value === null || value === undefined || value[0] === undefined) {
// @ts-ignore
return Settings[key];
return undefined;
}
return value[0].value;
}

static getNumber(key: string): number | undefined {
const stringValue = this.get(key);
if (stringValue === undefined) {
// @ts-ignore
return Settings[key];
return undefined;
}

return +stringValue;
Expand All @@ -57,8 +54,7 @@ class SettingsProvider {
static getBoolean(key: string): boolean | undefined {
const stringValue = this.get(key);
if (stringValue === undefined) {
// @ts-ignore
return Settings[key];
return undefined;
}

return stringValue.toString() == "true";
Expand Down

0 comments on commit cf813aa

Please sign in to comment.