···11-- Fixes for latest Discord
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.
···22import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
33import parser from "@moonlight-mod/wp/contextMenu_evilMenu";
4455+// NOTE: We originally had item as a function that returned this, but it didn't
66+// quite know how to work out the type and thought it was a JSX element (it
77+// *technically* was). This has less type safety, but a @ts-expect-error has
88+// zero, so it's better than nothing.
99+type ReturnType = MenuElement | MenuElement[];
1010+511type Patch = {
612 navId: string;
77- item: (props: any) => MenuElement | MenuElement[];
88- anchorId: string;
1313+ item: React.FC<any>;
1414+ anchor: string | RegExp;
915 before: boolean;
1016};
11171212-function addItem<T>(navId: string, item: (props: T) => MenuElement | MenuElement[], anchorId: string, before = false) {
1313- patches.push({ navId, item, anchorId, before });
1818+function addItem<T = any>(navId: string, item: React.FC<T>, anchor: string | RegExp, before = false) {
1919+ if (anchor instanceof RegExp && anchor.flags.includes("g"))
2020+ throw new Error("anchor regular expression should not be global");
2121+ patches.push({ navId, item, anchor, before });
1422}
15231624const patches: Patch[] = [];
1725function _patchMenu(props: React.ComponentProps<Menu>, items: InternalItem[]) {
1826 const matches = patches.filter((p) => p.navId === props.navId);
1919- if (!matches.length) return;
2727+ if (!matches.length) return items;
20282129 for (const patch of matches) {
2222- const idx = items.findIndex((i) => i.key === patch.anchorId);
3030+ const idx = items.findIndex((i) =>
3131+ typeof patch.anchor === "string" ? i.key === patch.anchor : patch.anchor.test(i.key!)
3232+ );
2333 if (idx === -1) continue;
2424- items.splice(idx + 1 - +patch.before, 0, ...parser(patch.item(menuProps)));
3434+ items.splice(idx + 1 - +patch.before, 0, ...parser(patch.item(menuProps) as ReturnType));
2535 }
3636+3737+ return items;
2638}
27392840let menuProps: any;
···4658};
47594860// Unmangle Menu elements
6161+// spacepack.require.m[moonlight.moonmap.modules["discord/modules/menus/web/Menu"]].toString();
4962const code =
5063 spacepack.require.m[
5164 spacepack.findByCode("Menu API only allows Items and groups of Items as children.")[0].id
···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[
56 spacepack.findByCode("Menu API only allows Items and groups of Items as children.")[0].id
67 ].toString();
77-code = code.replace(/,.=(?=function .\(.\){.+?,.=function)/, ";return ");
88-code = code.replace(/,(?=__contextMenu)/, ";let ");
88+99+const parserSym = code.match(/(?<=_patchMenu\(.,).+?(?=\()/)![0];
1010+1111+code = code.replace(/{(.):\(\)=>./, (orig, e) => `{${e}:()=>${parserSym}`);
912const mod = new Function("module", "exports", "require", `(${code}).apply(this, arguments)`);
1313+1014const exp: any = {};
1115mod({}, exp, require);
1212-const Menu = spacepack.findFunctionByStrings(exp, "Menu API only allows Items and groups of Items as children.")!;
1313-module.exports = (el: any) => {
1414- return Menu({
1515- children: el,
1616- __contextMenu_evilMenu: true
1717- });
1818-};
1616+1717+const parser = spacepack.findFunctionByStrings(exp, "Menu API only allows Items and groups of Items as children.")!;
1818+module.exports = parser;
···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}
···3333 };
34343535export type BooleanSettingType = {
3636+ /**
3737+ * Displays as a simple switch.
3838+ */
3639 type: ExtensionSettingType.Boolean;
3740 default?: boolean;
3841};
39424043export type NumberSettingType = {
4444+ /**
4545+ * Displays as a simple slider.
4646+ */
4147 type: ExtensionSettingType.Number;
4248 default?: number;
4349 min?: number;
···4551};
46524753export type StringSettingType = {
5454+ /**
5555+ * Displays as a single line string input.
5656+ */
4857 type: ExtensionSettingType.String;
4958 default?: string;
5059};
51605261export type MultilineTextInputSettingType = {
6262+ /**
6363+ * Displays as a multiple line string input.
6464+ */
5365 type: ExtensionSettingType.MultilineString;
5466 default?: string;
5567};
56685769export type SelectSettingType = {
7070+ /**
7171+ * A dropdown to pick between one of many values.
7272+ */
5873 type: ExtensionSettingType.Select;
5974 options: SelectOption[];
6075 default?: string;
6176};
62776378export type MultiSelectSettingType = {
7979+ /**
8080+ * A dropdown to pick multiple values.
8181+ */
6482 type: ExtensionSettingType.MultiSelect;
6583 options: string[];
6684 default?: string[];
6785};
68866987export type ListSettingType = {
8888+ /**
8989+ * A list of strings that the user can add or remove from.
9090+ */
7091 type: ExtensionSettingType.List;
7192 default?: string[];
7293};
73947495export type DictionarySettingType = {
9696+ /**
9797+ * A dictionary (key-value pair) that the user can add or remove from.
9898+ */
7599 type: ExtensionSettingType.Dictionary;
76100 default?: Record<string, string>;
77101};
7810279103export type CustomSettingType = {
104104+ /**
105105+ * A custom component.
106106+ * You can use the registerConfigComponent function in the Moonbase API to register a React component to render here.
107107+ */
80108 type: ExtensionSettingType.Custom;
81109 default?: any;
82110};
83111112112+export enum ExtensionSettingsAdvice {
113113+ None = "none",
114114+ Reload = "reload",
115115+ Restart = "restart"
116116+}
117117+84118export type ExtensionSettingsManifest = {
119119+ /**
120120+ * A human friendly name for the setting.
121121+ */
85122 displayName?: string;
123123+124124+ /**
125125+ * A longer description for the setting.
126126+ * Markdown is not supported.
127127+ */
86128 description?: string;
129129+130130+ /**
131131+ * The "advice" to give upon changing this setting.
132132+ * Can be configured to reload the client, restart the client, or do nothing.
133133+ */
134134+ advice?: ExtensionSettingsAdvice;
87135} & (
88136 | BooleanSettingType
89137 | NumberSettingType
···11export 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+ */
27 addPanel: (section: string, element: React.FC<any>) => void;
88+99+ /**
1010+ * @private
1111+ */
312 getPanels: (el: React.FC<any>) => React.ReactNode;
413};
···1010} from "@moonlight-mod/mappings/discord/components/common/index";
11111212export type ContextMenu = {
1313- addItem: (navId: string, item: (props: any) => MenuElement, anchorId: string, before?: boolean) => void;
1313+ /**
1414+ * Registers a new context menu item for a given context menu type.
1515+ * @param navId The navigation ID for the target context menu (e.g. "user-context", "message")
1616+ * @param item A React component
1717+ * @param anchor An existing item's ID to anchor the new item to
1818+ * @param before Whether to insert the new item before the anchor item
1919+ */
2020+ addItem: (navId: string, item: React.FC<any>, anchor: string | RegExp, before?: boolean) => void;
14211522 MenuCheckboxItem: MenuCheckboxItem;
1623 MenuControlItem: MenuControlItem;
+15
packages/types/src/coreExtensions/markdown.ts
···8282 slateDecorators: Record<string, string>;
8383 ruleBlacklists: Record<Ruleset, Record<string, boolean>>;
84848585+ /**
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+ */
8594 addRule: (
8695 name: string,
8796 markdown: (rules: Record<string, MarkdownRule>) => MarkdownRule,
8897 slate: (rules: Record<string, SlateRule>) => SlateRule,
8998 decorator?: string | undefined
9099 ) => void;
100100+101101+ /**
102102+ * Blacklist a rule from a ruleset.
103103+ * @param ruleset The ruleset name
104104+ * @param name The rule name
105105+ */
91106 blacklistFromRuleset: (ruleset: Ruleset, name: string) => void;
92107};
+11-2
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 = {
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+ */
716 registerConfigComponent: (ext: string, option: string, component: CustomComponent) => void;
817};
+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};
+58-5
packages/types/src/coreExtensions/spacepack.ts
···11import { WebpackModule, WebpackModuleFunc, WebpackRequireType } from "../discord";
2233-// Only bothered TSDoc'ing the hard-to-understand functions
44-53export 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+ */
610 inspect: (module: number | string) => WebpackModuleFunc | null;
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+ */
717 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+ */
825 findByExports: (...args: string[]) => WebpackModule[];
99- // re-export of require
2626+2727+ /**
2828+ * The Webpack require function.
2929+ */
1030 require: WebpackRequireType;
1111- // re-export of require.m
3131+3232+ /**
3333+ * The Webpack module list.
3434+ * Re-export of require.m.
3535+ */
1236 modules: Record<string, WebpackModuleFunc>;
1313- // re-export of require.c
3737+3838+ /**
3939+ * The Webpack module cache.
4040+ * Re-export of require.c.
4141+ */
1442 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+ */
1550 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+ */
1658 findObjectFromValue: (exports: Record<string, any>, value: any) => 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+ */
1767 findObjectFromKeyValuePair: (exports: Record<string, any>, key: string, value: any) => any | null;
6868+1869 /**
1970 * Finds a function from a module's exports using the given source find.
2071 * This behaves like findByCode but localized to the exported function.
···2778 ...strings: (string | RegExp)[]
2879 // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2980 ) => Function | null;
8181+3082 /**
3183 * Lazy load a Webpack module.
3284 * @param find A list of finds to discover a target module with
···3587 * @returns The target Webpack module
3688 */
3789 lazyLoad: (find: string | RegExp | (string | RegExp)[], chunk: RegExp, module: RegExp) => Promise<any>;
9090+3891 /**
3992 * Filter a list of Webpack modules to "real" ones from the Discord client.
4093 * @param modules A list of Webpack modules
+3
packages/types/src/coreExtensions.ts
···55export * as Notices from "./coreExtensions/notices";
66export * as Moonbase from "./coreExtensions/moonbase";
77export * 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";
+12
packages/types/src/discord/require.ts
···11import { 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";
25import { ContextMenu, EvilItemParser } from "../coreExtensions/contextMenu";
36import { Markdown } from "../coreExtensions/markdown";
47import { Moonbase } from "../coreExtensions/moonbase";
···912declare function WebpackRequire(id: string): any;
10131114declare 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;
12241325declare function WebpackRequire(id: "contextMenu_evilMenu"): EvilItemParser;
1426declare function WebpackRequire(id: "contextMenu_contextMenu"): ContextMenu;
+103-1
packages/types/src/extension.ts
···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···107208export type Patch = {
108209 find: PatchMatch;
109210 replace: PatchReplace | PatchReplace[];
211211+ hardFail?: boolean; // if any patches fail, all fail
110212 prerequisite?: () => boolean;
111213};
112214