this repo has no description
at v1.0.10 1.7 kB view raw
1import { constants } from "@moonlight-mod/types"; 2import requireImport from "./import"; 3 4export function getMoonlightDir(): string { 5 const electron = require("electron"); 6 const fs = requireImport("fs"); 7 const path = requireImport("path"); 8 9 let appData = ""; 10 injector: { 11 appData = electron.app.getPath("appData"); 12 } 13 14 nodePreload: { 15 appData = electron.ipcRenderer.sendSync(constants.ipcGetAppData); 16 } 17 18 const dir = path.join(appData, "moonlight-mod"); 19 if (!fs.existsSync(dir)) fs.mkdirSync(dir); 20 21 return dir; 22} 23 24type BuildInfo = { 25 releaseChannel: string; 26 version: string; 27}; 28 29export function getConfigPath(): string { 30 const dir = getMoonlightDir(); 31 const fs = requireImport("fs"); 32 const path = requireImport("path"); 33 34 let configPath = ""; 35 36 const buildInfoPath = path.join(process.resourcesPath, "build_info.json"); 37 if (!fs.existsSync(buildInfoPath)) { 38 configPath = path.join(dir, "desktop.json"); 39 } else { 40 const buildInfo: BuildInfo = JSON.parse( 41 fs.readFileSync(buildInfoPath, "utf8") 42 ); 43 configPath = path.join(dir, buildInfo.releaseChannel + ".json"); 44 } 45 46 return configPath; 47} 48 49function getPathFromMoonlight(...names: string[]): string { 50 const dir = getMoonlightDir(); 51 const fs = requireImport("fs"); 52 const path = requireImport("path"); 53 54 const target = path.join(dir, ...names); 55 if (!fs.existsSync(target)) fs.mkdirSync(target); 56 57 return target; 58} 59 60export function getExtensionsPath(): string { 61 return getPathFromMoonlight(constants.extensionsDir); 62} 63 64export function getCoreExtensionsPath(): string { 65 const path = requireImport("path"); 66 const a = path.join(__dirname, constants.coreExtensionsDir); 67 return a; 68}