diff options
author | Vendicated <vendicated@riseup.net> | 2022-10-14 00:36:44 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-10-14 00:36:44 +0200 |
commit | bf49acd53578a141689f7faedbe5912ab10ab570 (patch) | |
tree | 2e8cc44b58ea50f33bca00f001daf3326eebd8bb /src | |
parent | ea0ded0f11b95373a5a19c5e705d19ad91ff32be (diff) | |
download | Vencord-bf49acd53578a141689f7faedbe5912ab10ab570.tar.gz Vencord-bf49acd53578a141689f7faedbe5912ab10ab570.tar.bz2 Vencord-bf49acd53578a141689f7faedbe5912ab10ab570.zip |
Fix Settings errors when retrieving a null value; add PlainSettings
Diffstat (limited to 'src')
-rw-r--r-- | src/Vencord.ts | 4 | ||||
-rw-r--r-- | src/api/settings.ts | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/Vencord.ts b/src/Vencord.ts index 578e69d..9a0873e 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -5,10 +5,10 @@ export * as Updater from "./utils/updater"; export * as QuickCss from "./utils/quickCss"; import { popNotice, showNotice } from "./api/Notices"; -import { Settings } from "./api/settings"; +import { Settings, PlainSettings } from "./api/settings"; import { startAllPlugins } from "./plugins"; -export { Settings }; +export { Settings, PlainSettings }; import "./webpack/patchWebpack"; import "./utils/quickCss"; diff --git a/src/api/settings.ts b/src/api/settings.ts index 0f2356f..a5bda83 100644 --- a/src/api/settings.ts +++ b/src/api/settings.ts @@ -46,7 +46,7 @@ function makeProxy(settings: Settings, root = settings, path = ""): Settings { return new Proxy(settings, { get(target, p: string) { const v = target[p]; - if (typeof v === "object" && !Array.isArray(v)) + if (typeof v === "object" && !Array.isArray(v) && v !== null) return makeProxy(v, root, `${path}${path && "."}${p}`); return v; }, @@ -67,11 +67,17 @@ function makeProxy(settings: Settings, root = settings, path = ""): Settings { } /** + * Same as {@link Settings} but unproxied. You should treat this as readonly, + * as modifying properties on this will not save to disk or call settings + * listeners. + */ +export const PlainSettings = settings; +/** * A smart settings object. Altering props automagically saves * the updated settings to disk. + * This recursively proxies objects. If you need the object non proxied, use {@link PlainSettings} */ export const Settings = makeProxy(settings); - /** * Settings hook for React components. Returns a smart settings * object that automagically triggers a rerender if any properties |