96 lines
2.9 kB
1
import type { Logger } from "./logger";
2
import type { Config, ConfigExtension } from "./config";
3
import type { DetectedExtension, IdentifiedPatch, IdentifiedWebpackModule, ProcessedExtensions } from "./extension";
4
import type EventEmitter from "events";
5
import type LunAST from "@moonlight-mod/lunast";
6
import type Moonmap from "@moonlight-mod/moonmap";
7
import type { EventPayloads, EventType, MoonlightEventEmitter } from "./core/event";
8
import { MoonlightFS } from "./fs";
9
10
export type MoonlightHost = {
11
config: Config;
12
extensions: DetectedExtension[];
13
processedExtensions: ProcessedExtensions;
14
asarPath: string;
15
events: EventEmitter;
16
17
version: string;
18
branch: MoonlightBranch;
19
20
getConfig: (ext: string) => ConfigExtension["config"];
21
getConfigOption: <T>(ext: string, name: string) => T | undefined;
22
setConfigOption: <T>(ext: string, name: string, value: T) => void;
23
writeConfig: (config: Config) => Promise<void>;
24
25
getLogger: (id: string) => Logger;
26
getMoonlightDir: () => string;
27
getExtensionDir: (ext: string) => string;
28
};
29
30
export type MoonlightNode = {
31
config: Config;
32
extensions: DetectedExtension[];
33
processedExtensions: ProcessedExtensions;
34
nativesCache: Record<string, any>;
35
isBrowser: boolean;
36
37
version: string;
38
branch: MoonlightBranch;
39
40
getConfig: (ext: string) => ConfigExtension["config"];
41
getConfigOption: <T>(ext: string, name: string) => T | undefined;
42
setConfigOption: <T>(ext: string, name: string, value: T) => void;
43
writeConfig: (config: Config) => Promise<void>;
44
45
getNatives: (ext: string) => any | undefined;
46
getLogger: (id: string) => Logger;
47
getMoonlightDir: () => string;
48
getExtensionDir: (ext: string) => string;
49
};
50
51
export type MoonlightNodeSandboxed = {
52
fs: MoonlightFS;
53
addCors: (url: string) => void;
54
addBlocked: (url: string) => void;
55
};
56
57
export type MoonlightWeb = {
58
unpatched: Set<IdentifiedPatch>;
59
pendingModules: Set<IdentifiedWebpackModule>;
60
enabledExtensions: Set<string>;
61
events: MoonlightEventEmitter<EventType, EventPayloads>;
62
patchingInternals: {
63
onModuleLoad: (moduleId: string | string[], callback: (moduleId: string) => void) => void;
64
registerPatch: (patch: IdentifiedPatch) => void;
65
registerWebpackModule: (module: IdentifiedWebpackModule) => void;
66
};
67
localStorage: Storage;
68
69
version: string;
70
branch: MoonlightBranch;
71
apiLevel: number;
72
73
// Re-exports for ease of use
74
getConfig: MoonlightNode["getConfig"];
75
getConfigOption: MoonlightNode["getConfigOption"];
76
setConfigOption: MoonlightNode["setConfigOption"];
77
writeConfig: MoonlightNode["writeConfig"];
78
79
getNatives: (ext: string) => any | undefined;
80
getLogger: (id: string) => Logger;
81
82
lunast: LunAST;
83
moonmap: Moonmap;
84
};
85
86
export enum MoonlightEnv {
87
Injector = "injector",
88
NodePreload = "node-preload",
89
WebPreload = "web-preload"
90
}
91
92
export enum MoonlightBranch {
93
STABLE = "stable",
94
NIGHTLY = "nightly",
95
DEV = "dev"
96
}
97