this repo has no description
1import type { Config, DetectedExtension, ExtensionManifest } from "@moonlight-mod/types";
2
3export function getManifest(extensions: DetectedExtension[], ext: string) {
4 return extensions.find((x) => x.id === ext)?.manifest;
5}
6
7export function getConfig(ext: string, config: Config) {
8 const val = config.extensions[ext];
9 if (val == null || typeof val === "boolean") return undefined;
10 return val.config;
11}
12
13export function getConfigOption<T>(
14 ext: string,
15 key: string,
16 config: Config,
17 settings?: ExtensionManifest["settings"]
18): T | undefined {
19 const defaultValue: T | undefined = structuredClone(settings?.[key]?.default);
20 const cfg = getConfig(ext, config);
21 if (cfg == null || typeof cfg === "boolean") return defaultValue;
22 return cfg?.[key] ?? defaultValue;
23}
24
25export function setConfigOption<T>(config: Config, ext: string, key: string, value: T) {
26 const oldConfig = config.extensions[ext];
27 const newConfig =
28 typeof oldConfig === "boolean"
29 ? {
30 enabled: oldConfig,
31 config: { [key]: value }
32 }
33 : {
34 ...oldConfig,
35 config: { ...(oldConfig?.config ?? {}), [key]: value }
36 };
37
38 config.extensions[ext] = newConfig;
39}