mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-18 05:13:29 -05:00
fix: statusPresets finds and patches (#104)
* fix: statusPresets finds and patches * fix: statusPresets modal not opening
This commit is contained in:
parent
8e9bdf7be2
commit
ac828b2340
1 changed files with 24 additions and 7 deletions
|
@ -22,11 +22,15 @@ import { definePluginSettings } from "@api/Settings";
|
|||
import { getUserSettingLazy } from "@api/UserSettings";
|
||||
import ErrorBoundary from "@components/ErrorBoundary";
|
||||
import { EquicordDevs } from "@utils/constants";
|
||||
import { proxyLazy } from "@utils/lazy";
|
||||
import { classes } from "@utils/misc";
|
||||
import { ModalProps, openModalLazy } from "@utils/modal";
|
||||
import { useForceUpdater } from "@utils/react";
|
||||
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
||||
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
||||
import { extractAndLoadChunksLazy, findByPropsLazy, findComponentByCodeLazy, findModuleId, wreq } from "@webpack";
|
||||
import { Button, Clickable, Icons, Menu, Toasts, UserStore, useState } from "@webpack/common";
|
||||
import { FunctionComponent } from "react";
|
||||
|
||||
|
||||
const settings = definePluginSettings({
|
||||
StatusPresets: {
|
||||
|
@ -51,11 +55,23 @@ interface DiscordStatus {
|
|||
}
|
||||
|
||||
const StatusStyles = findByPropsLazy("statusItem");
|
||||
// TODO: find clearCustomStatusHint original css/svg or replace
|
||||
|
||||
const PMenu = findComponentByCodeLazy(".menuItemLabel", ".menuItemInner");
|
||||
const EmojiComponent = findComponentByCodeLazy(".translateSurrogatesToInlineEmoji(");
|
||||
const EmojiComponent = findComponentByCodeLazy(/\.translateSurrogatesToInlineEmoji\(\i.\i\),/);
|
||||
|
||||
const CustomStatusSettings = getUserSettingLazy("status", "customStatus")!;
|
||||
const StatsModule: { default: FunctionComponent<ModalProps>; } = proxyLazy(() => {
|
||||
const id = findModuleId("this.renderCustomStatusInput()");
|
||||
return wreq(Number(id));
|
||||
});
|
||||
|
||||
const requireCustomStatusModal = extractAndLoadChunksLazy(["action:\"PRESS_ADD_CUSTOM_STATUS\"", ".openModalLazy"]);
|
||||
|
||||
const openCustomStatusModalLazy = () => openModalLazy(async () => {
|
||||
await requireCustomStatusModal();
|
||||
return props => <StatsModule.default {...props} />;
|
||||
});
|
||||
|
||||
function getExpirationMs(expiration: "TODAY" | number) {
|
||||
if (expiration !== "TODAY") return Date.now() + expiration;
|
||||
|
@ -140,20 +156,21 @@ export default definePlugin({
|
|||
{
|
||||
find: "#{intl::STATUS_MENU_LABEL}",
|
||||
replacement: {
|
||||
match: /!\i\i&&(.{0,20}\i\.Fragment.{0,100}null==(\i).{0,200}customEmojiPlaceholder\}\),onClick:(.*?}))/,
|
||||
replace: "$self.render($2, $3),false&&$1"
|
||||
match: /"set-status-submenu-mobile-web".{150,165}void 0\}\)/,
|
||||
replace: "$&,$self.render()"
|
||||
},
|
||||
all: true
|
||||
}
|
||||
],
|
||||
render(status: null | { emoji: Emoji | null; }, openCustomStatusModal: () => void) {
|
||||
render() {
|
||||
const status = CustomStatusSettings.getSetting();
|
||||
return <ErrorBoundary>
|
||||
<div className={StatusStyles.menuDivider} />
|
||||
{status == null ?
|
||||
<PMenu
|
||||
id="sp-custom/presets-status"
|
||||
action="PRESS_SET_STATUS"
|
||||
onClick={openCustomStatusModal}
|
||||
onClick={openCustomStatusModalLazy}
|
||||
icon={() => <div className={StatusStyles.customEmojiPlaceholder} />}
|
||||
label="Set Custom Status" renderSubmenu={StatusSubMenuComponent}
|
||||
/>
|
||||
|
@ -161,7 +178,7 @@ export default definePlugin({
|
|||
<PMenu
|
||||
id="sp-edit/presets-status"
|
||||
action="PRESS_EDIT_CUSTOM_STATUS"
|
||||
onClick={openCustomStatusModal}
|
||||
onClick={openCustomStatusModalLazy}
|
||||
hint={<ClearStatusButton />}
|
||||
icon={() => status.emoji != null ? <EmojiComponent emoji={status.emoji} animate={false} hideTooltip={false} /> : null}
|
||||
label="Edit Custom Status" renderSubmenu={StatusSubMenuComponent}
|
||||
|
|
Loading…
Reference in a new issue