this repo has no description
at v1.3.7 1.7 kB view raw
1import { Config } from "@moonlight-mod/types"; 2import { getConfigPath } from "./util/data"; 3import * as constants from "@moonlight-mod/types/constants"; 4import Logger from "./util/logger"; 5 6const logger = new Logger("core/config"); 7 8const defaultConfig: Config = { 9 // If you're updating this, update `builtinExtensions` in constants as well 10 extensions: { 11 moonbase: true, 12 disableSentry: true, 13 noTrack: true, 14 noHideToken: true 15 }, 16 repositories: [constants.mainRepo] 17}; 18 19export async function writeConfig(config: Config) { 20 try { 21 const configPath = await getConfigPath(); 22 await moonlightNodeSandboxed.fs.writeFileString(configPath, JSON.stringify(config, null, 2)); 23 } catch (e) { 24 logger.error("Failed to write config", e); 25 } 26} 27 28export async function readConfig(): Promise<Config> { 29 webPreload: { 30 return moonlightNode.config; 31 } 32 33 const configPath = await getConfigPath(); 34 if (!(await moonlightNodeSandboxed.fs.exists(configPath))) { 35 await writeConfig(defaultConfig); 36 return defaultConfig; 37 } else { 38 try { 39 let config: Config = JSON.parse(await moonlightNodeSandboxed.fs.readFileString(configPath)); 40 // Assign the default values if they don't exist (newly added) 41 config = { ...defaultConfig, ...config }; 42 await writeConfig(config); 43 44 return config; 45 } catch (e) { 46 logger.error("Failed to read config, falling back to defaults", e); 47 // We don't want to write the default config here - if a user is manually 48 // editing their config and messes it up, we'll delete it all instead of 49 // letting them fix it 50 return defaultConfig; 51 } 52 } 53}