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