mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-16 01:53:05 -04:00
fix first set of plugins (#2591)
* Add back mangled webpack searching * Make window non enumerable in all cases * fix some webpack commons * oops * fix more webpack commons * fix some finds * fix more webpack commons * fix common names * fix reporter * fix Constants common * more fix * fix SettingsStores (return of old SettingsStoreAPI) * doomsday fix: MutualGroupDMs (#2585) * fix SettingsStoreAPI * fix MessageLinkEmbeds * fix checking uninitialised settings * doomsday fix: BetterSessions (#2587) * doomsday fix: ReviewDB and Summaries (#2586) Co-authored-by: vee <vendicated@riseup.net> * fix various things that use default/other names * fix settings * wbctxmenus * fix BetterSettings * wouldnt it be funny if discord reverted again once we're done * fix ViewIcons * fix showconnections * fix FriendsSince * FakeNitro: fix app icons * doomsday fix: NoPendingCount (#2590) --------- Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Co-authored-by: Amia <9750071+aamiaa@users.noreply.github.com> Co-authored-by: Manti <67705577+mantikafasi@users.noreply.github.com>
This commit is contained in:
parent
db6b1f5aaf
commit
d6f1209438
45 changed files with 393 additions and 147 deletions
|
@ -17,12 +17,16 @@
|
|||
*/
|
||||
|
||||
// eslint-disable-next-line path-alias/no-relative
|
||||
import { findByPropsLazy, waitFor } from "../webpack";
|
||||
import { filters, mapMangledModuleLazy, waitFor } from "../webpack";
|
||||
import type * as t from "./types/menu";
|
||||
|
||||
export let Menu = {} as t.Menu;
|
||||
|
||||
waitFor(["MenuItem", "MenuSliderControl"], m => Menu = m);
|
||||
|
||||
export const ContextMenuApi: t.ContextMenuApi = findByPropsLazy("closeContextMenu", "openContextMenu");
|
||||
export const ContextMenuApi: t.ContextMenuApi = mapMangledModuleLazy('type:"CONTEXT_MENU_OPEN', {
|
||||
closeContextMenu: filters.byCode("CONTEXT_MENU_CLOSE"),
|
||||
openContextMenu: filters.byCode("renderLazy:"),
|
||||
openContextMenuLazy: e => typeof e === "function" && e.toString().length < 100
|
||||
});
|
||||
|
||||
|
|
|
@ -4,12 +4,9 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { findLazy } from "@webpack";
|
||||
|
||||
import * as t from "./types/settingsStores";
|
||||
|
||||
|
||||
export const TextAndImagesSettingsStores = findByPropsLazy("MessageDisplayCompact") as Record<string, t.SettingsStore>;
|
||||
export const StatusSettingsStores = findByPropsLazy("ShowCurrentGame") as Record<string, t.SettingsStore>;
|
||||
|
||||
export const UserSettingsActionCreators = findByPropsLazy("PreloadedUserSettingsActionCreators");
|
||||
export const UserSettingsActionCreators = {
|
||||
FrecencyUserSettingsActionCreators: findLazy(m => m.typeName?.endsWith(".FrecencyUserSettings")),
|
||||
PreloadedUserSettingsActionCreators: findLazy(m => m.typeName?.endsWith(".PreloadedUserSettings")),
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
import type * as Stores from "discord-types/stores";
|
||||
|
||||
// eslint-disable-next-line path-alias/no-relative
|
||||
import { findByPropsLazy } from "../webpack";
|
||||
import { findByCodeLazy, findByPropsLazy } from "../webpack";
|
||||
import { waitForStore } from "./internal";
|
||||
import * as t from "./types/stores";
|
||||
|
||||
|
@ -27,7 +27,7 @@ export const Flux: t.Flux = findByPropsLazy("connectStores");
|
|||
|
||||
export type GenericStore = t.FluxStore & Record<string, any>;
|
||||
|
||||
export const { DraftType }: { DraftType: typeof t.DraftType; } = findByPropsLazy("DraftType");
|
||||
export const DraftType = findByPropsLazy("ChannelMessage", "SlashCommand");
|
||||
|
||||
export let MessageStore: Omit<Stores.MessageStore, "getMessages"> & {
|
||||
getMessages(chanId: string): any;
|
||||
|
@ -67,7 +67,7 @@ export let DraftStore: t.DraftStore;
|
|||
* @example const user = useStateFromStores([UserStore], () => UserStore.getCurrentUser(), null, (old, current) => old.id === current.id);
|
||||
*/
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
export const useStateFromStores: t.useStateFromStores = findByPropsLazy("useStateFromStores").useStateFromStores;
|
||||
export const useStateFromStores: t.useStateFromStores = findByCodeLazy("useStateFromStores");
|
||||
|
||||
waitForStore("DraftStore", s => DraftStore = s);
|
||||
waitForStore("UserStore", s => UserStore = s);
|
||||
|
|
14
src/webpack/common/types/utils.d.ts
vendored
14
src/webpack/common/types/utils.d.ts
vendored
|
@ -168,17 +168,8 @@ export interface Clipboard {
|
|||
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;
|
||||
}
|
||||
|
||||
export interface IconUtils {
|
||||
|
@ -224,3 +215,8 @@ export interface IconUtils {
|
|||
getApplicationIconSource: any;
|
||||
getAnimatableSourceWithFallback: any;
|
||||
}
|
||||
|
||||
export interface Constants {
|
||||
Endpoints: Record<string, any>;
|
||||
UserFlags: Record<string, number>;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type { Channel, User } from "discord-types/general";
|
||||
import type { Channel } from "discord-types/general";
|
||||
|
||||
// eslint-disable-next-line path-alias/no-relative
|
||||
import { _resolveReady, filters, findByCodeLazy, findByProps, findByPropsLazy, findLazy, proxyLazyWebpack, waitFor } from "../webpack";
|
||||
import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack";
|
||||
import type * as t from "./types/utils";
|
||||
|
||||
export let FluxDispatcher: t.FluxDispatcher;
|
||||
|
@ -36,15 +36,14 @@ waitFor(["dispatch", "subscribe"], m => {
|
|||
});
|
||||
|
||||
export let ComponentDispatch;
|
||||
waitFor(["ComponentDispatch", "ComponentDispatcher"], m => ComponentDispatch = m.ComponentDispatch);
|
||||
waitFor(["dispatchToLastSubscribed"], m => ComponentDispatch = m);
|
||||
|
||||
|
||||
export const Constants = findByPropsLazy("Endpoints");
|
||||
|
||||
export const RestAPI: t.RestAPI = proxyLazyWebpack(() => {
|
||||
const mod = findByProps("getAPIBaseURL");
|
||||
return mod.HTTP ?? mod;
|
||||
export const Constants: t.Constants = mapMangledModuleLazy('ME:"/users/@me"', {
|
||||
Endpoints: filters.byProps("USER", "ME"),
|
||||
UserFlags: filters.byProps("STAFF", "SPAMMER")
|
||||
});
|
||||
|
||||
export const RestAPI: t.RestAPI = findLazy(m => typeof m === "object" && m.del && m.put);
|
||||
export const moment: typeof import("moment") = findByPropsLazy("parseTwoDigitYear");
|
||||
|
||||
export const hljs: typeof import("highlight.js") = findByPropsLazy("highlight", "registerLanguage");
|
||||
|
@ -118,30 +117,39 @@ export function showToast(message: string, type = ToastType.MESSAGE) {
|
|||
});
|
||||
}
|
||||
|
||||
export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise<User>; };
|
||||
export const UserUtils = {
|
||||
getUser: findByCodeLazy(".USER(")
|
||||
};
|
||||
|
||||
export const UploadManager = findByPropsLazy("clearAll", "addFile");
|
||||
export const UploadHandler = findByPropsLazy("showUploadFileSizeExceededError", "promptToUpload") as {
|
||||
promptToUpload: (files: File[], channel: Channel, draftType: Number) => void;
|
||||
export const UploadHandler = {
|
||||
promptToUpload: findByCodeLazy(".ATTACHMENT_TOO_MANY_ERROR_TITLE,") as (files: File[], channel: Channel, draftType: Number) => void
|
||||
};
|
||||
|
||||
export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetImage") as {
|
||||
fetchAssetIds: (applicationId: string, e: string[]) => Promise<string[]>;
|
||||
};
|
||||
|
||||
export const Clipboard: t.Clipboard = findByPropsLazy("SUPPORTS_COPY", "copy");
|
||||
export const Clipboard: t.Clipboard = mapMangledModuleLazy('queryCommandEnabled("copy")', {
|
||||
copy: filters.byCode(".copy("),
|
||||
SUPPORTS_COPY: e => typeof e === "boolean"
|
||||
});
|
||||
|
||||
export const NavigationRouter: t.NavigationRouter = findByPropsLazy("transitionTo", "replaceWith", "transitionToGuild");
|
||||
export const NavigationRouter: t.NavigationRouter = mapMangledModuleLazy("Transitioning to ", {
|
||||
transitionTo: filters.byCode("transitionTo -"),
|
||||
transitionToGuild: filters.byCode("transitionToGuild -"),
|
||||
back: filters.byCode("goBack()"),
|
||||
forward: filters.byCode("goForward()"),
|
||||
});
|
||||
|
||||
export let SettingsRouter: any;
|
||||
waitFor(["open", "saveAccountChanges"], m => SettingsRouter = m);
|
||||
|
||||
export const { Permissions: PermissionsBits } = findLazy(m => typeof m.Permissions?.ADMINISTRATOR === "bigint") as { Permissions: t.PermissionsBits; };
|
||||
export const PermissionsBits: t.PermissionsBits = findLazy(m => typeof m.ADMINISTRATOR === "bigint");
|
||||
|
||||
export const zustandCreate = findByCodeLazy("will be removed in v4");
|
||||
|
||||
const persistFilter = filters.byCode("[zustand persist middleware]");
|
||||
export const { persist: zustandPersist } = findLazy(m => m.persist && persistFilter(m.persist));
|
||||
export const zustandPersist = findByCodeLazy("[zustand persist middleware]");
|
||||
|
||||
export const MessageActions = findByPropsLazy("editMessage", "sendMessage");
|
||||
export const MessageCache = findByPropsLazy("clearCache", "_channelMessages");
|
||||
|
|
|
@ -209,14 +209,33 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
|
|||
|
||||
// There are (at the time of writing) 11 modules exporting the window
|
||||
// Make these non enumerable to improve webpack search performance
|
||||
if (require.c && (exports === window || exports?.default === window)) {
|
||||
Object.defineProperty(require.c, id, {
|
||||
value: require.c[id],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
return;
|
||||
if (require.c) {
|
||||
let foundWindow = false;
|
||||
|
||||
if (exports === window) {
|
||||
foundWindow = true;
|
||||
} else if (typeof exports === "object") {
|
||||
if (exports?.default === window) {
|
||||
foundWindow = true;
|
||||
} else {
|
||||
for (const nested in exports) if (nested.length <= 3) {
|
||||
if (exports[nested] === window) {
|
||||
foundWindow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundWindow) {
|
||||
Object.defineProperty(require.c, id, {
|
||||
value: require.c[id],
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (const callback of moduleListeners) {
|
||||
|
@ -232,9 +251,18 @@ function patchFactories(factories: Record<string, (module: any, exports: any, re
|
|||
if (exports && filter(exports)) {
|
||||
subscriptions.delete(filter);
|
||||
callback(exports, id);
|
||||
} else if (exports.default && filter(exports.default)) {
|
||||
subscriptions.delete(filter);
|
||||
callback(exports.default, id);
|
||||
} else if (typeof exports === "object") {
|
||||
if (exports.default && filter(exports.default)) {
|
||||
subscriptions.delete(filter);
|
||||
callback(exports.default, id);
|
||||
} else {
|
||||
for (const nested in exports) if (nested.length <= 3) {
|
||||
if (exports[nested] && filter(exports[nested])) {
|
||||
subscriptions.delete(filter);
|
||||
callback(exports[nested], id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error("Error while firing callback for Webpack subscription:\n", err, filter, callback);
|
||||
|
|
|
@ -112,10 +112,20 @@ export const find = traceFunction("find", function find(filter: FilterFn, { isIn
|
|||
return isWaitFor ? [mod.exports, key] : mod.exports;
|
||||
}
|
||||
|
||||
if (typeof mod.exports !== "object") continue;
|
||||
|
||||
if (mod.exports.default && filter(mod.exports.default)) {
|
||||
const found = mod.exports.default;
|
||||
return isWaitFor ? [found, key] : found;
|
||||
}
|
||||
|
||||
// the length check makes search about 20% faster
|
||||
for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
|
||||
const nested = mod.exports[nestedMod];
|
||||
if (nested && filter(nested)) {
|
||||
return isWaitFor ? [nested, key] : nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isIndirect) {
|
||||
|
@ -136,9 +146,15 @@ export function findAll(filter: FilterFn) {
|
|||
|
||||
if (filter(mod.exports))
|
||||
ret.push(mod.exports);
|
||||
else if (typeof mod.exports !== "object")
|
||||
continue;
|
||||
|
||||
if (mod.exports.default && filter(mod.exports.default))
|
||||
ret.push(mod.exports.default);
|
||||
else for (const nestedMod in mod.exports) if (nestedMod.length <= 3) {
|
||||
const nested = mod.exports[nestedMod];
|
||||
if (nested && filter(nested)) ret.push(nested);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -188,12 +204,26 @@ export const findBulk = traceFunction("findBulk", function findBulk(...filterFns
|
|||
break;
|
||||
}
|
||||
|
||||
if (typeof mod.exports !== "object")
|
||||
continue;
|
||||
|
||||
if (mod.exports.default && filter(mod.exports.default)) {
|
||||
results[j] = mod.exports.default;
|
||||
filters[j] = undefined;
|
||||
if (++found === length) break outer;
|
||||
break;
|
||||
}
|
||||
|
||||
for (const nestedMod in mod.exports)
|
||||
if (nestedMod.length <= 3) {
|
||||
const nested = mod.exports[nestedMod];
|
||||
if (nested && filter(nested)) {
|
||||
results[j] = nested;
|
||||
filters[j] = undefined;
|
||||
if (++found === length) break outer;
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,6 +432,60 @@ export function findExportedComponentLazy<T extends object = any>(...props: stri
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 The code to look for
|
||||
* @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 as any);
|
||||
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;
|
||||
});
|
||||
|
||||
/**
|
||||
* {@link mapMangledModule}, lazy.
|
||||
|
||||
* 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 The code to look for
|
||||
* @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 function mapMangledModuleLazy<S extends string>(code: string, mappers: Record<S, FilterFn>): Record<S, any> {
|
||||
return proxyLazy(() => mapMangledModule(code, mappers));
|
||||
}
|
||||
|
||||
export const DefaultExtractAndLoadChunksRegex = /(?:(?:Promise\.all\(\[)?(\i\.e\("[^)]+?"\)[^\]]*?)(?:\]\))?|Promise\.resolve\(\))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/;
|
||||
export const ChunkIdsRegex = /\("([^"]+?)"\)/g;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue