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