Remove obsolete mapMangledModule ~ modules are no longer mangled
This commit is contained in:
parent
6869705673
commit
63451bad25
12 changed files with 46 additions and 90 deletions
|
@ -19,11 +19,9 @@
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { insertTextIntoChatInputBox } from "@utils/discord";
|
import { insertTextIntoChatInputBox } from "@utils/discord";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { filters, mapMangledModuleLazy } from "@webpack";
|
import { findByPropsLazy } from "@webpack";
|
||||||
|
|
||||||
const ExpressionPickerState = mapMangledModuleLazy('name:"expression-picker-last-active-view"', {
|
const { closeExpressionPicker } = findByPropsLazy("closeExpressionPicker");
|
||||||
close: filters.byCode("activeView:null", "setState")
|
|
||||||
});
|
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "GifPaste",
|
name: "GifPaste",
|
||||||
|
@ -41,7 +39,7 @@ export default definePlugin({
|
||||||
handleSelect(gif?: { url: string; }) {
|
handleSelect(gif?: { url: string; }) {
|
||||||
if (gif) {
|
if (gif) {
|
||||||
insertTextIntoChatInputBox(gif.url + " ");
|
insertTextIntoChatInputBox(gif.url + " ");
|
||||||
ExpressionPickerState.close();
|
closeExpressionPicker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByPropsLazy } from "@webpack";
|
import { findByPropsLazy } from "@webpack";
|
||||||
import { ContextMenu, FluxDispatcher, Menu } from "@webpack/common";
|
import { ContextMenuApi, FluxDispatcher, Menu } from "@webpack/common";
|
||||||
import { Channel, Message } from "discord-types/general";
|
import { Channel, Message } from "discord-types/general";
|
||||||
|
|
||||||
interface Sticker {
|
interface Sticker {
|
||||||
|
@ -183,6 +183,6 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (!(props.message as any).deleted)
|
if (!(props.message as any).deleted)
|
||||||
ContextMenu.open(event, () => <GreetMenu {...props} />);
|
ContextMenuApi.openContextMenu(event, () => <GreetMenu {...props} />);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ import { makeRange } from "@components/PluginSettings/components";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { debounce } from "@utils/debounce";
|
import { debounce } from "@utils/debounce";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { ContextMenu, Menu, React, ReactDOM } from "@webpack/common";
|
import { ContextMenuApi, Menu, React, ReactDOM } from "@webpack/common";
|
||||||
import type { Root } from "react-dom/client";
|
import type { Root } from "react-dom/client";
|
||||||
|
|
||||||
import { Magnifier, MagnifierProps } from "./components/Magnifier";
|
import { Magnifier, MagnifierProps } from "./components/Magnifier";
|
||||||
|
@ -89,7 +89,7 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
|
||||||
checked={settings.store.square}
|
checked={settings.store.square}
|
||||||
action={() => {
|
action={() => {
|
||||||
settings.store.square = !settings.store.square;
|
settings.store.square = !settings.store.square;
|
||||||
ContextMenu.close();
|
ContextMenuApi.closeContextMenu();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Menu.MenuCheckboxItem
|
<Menu.MenuCheckboxItem
|
||||||
|
@ -98,7 +98,7 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
|
||||||
checked={settings.store.nearestNeighbour}
|
checked={settings.store.nearestNeighbour}
|
||||||
action={() => {
|
action={() => {
|
||||||
settings.store.nearestNeighbour = !settings.store.nearestNeighbour;
|
settings.store.nearestNeighbour = !settings.store.nearestNeighbour;
|
||||||
ContextMenu.close();
|
ContextMenuApi.closeContextMenu();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Menu.MenuControlItem
|
<Menu.MenuControlItem
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { Flex } from "@components/Flex";
|
||||||
import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
|
import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
|
||||||
import { getUniqueUsername } from "@utils/discord";
|
import { getUniqueUsername } from "@utils/discord";
|
||||||
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
|
||||||
import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
|
import { ContextMenuApi, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
|
||||||
import type { Guild } from "discord-types/general";
|
import type { Guild } from "discord-types/general";
|
||||||
|
|
||||||
import { settings } from "..";
|
import { settings } from "..";
|
||||||
|
@ -111,7 +111,7 @@ function RolesAndUsersPermissionsComponent({ permissions, guild, modalProps, hea
|
||||||
className={cl("perms-list-item", { "perms-list-item-active": selectedItemIndex === index })}
|
className={cl("perms-list-item", { "perms-list-item-active": selectedItemIndex === index })}
|
||||||
onContextMenu={e => {
|
onContextMenu={e => {
|
||||||
if ((settings.store as any).unsafeViewAsRole && permission.type === PermissionType.Role)
|
if ((settings.store as any).unsafeViewAsRole && permission.type === PermissionType.Role)
|
||||||
ContextMenu.open(e, () => (
|
ContextMenuApi.openContextMenu(e, () => (
|
||||||
<RoleContextMenu
|
<RoleContextMenu
|
||||||
guild={guild}
|
guild={guild}
|
||||||
roleId={permission.id!}
|
roleId={permission.id!}
|
||||||
|
@ -194,7 +194,7 @@ function RoleContextMenu({ guild, roleId, onClose }: { guild: Guild; roleId: str
|
||||||
return (
|
return (
|
||||||
<Menu.Menu
|
<Menu.Menu
|
||||||
navId={cl("role-context-menu")}
|
navId={cl("role-context-menu")}
|
||||||
onClose={ContextMenu.close}
|
onClose={ContextMenuApi.closeContextMenu}
|
||||||
aria-label="Role Options"
|
aria-label="Role Options"
|
||||||
>
|
>
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons";
|
||||||
import { debounce } from "@utils/debounce";
|
import { debounce } from "@utils/debounce";
|
||||||
import { openImageModal } from "@utils/discord";
|
import { openImageModal } from "@utils/discord";
|
||||||
import { classes, copyWithToast } from "@utils/misc";
|
import { classes, copyWithToast } from "@utils/misc";
|
||||||
import { ContextMenu, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common";
|
import { ContextMenuApi, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common";
|
||||||
|
|
||||||
import { SpotifyStore, Track } from "./SpotifyStore";
|
import { SpotifyStore, Track } from "./SpotifyStore";
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ function CopyContextMenu({ name, path }: { name: string; path: string; }) {
|
||||||
|
|
||||||
function makeContextMenu(name: string, path: string) {
|
function makeContextMenu(name: string, path: string) {
|
||||||
return (e: React.MouseEvent<HTMLElement, MouseEvent>) =>
|
return (e: React.MouseEvent<HTMLElement, MouseEvent>) =>
|
||||||
ContextMenu.open(e, () => <CopyContextMenu name={name} path={path} />);
|
ContextMenuApi.openContextMenu(e, () => <CopyContextMenu name={name} path={path} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Controls() {
|
function Controls() {
|
||||||
|
@ -277,7 +277,7 @@ function Info({ track }: { track: Track; }) {
|
||||||
alt="Album Image"
|
alt="Album Image"
|
||||||
onClick={() => setCoverExpanded(!coverExpanded)}
|
onClick={() => setCoverExpanded(!coverExpanded)}
|
||||||
onContextMenu={e => {
|
onContextMenu={e => {
|
||||||
ContextMenu.open(e, () => <AlbumContextMenu track={track} />);
|
ContextMenuApi.openContextMenu(e, () => <AlbumContextMenu track={track} />);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { filters, findByProps, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
|
import { findByProps, findByPropsLazy } from "@webpack";
|
||||||
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
|
import type { ComponentType, PropsWithChildren, ReactNode, Ref } from "react";
|
||||||
|
|
||||||
import { LazyComponent } from "./react";
|
import { LazyComponent } from "./react";
|
||||||
|
@ -49,13 +49,7 @@ export interface ModalOptions {
|
||||||
|
|
||||||
type RenderFunction = (props: ModalProps) => ReactNode;
|
type RenderFunction = (props: ModalProps) => ReactNode;
|
||||||
|
|
||||||
export const Modals = mapMangledModuleLazy(".closeWithCircleBackground", {
|
export const Modals = findByPropsLazy("ModalRoot", "ModalCloseButton") as {
|
||||||
ModalRoot: filters.byCode(".root"),
|
|
||||||
ModalHeader: filters.byCode(".header"),
|
|
||||||
ModalContent: filters.byCode(".content"),
|
|
||||||
ModalFooter: filters.byCode(".footerSeparator"),
|
|
||||||
ModalCloseButton: filters.byCode(".closeWithCircleBackground"),
|
|
||||||
}) as {
|
|
||||||
ModalRoot: ComponentType<PropsWithChildren<{
|
ModalRoot: ComponentType<PropsWithChildren<{
|
||||||
transitionState: ModalTransitionState;
|
transitionState: ModalTransitionState;
|
||||||
size?: ModalSize;
|
size?: ModalSize;
|
||||||
|
|
|
@ -17,16 +17,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// eslint-disable-next-line path-alias/no-relative
|
// eslint-disable-next-line path-alias/no-relative
|
||||||
import { filters, mapMangledModuleLazy, waitFor } from "../webpack";
|
import { findByPropsLazy, waitFor } from "../webpack";
|
||||||
import type * as t from "./types/menu";
|
import type * as t from "./types/menu";
|
||||||
|
|
||||||
export let Menu = {} as t.Menu;
|
export let Menu = {} as t.Menu;
|
||||||
|
|
||||||
waitFor(["MenuItem", "MenuSliderControl"], m => Menu = m);
|
waitFor(["MenuItem", "MenuSliderControl"], m => Menu = m);
|
||||||
|
|
||||||
export const ContextMenu: t.ContextMenuApi = mapMangledModuleLazy('type:"CONTEXT_MENU_OPEN"', {
|
export const ContextMenuApi: t.ContextMenuApi = findByPropsLazy("closeContextMenu", "openContextMenu");
|
||||||
open: filters.byCode("stopPropagation"),
|
|
||||||
openLazy: m => m.toString().length < 50,
|
|
||||||
close: filters.byCode("CONTEXT_MENU_CLOSE")
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
import type * as Stores from "discord-types/stores";
|
import type * as Stores from "discord-types/stores";
|
||||||
|
|
||||||
// eslint-disable-next-line path-alias/no-relative
|
// eslint-disable-next-line path-alias/no-relative
|
||||||
import { filters, findByPropsLazy, mapMangledModuleLazy } from "../webpack";
|
import { findByPropsLazy } from "../webpack";
|
||||||
import { waitForStore } from "./internal";
|
import { waitForStore } from "./internal";
|
||||||
import * as t from "./types/stores";
|
import * as t from "./types/stores";
|
||||||
|
|
||||||
|
@ -62,10 +62,6 @@ export let EmojiStore: t.EmojiStore;
|
||||||
export let WindowStore: t.WindowStore;
|
export let WindowStore: t.WindowStore;
|
||||||
export let DraftStore: t.DraftStore;
|
export let DraftStore: t.DraftStore;
|
||||||
|
|
||||||
export const MaskedLinkStore = mapMangledModuleLazy('"MaskedLinkStore"', {
|
|
||||||
openUntrustedLink: filters.byCode(".apply(this,arguments)")
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React hook that returns stateful data for one or more stores
|
* React hook that returns stateful data for one or more stores
|
||||||
* You might need a custom comparator (4th argument) if your store data is an object
|
* You might need a custom comparator (4th argument) if your store data is an object
|
||||||
|
|
6
src/webpack/common/types/menu.d.ts
vendored
6
src/webpack/common/types/menu.d.ts
vendored
|
@ -75,14 +75,14 @@ export interface Menu {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ContextMenuApi {
|
export interface ContextMenuApi {
|
||||||
close(): void;
|
closeContextMenu(): void;
|
||||||
open(
|
openContextMenu(
|
||||||
event: UIEvent,
|
event: UIEvent,
|
||||||
render?: Menu["Menu"],
|
render?: Menu["Menu"],
|
||||||
options?: { enableSpellCheck?: boolean; },
|
options?: { enableSpellCheck?: boolean; },
|
||||||
renderLazy?: () => Promise<Menu["Menu"]>
|
renderLazy?: () => Promise<Menu["Menu"]>
|
||||||
): void;
|
): void;
|
||||||
openLazy(
|
openContextMenuLazy(
|
||||||
event: UIEvent,
|
event: UIEvent,
|
||||||
renderLazy?: () => Promise<Menu["Menu"]>,
|
renderLazy?: () => Promise<Menu["Menu"]>,
|
||||||
options?: { enableSpellCheck?: boolean; }
|
options?: { enableSpellCheck?: boolean; }
|
||||||
|
|
21
src/webpack/common/types/utils.d.ts
vendored
21
src/webpack/common/types/utils.d.ts
vendored
|
@ -161,3 +161,24 @@ export interface i18n {
|
||||||
|
|
||||||
Messages: Record<i18nMessages, any>;
|
Messages: Record<i18nMessages, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Clipboard {
|
||||||
|
copy(text: string): void;
|
||||||
|
SUPPORTS_COPY: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NavigationRouter {
|
||||||
|
back(): void;
|
||||||
|
forward(): void;
|
||||||
|
hasNavigated(): boolean;
|
||||||
|
getHistory(): {
|
||||||
|
action: string;
|
||||||
|
length: 50;
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
|
transitionTo(path: string, ...args: unknown[]): void;
|
||||||
|
transitionToGuild(guildId: string, ...args: unknown[]): void;
|
||||||
|
replaceWith(...args: unknown[]): void;
|
||||||
|
getLastRouteChangeSource(): any;
|
||||||
|
getLastRouteChangeSourceLocationStack(): any;
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { proxyLazy } from "@utils/lazy";
|
||||||
import type { Channel, User } from "discord-types/general";
|
import type { Channel, User } from "discord-types/general";
|
||||||
|
|
||||||
// eslint-disable-next-line path-alias/no-relative
|
// eslint-disable-next-line path-alias/no-relative
|
||||||
import { _resolveReady, filters, find, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
|
import { _resolveReady, find, findByPropsLazy, findLazy, waitFor } from "../webpack";
|
||||||
import type * as t from "./types/utils";
|
import type * as t from "./types/utils";
|
||||||
|
|
||||||
export let FluxDispatcher: t.FluxDispatcher;
|
export let FluxDispatcher: t.FluxDispatcher;
|
||||||
|
@ -102,17 +102,9 @@ export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetI
|
||||||
fetchAssetIds: (applicationId: string, e: string[]) => Promise<string[]>;
|
fetchAssetIds: (applicationId: string, e: string[]) => Promise<string[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
|
export const Clipboard: t.Clipboard = findByPropsLazy("SUPPORTS_COPY", "copy");
|
||||||
copy: filters.byCode(".copy("),
|
|
||||||
SUPPORTS_COPY: x => typeof x === "boolean",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const NavigationRouter = mapMangledModuleLazy("transitionToGuild - ", {
|
export const NavigationRouter: t.NavigationRouter = findByPropsLazy("transitionTo", "replaceWith", "transitionToGuild");
|
||||||
transitionTo: filters.byCode("transitionTo -"),
|
|
||||||
transitionToGuild: filters.byCode("transitionToGuild -"),
|
|
||||||
goBack: filters.byCode("goBack()"),
|
|
||||||
goForward: filters.byCode("goForward()"),
|
|
||||||
});
|
|
||||||
|
|
||||||
waitFor(["dispatch", "subscribe"], m => {
|
waitFor(["dispatch", "subscribe"], m => {
|
||||||
FluxDispatcher = m;
|
FluxDispatcher = m;
|
||||||
|
|
|
@ -312,47 +312,6 @@ export const findModuleId = traceFunction("findModuleId", function findModuleId(
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds a mangled module by the provided code "code" (must be unique and can be anywhere in the module)
|
|
||||||
* then maps it into an easily usable module via the specified mappers
|
|
||||||
* @param code Code snippet
|
|
||||||
* @param mappers Mappers to create the non mangled exports
|
|
||||||
* @returns Unmangled exports as specified in mappers
|
|
||||||
*
|
|
||||||
* @example mapMangledModule("headerIdIsManaged:", {
|
|
||||||
* openModal: filters.byCode("headerIdIsManaged:"),
|
|
||||||
* closeModal: filters.byCode("key==")
|
|
||||||
* })
|
|
||||||
*/
|
|
||||||
export const mapMangledModule = traceFunction("mapMangledModule", function mapMangledModule<S extends string>(code: string, mappers: Record<S, FilterFn>): Record<S, any> {
|
|
||||||
const exports = {} as Record<S, any>;
|
|
||||||
|
|
||||||
const id = findModuleId(code);
|
|
||||||
if (id === null)
|
|
||||||
return exports;
|
|
||||||
|
|
||||||
const mod = wreq(id);
|
|
||||||
outer:
|
|
||||||
for (const key in mod) {
|
|
||||||
const member = mod[key];
|
|
||||||
for (const newName in mappers) {
|
|
||||||
// if the current mapper matches this module
|
|
||||||
if (mappers[newName](member)) {
|
|
||||||
exports[newName] = member;
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return exports;
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {@link mapMangledModule} but lazy
|
|
||||||
*/
|
|
||||||
export function mapMangledModuleLazy<S extends string>(code: string, mappers: Record<S, FilterFn>): Record<S, any> {
|
|
||||||
return proxyLazy(() => mapMangledModule(code, mappers));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the first module that has the specified properties
|
* Find the first module that has the specified properties
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue