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