[Linux-only] basically bloxstap for sober
at dev 62 lines 2.1 kB view raw
1import { SOBER_CONFIG_PATH, TUXSTRAP_VERSION } from "../constants"; 2import { getPlugins } from "../Plugin"; 3import type { fflagList, SoberConfig } from "../types"; 4import { writeFileSync } from "fs"; 5 6const defaultConfig: SoberConfig = { 7 allowGamepad: false, 8 bringBackOof: false, 9 closeOnLeaave: false, 10 enableRichPresence: true, 11 enableGamemode: true, 12 enableHiDPI: false, 13 serverLocationIndicator: false, 14 touchMode: "off", 15 useConsoleExperience: false, 16 useLibsecret: false, 17 useOpenGL: false 18}; 19 20export function generateConfiguration() { 21 console.log("[api/sober/ConfigManager] Generating config file"); 22 23 // Lower configPrio means it merges first 24 const plugins = getPlugins().sort((a, b) => a.configPrio - b.configPrio); 25 26 var currentConfig: SoberConfig = { ...defaultConfig }; 27 var currentFFlags: fflagList = {}; 28 29 for (const plugin of plugins) { 30 if (plugin.soberConfig) { 31 currentConfig = { ...currentConfig, ...plugin.soberConfig }; 32 } 33 if (plugin.fflags) { 34 currentFFlags = { ...currentFFlags, ...plugin.fflags }; 35 } 36 } 37 38 const finalConfig = { 39 "*": `WARNING: This file has been modified with TuxStrap. Launching it will discard all changes to this file. TuxStrap version: ${TUXSTRAP_VERSION}`, 40 allow_gamepad_permission: currentConfig.allowGamepad, 41 bring_back_oof: currentConfig.bringBackOof, 42 close_on_leave: currentConfig.closeOnLeaave, 43 discord_rpc_enabled: currentConfig.enableRichPresence, 44 enable_gamemode: currentConfig.enableGamemode, 45 enable_hidpi: currentConfig.enableHiDPI, 46 fflags: currentFFlags, 47 server_location_indicator_enabled: 48 currentConfig.serverLocationIndicator, 49 touch_mode: currentConfig.touchMode, 50 use_console_experience: currentConfig.useConsoleExperience, 51 use_libsecret: currentConfig.useLibsecret, 52 use_opengl: currentConfig.useOpenGL 53 }; 54 55 return finalConfig; 56} 57 58export function generateConfigFile() { 59 const content = JSON.stringify(generateConfiguration(), undefined, "\t"); 60 writeFileSync(SOBER_CONFIG_PATH, content); 61 console.log(`[api/sober/ConfigManager] Updated ${SOBER_CONFIG_PATH}`); 62}