···11-- core-extensions/contextMenu: Fix patches
11+## Core
22+33+- Updated mappings
44+- Fixed using remapped paths as patch finds not working
+10-3
README.md
···55 <img src="./img/wordmark.png" alt="moonlight" />
66 </picture>
7788-<a href="https://discord.gg/FdZBTFCP6F">Discord server</a>
88+<a href="https://moonlight-mod.github.io/using/install">Install</a>
99+\- <a href="https://moonlight-mod.github.io/ext-dev/getting-started">Docs</a>
1010+\- <a href="https://discord.gg/FdZBTFCP6F">Discord server</a>
911\- <a href="https://github.com/moonlight-mod/moonlight">GitHub</a>
1010-\- <a href="https://moonlight-mod.github.io/">Docs</a>
11121213 <hr />
1414+1515+ <picture>
1616+ <source media="(prefers-color-scheme: dark)" srcset="https://moonlight-mod.github.io/moonbase.png">
1717+ <source media="(prefers-color-scheme: light)" srcset="https://moonlight-mod.github.io/moonbase-light.png">
1818+ <img src="https://moonlight-mod.github.io/moonbase.png" alt="A screenshot of Moonbase, the moonlight UI" />
1919+ </picture>
1320</h3>
14211522**moonlight** is yet another Discord client mod, focused on providing a decent user and developer experience.
16231724moonlight is heavily inspired by hh3 (a private client mod) and the projects before it that it is inspired by, namely EndPwn. All core code is original or used with permission from their respective authors where not copyleft.
18251919-**_This is an experimental passion project._** Anything and everything is subject to change, but it is stable enough for developers to experiment with.
2626+moonlight is a **_passion project_** - things may break from time to time, but we try our best to keep things working in a timely manner.
20272128moonlight is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.html) (`LGPL-3.0-or-later`). See [the documentation](https://moonlight-mod.github.io/) for more information.
···11import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
2233+// spacepack.require.m[moonlight.moonmap.modules["discord/modules/menus/web/Menu"]].toString();
34let code =
45 spacepack.require.m[
55- spacepack.findByCode(
66- "Menu API only allows Items and groups of Items as children."
77- )[0].id
66+ spacepack.findByCode("Menu API only allows Items and groups of Items as children.")[0].id
87 ].toString();
99-code = code.replace(/,.=(?=function .\(.\){.+?,.=function)/, ";return ");
1010-code = code.replace(/,(?=__contextMenu)/, ";let ");
1111-const mod = new Function(
1212- "module",
1313- "exports",
1414- "require",
1515- `(${code}).apply(this, arguments)`
1616-);
88+99+const parserSym = code.match(/(?<=_patchMenu\(.,).+?(?=\()/)![0];
1010+1111+code = code.replace(/{(.):\(\)=>./, (orig, e) => `{${e}:()=>${parserSym}`);
1212+const mod = new Function("module", "exports", "require", `(${code}).apply(this, arguments)`);
1313+1714const exp: any = {};
1815mod({}, exp, require);
1919-const Menu = spacepack.findFunctionByStrings(
2020- exp,
2121- "Menu API only allows Items and groups of Items as children."
2222-)!;
2323-module.exports = (el: any) => {
2424- return Menu({
2525- children: el,
2626- __contextMenu_evilMenu: true
2727- });
2828-};
1616+1717+const parser = spacepack.findFunctionByStrings(exp, "Menu API only allows Items and groups of Items as children.")!;
1818+module.exports = parser;
···11import { Store } from "@moonlight-mod/wp/discord/packages/flux";
22import Dispatcher from "@moonlight-mod/wp/discord/Dispatcher";
33-import type {
44- Notice,
55- Notices
66-} from "@moonlight-mod/types/coreExtensions/notices";
33+import type { Notice, Notices } from "@moonlight-mod/types/coreExtensions/notices";
7485// very lazy way of doing this, FIXME
96let open = false;
···11{
22+ "$schema": "https://moonlight-mod.github.io/manifest.schema.json",
23 "id": "rocketship",
34 "apiLevel": 2,
55+ "environment": "desktop",
46 "meta": {
57 "name": "Rocketship",
68 "tagline": "Adds new features when using rocketship",
79 "description": "**This extension only works on Linux when using rocketship:**\nhttps://github.com/moonlight-mod/rocketship\n\nAdds new features to the Discord Linux client with rocketship, such as a better screensharing experience.",
88- "authors": ["NotNite", "Cynosphere", "adryd"]
1010+ "authors": ["NotNite", "Cynosphere", "adryd"],
1111+ "deprecated": true
912 }
1013}
···11+export type AppPanels = {
22+ /**
33+ * Registers a new panel to be displayed around the user/voice controls.
44+ * @param section A unique name for your section
55+ * @param element A React component
66+ */
77+ addPanel: (section: string, element: React.FC<any>) => void;
88+99+ /**
1010+ * @private
1111+ */
1212+ getPanels: (el: React.FC<any>) => React.ReactNode;
1313+};
···11111212export type ASTNode = SingleASTNode | Array<SingleASTNode>;
13131414-export type Parser = (
1515- source: string,
1616- state?: State | null | undefined
1717-) => Array<SingleASTNode>;
1414+export type Parser = (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
18151919-export type ParseFunction = (
2020- capture: Capture,
2121- nestedParse: Parser,
2222- state: State
2323-) => UntypedASTNode | ASTNode;
1616+export type ParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UntypedASTNode | ASTNode;
24172518export type Capture =
2619 | (Array<string> & {
···38313932export type MatchFunction = {
4033 regex?: RegExp;
4141-} & ((
4242- source: string,
4343- state: State,
4444- prevCapture: string
4545-) => Capture | null | undefined);
3434+} & ((source: string, state: State, prevCapture: string) => Capture | null | undefined);
46354747-export type Output<Result> = (
4848- node: ASTNode,
4949- state?: State | null | undefined
5050-) => Result;
3636+export type Output<Result> = (node: ASTNode, state?: State | null | undefined) => Result;
51375252-export type SingleNodeOutput<Result> = (
5353- node: SingleASTNode,
5454- nestedOutput: Output<Result>,
5555- state: State
5656-) => Result;
3838+export type SingleNodeOutput<Result> = (node: SingleASTNode, nestedOutput: Output<Result>, state: State) => Result;
57395840// }}}
5941···10082 slateDecorators: Record<string, string>;
10183 ruleBlacklists: Record<Ruleset, Record<string, boolean>>;
102848585+ /**
8686+ * Registers a new Markdown rule with simple-markdown.
8787+ * @param name The name of the rule
8888+ * @param markdown A function that returns simple-markdown rules
8989+ * @param slate A function that returns Slate rules
9090+ * @param decorator A decorator name for Slate
9191+ * @see https://www.npmjs.com/package/simple-markdown#adding-a-simple-extension
9292+ * @see https://docs.slatejs.org/
9393+ */
10394 addRule: (
10495 name: string,
10596 markdown: (rules: Record<string, MarkdownRule>) => MarkdownRule,
10697 slate: (rules: Record<string, SlateRule>) => SlateRule,
10798 decorator?: string | undefined
10899 ) => void;
100100+101101+ /**
102102+ * Blacklist a rule from a ruleset.
103103+ * @param ruleset The ruleset name
104104+ * @param name The rule name
105105+ */
109106 blacklistFromRuleset: (ruleset: Ruleset, name: string) => void;
110107};
+12-7
packages/types/src/coreExtensions/moonbase.ts
···11-export type CustomComponent = React.FC<{
11+export type CustomComponentProps = {
22 value: any;
33 setValue: (value: any) => void;
44-}>;
44+};
55+66+export type CustomComponent = React.FC<CustomComponentProps>;
5768export type Moonbase = {
77- registerConfigComponent: (
88- ext: string,
99- option: string,
1010- component: CustomComponent
1111- ) => void;
99+ /**
1010+ * Registers a custom component for an extension setting.
1111+ * The extension setting must be of type "custom".
1212+ * @param ext The extension ID
1313+ * @param option The setting ID
1414+ * @param component A React component
1515+ */
1616+ registerConfigComponent: (ext: string, option: string, component: CustomComponent) => void;
1217};
+16-1
packages/types/src/coreExtensions/notices.ts
···11-import type { Store } from "@moonlight-mod/mappings/discord/packages/flux";
11+import type { Store } from "@moonlight-mod/mappings/discord/packages/flux/Store";
2233export type NoticeButton = {
44 name: string;
···1414};
15151616export type Notices = Store<any> & {
1717+ /**
1818+ * Adds a custom notice to the top of the screen.
1919+ */
1720 addNotice: (notice: Notice) => void;
2121+2222+ /**
2323+ * Removes the current notice from the top of the screen.
2424+ */
1825 popNotice: () => void;
2626+2727+ /**
2828+ * @private
2929+ */
1930 getCurrentNotice: () => Notice | null;
3131+3232+ /**
3333+ * @private
3434+ */
2035 shouldShowNotice: () => boolean;
2136};
+39-8
packages/types/src/coreExtensions/settings.ts
···11import React, { ReactElement } from "react";
22-import type { Store } from "@moonlight-mod/mappings/discord/packages/flux";
22+import type { Store } from "@moonlight-mod/mappings/discord/packages/flux/Store";
3344export type NoticeProps = {
55 stores: Store<any>[];
···77};
8899export type SettingsSection =
1010- | { section: "DIVIDER"; pos: number }
1111- | { section: "HEADER"; label: string; pos: number }
1010+ | { section: "DIVIDER"; pos: number | ((sections: SettingsSection[]) => number) }
1111+ | { section: "HEADER"; label: string; pos: number | ((sections: SettingsSection[]) => number) }
1212 | {
1313 section: string;
1414 label: string;
1515 color: string | null;
1616 element: React.FunctionComponent;
1717- pos: number;
1717+ pos: number | ((sections: SettingsSection[]) => number);
1818 notice?: NoticeProps;
1919+ onClick?: () => void;
1920 _moonlight_submenu?: () => ReactElement | ReactElement[];
2021 };
2122···2425 sectionNames: string[];
2526 sectionMenuItems: Record<string, ReactElement[]>;
26272828+ /**
2929+ * Registers a new section in the settings menu.
3030+ * @param section The section ID
3131+ * @param label The label for the section
3232+ * @param element The React component to render
3333+ * @param color A color to use for the section
3434+ * @param pos The position in the settings menu to place the section
3535+ * @param notice A notice to display when in the section
3636+ * @param onClick A custom action to execute when clicked from the context menu
3737+ */
2738 addSection: (
2839 section: string,
2940 label: string,
3041 element: React.FunctionComponent,
3142 color?: string | null,
3232- pos?: number,
3333- notice?: NoticeProps
4343+ pos?: number | ((sections: SettingsSection[]) => number),
4444+ notice?: NoticeProps,
4545+ onClick?: () => void
3446 ) => void;
4747+4848+ /**
4949+ * Adds new items to a section in the settings menu.
5050+ * @param section The section ID
5151+ * @param items The React components to render
5252+ */
3553 addSectionMenuItems: (section: string, ...items: ReactElement[]) => void;
36543737- addDivider: (pos: number | null) => void;
3838- addHeader: (label: string, pos: number | null) => void;
5555+ /**
5656+ * Places a divider in the settings menu.
5757+ * @param pos The position in the settings menu to place the divider
5858+ */
5959+ addDivider: (pos: number | ((sections: SettingsSection[]) => number) | null) => void;
6060+6161+ /**
6262+ * Places a header in the settings menu.
6363+ * @param pos The position in the settings menu to place the header
6464+ */
6565+ addHeader: (label: string, pos: number | ((sections: SettingsSection[]) => number) | null) => void;
6666+6767+ /**
6868+ * @private
6969+ */
3970 _mutateSections: (sections: SettingsSection[]) => SettingsSection[];
4071};
+83-18
packages/types/src/coreExtensions/spacepack.ts
···11-import {
22- WebpackModule,
33- WebpackModuleFunc,
44- WebpackRequireType
55-} from "../discord";
11+import { WebpackModule, WebpackModuleFunc, WebpackRequireType } from "../discord";
6273export type Spacepack = {
44+ /**
55+ * Given a Webpack module ID, returns the function for the Webpack module.
66+ * Can be double clicked to inspect in DevTools.
77+ * @param module The module ID
88+ * @returns The Webpack module, if found
99+ */
810 inspect: (module: number | string) => WebpackModuleFunc | null;
99- findByCode: (...args: (string | RegExp)[]) => any[];
1010- findByExports: (...args: string[]) => any[];
1111+1212+ /**
1313+ * Find Webpack modules based on matches in code.
1414+ * @param args A list of finds to match against
1515+ * @returns The Webpack modules, if found
1616+ */
1717+ findByCode: (...args: (string | RegExp)[]) => WebpackModule[];
1818+1919+ /**
2020+ * Find Webpack modules based on their exports.
2121+ * @deprecated This has race conditions. Consider using findByCode instead.
2222+ * @param args A list of finds to match exports against
2323+ * @returns The Webpack modules, if found
2424+ */
2525+ findByExports: (...args: string[]) => WebpackModule[];
2626+2727+ /**
2828+ * The Webpack require function.
2929+ */
1130 require: WebpackRequireType;
3131+3232+ /**
3333+ * The Webpack module list.
3434+ * Re-export of require.m.
3535+ */
1236 modules: Record<string, WebpackModuleFunc>;
3737+3838+ /**
3939+ * The Webpack module cache.
4040+ * Re-export of require.c.
4141+ */
1342 cache: Record<string, any>;
4343+4444+ /**
4545+ * Finds an object from a module's exports using the given key.
4646+ * @param exports Exports from a Webpack module
4747+ * @param key The key to find with
4848+ * @returns The object, if found
4949+ */
1450 findObjectFromKey: (exports: Record<string, any>, key: string) => any | null;
5151+5252+ /**
5353+ * Finds an object from a module's exports using the given value.
5454+ * @param exports Exports from a Webpack module
5555+ * @param value The value to find with
5656+ * @returns The object, if found
5757+ */
1558 findObjectFromValue: (exports: Record<string, any>, value: any) => any | null;
1616- findObjectFromKeyValuePair: (
1717- exports: Record<string, any>,
1818- key: string,
1919- value: any
2020- ) => any | null;
5959+6060+ /**
6161+ * Finds an object from a module's exports using the given key-value pair.
6262+ * @param exports Exports from a Webpack module
6363+ * @param key The key to find with
6464+ * @param value The value to find with
6565+ * @returns The object, if found
6666+ */
6767+ findObjectFromKeyValuePair: (exports: Record<string, any>, key: string, value: any) => any | null;
6868+6969+ /**
7070+ * Finds a function from a module's exports using the given source find.
7171+ * This behaves like findByCode but localized to the exported function.
7272+ * @param exports A module's exports
7373+ * @param strings A list of finds to use
7474+ * @returns The function, if found
7575+ */
2176 findFunctionByStrings: (
2277 exports: Record<string, any>,
2378 ...strings: (string | RegExp)[]
2424- // eslint-disable-next-line @typescript-eslint/ban-types
7979+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2580 ) => Function | null;
2626- lazyLoad: (
2727- find: string | RegExp | (string | RegExp)[],
2828- chunk: RegExp,
2929- module: RegExp
3030- ) => Promise<any>;
8181+8282+ /**
8383+ * Lazy load a Webpack module.
8484+ * @param find A list of finds to discover a target module with
8585+ * @param chunk A RegExp to match chunks to load
8686+ * @param module A RegExp to match the target Webpack module
8787+ * @returns The target Webpack module
8888+ */
8989+ lazyLoad: (find: string | RegExp | (string | RegExp)[], chunk: RegExp, module: RegExp) => Promise<any>;
9090+9191+ /**
9292+ * Filter a list of Webpack modules to "real" ones from the Discord client.
9393+ * @param modules A list of Webpack modules
9494+ * @returns A filtered list of Webpack modules
9595+ */
3196 filterReal: (modules: WebpackModule[]) => WebpackModule[];
3297};
+4
packages/types/src/coreExtensions.ts
···44export * as ContextMenu from "./coreExtensions/contextMenu";
55export * as Notices from "./coreExtensions/notices";
66export * as Moonbase from "./coreExtensions/moonbase";
77+export * as AppPanels from "./coreExtensions/appPanels";
88+export * as Commands from "./coreExtensions/commands";
99+export * as ComponentEditor from "./coreExtensions/componentEditor";
1010+export * as Common from "./coreExtensions/common";
+17-2
packages/types/src/discord/require.ts
···11+import { AppPanels } from "../coreExtensions/appPanels";
22+import { Commands } from "../coreExtensions/commands";
33+import { ErrorBoundary, Icons } from "../coreExtensions/common";
44+import { DMList, MemberList, Messages } from "../coreExtensions/componentEditor";
15import { ContextMenu, EvilItemParser } from "../coreExtensions/contextMenu";
26import { Markdown } from "../coreExtensions/markdown";
77+import { Moonbase } from "../coreExtensions/moonbase";
88+import { Notices } from "../coreExtensions/notices";
39import { Settings } from "../coreExtensions/settings";
410import { Spacepack } from "../coreExtensions/spacepack";
55-import { Notices } from "../coreExtensions/notices";
66-import { Moonbase } from "../coreExtensions/moonbase";
711812declare function WebpackRequire(id: string): any;
1313+1414+declare function WebpackRequire(id: "appPanels_appPanels"): AppPanels;
1515+1616+declare function WebpackRequire(id: "commands_commands"): Commands;
1717+1818+declare function WebpackRequire(id: "common_ErrorBoundary"): ErrorBoundary;
1919+declare function WebpackRequire(id: "common_icons"): Icons;
2020+2121+declare function WebpackRequire(id: "componentEditor_dmList"): DMList;
2222+declare function WebpackRequire(id: "componentEditor_memberList"): MemberList;
2323+declare function WebpackRequire(id: "componentEditor_messages"): Messages;
9241025declare function WebpackRequire(id: "contextMenu_evilMenu"): EvilItemParser;
1126declare function WebpackRequire(id: "contextMenu_contextMenu"): ContextMenu;
···2828 };
29293030export type ExtensionManifest = {
3131+ $schema?: string;
3232+3333+ /**
3434+ * A unique identifier for your extension.
3535+ */
3136 id: string;
3737+3838+ /**
3939+ * A version string for your extension - doesn't need to follow a specific format. Required for publishing.
4040+ */
3241 version?: string;
4242+4343+ /**
4444+ * The API level this extension targets. If it does not match the current version, the extension will not be loaded.
4545+ */
3346 apiLevel?: number;
4747+4848+ /**
4949+ * Which environment this extension is capable of running in.
5050+ */
3451 environment?: ExtensionEnvironment;
35525353+ /**
5454+ * Metadata about your extension for use in Moonbase.
5555+ */
3656 meta?: {
5757+ /**
5858+ * A human friendly name for your extension as a proper noun.
5959+ */
3760 name?: string;
6161+6262+ /**
6363+ * A short tagline that appears below the name.
6464+ */
3865 tagline?: string;
6666+6767+ /**
6868+ * A longer description that can use Markdown.
6969+ */
3970 description?: string;
7171+7272+ /**
7373+ * List of authors that worked on this extension - accepts string or object with ID.
7474+ */
4075 authors?: ExtensionAuthor[];
4141- deprecated?: boolean;
7676+7777+ /**
7878+ * A list of tags that are relevant to the extension.
7979+ */
4280 tags?: ExtensionTag[];
8181+8282+ /**
8383+ * The URL to the source repository.
8484+ */
4385 source?: string;
8686+8787+ /**
8888+ * A donation link (or other method of support). If you don't want financial contributions, consider putting your favorite charity here!
8989+ */
9090+ donate?: string;
9191+9292+ /**
9393+ * A changelog to show in Moonbase.
9494+ * Moonbase will show the changelog for the latest version, even if it is not installed.
9595+ */
9696+ changelog?: string;
9797+9898+ /**
9999+ * Whether the extension is deprecated and no longer receiving updates.
100100+ */
101101+ deprecated?: boolean;
44102 };
45103104104+ /**
105105+ * A list of extension IDs that are required for the extension to load.
106106+ */
46107 dependencies?: string[];
108108+109109+ /**
110110+ * A list of extension IDs that the user may want to install.
111111+ */
47112 suggested?: string[];
113113+114114+ /**
115115+ * A list of extension IDs that the extension is incompatible with.
116116+ * If two incompatible extensions are enabled, one of them will not load.
117117+ */
48118 incompatible?: string[];
49119120120+ /**
121121+ * A list of settings for your extension, where the key is the settings ID.
122122+ */
50123 settings?: Record<string, ExtensionSettingsManifest>;
51124125125+ /**
126126+ * A list of URLs to bypass CORS for.
127127+ * This is implemented by checking if the start of the URL matches.
128128+ * @example https://moonlight-mod.github.io/
129129+ */
52130 cors?: string[];
131131+132132+ /**
133133+ * A list of URLs to block all requests to.
134134+ * This is implemented by checking if the start of the URL matches.
135135+ * @example https://moonlight-mod.github.io/
136136+ */
53137 blocked?: string[];
138138+139139+ /**
140140+ * A mapping from CSP directives to URLs to allow.
141141+ * @example { "script-src": ["https://example.com"] }
142142+ */
143143+ csp?: Record<string, string[]>;
54144};
5514556146export enum ExtensionEnvironment {
147147+ /**
148148+ * The extension will run on both platforms, the host/native modules MAY be loaded
149149+ */
57150 Both = "both",
151151+152152+ /**
153153+ * Extension will run on desktop only, the host/native modules are guaranteed to load
154154+ */
58155 Desktop = "desktop",
156156+157157+ /**
158158+ * Currently equivalent to Both
159159+ */
59160 Web = "web"
60161}
61162···75176 webpackModules?: Record<string, string>;
76177 nodePath?: string;
77178 hostPath?: string;
179179+ style?: string;
78180 };
79181};
80182···106208export type Patch = {
107209 find: PatchMatch;
108210 replace: PatchReplace | PatchReplace[];
211211+ hardFail?: boolean; // if any patches fail, all fail
109212 prerequisite?: () => boolean;
110213};
111214···133236 id: number;
134237};
135238136136-export type IdentifiedWebpackModule = ExtensionWebpackModule &
137137- ExplicitExtensionDependency;
239239+export type IdentifiedWebpackModule = ExtensionWebpackModule & ExplicitExtensionDependency;