Move public servers
This commit is contained in:
parent
99ad2269ac
commit
7af885c10d
|
@ -1,26 +1,57 @@
|
|||
import Builtin from "../../structs/builtin";
|
||||
import {DiscordModules, WebpackModules, Strings, DOM} from "modules";
|
||||
import {DiscordModules, WebpackModules, Strings, DOM, React} from "modules";
|
||||
import PublicServersMenu from "../../ui/publicservers/menu";
|
||||
import Globe from "../../ui/icons/globe";
|
||||
|
||||
const LayerStack = WebpackModules.getByProps("pushLayer");
|
||||
|
||||
class ErrorBoundary extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {hasError: false};
|
||||
}
|
||||
|
||||
componentDidCatch() {
|
||||
this.setState({hasError: true});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) return null;
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
export default new class PublicServers extends Builtin {
|
||||
get name() {return "PublicServers";}
|
||||
get category() {return "general";}
|
||||
get id() {return "publicServers";}
|
||||
|
||||
enabled() {
|
||||
this._appendButton();
|
||||
const ListNavigators = WebpackModules.getByProps("ListNavigatorProvider");
|
||||
this.after(ListNavigators, "ListNavigatorProvider", (_, __, returnValue) => {
|
||||
if (returnValue.props.value.id !== "guildsnav") return;
|
||||
this._appendButton();
|
||||
const PrivateChannelList = WebpackModules.getModule(m => m?.displayName === "ConnectedPrivateChannelsList", {defaultExport: false});
|
||||
const PrivateChannelListComponents = WebpackModules.getByProps("LinkButton");
|
||||
this.after(PrivateChannelList, "default", (_, __, returnValue) => {
|
||||
const destination = returnValue?.props?.children?.props?.children;
|
||||
if (!destination || !Array.isArray(destination)) return;
|
||||
if (destination.find(b => b?.props?.children?.props?.id === "public-server-button")) return;
|
||||
|
||||
destination.push(
|
||||
React.createElement(ErrorBoundary, null,
|
||||
React.createElement(PrivateChannelListComponents.LinkButton,
|
||||
{
|
||||
id: "public-server-button",
|
||||
onClick: () => this.openPublicServers(),
|
||||
text: "Public Servers",
|
||||
icon: () => React.createElement(Globe, {color: "currentColor"})
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
disabled() {
|
||||
this.unpatchAll();
|
||||
DOM.query("#bd-pub-li").remove();
|
||||
// DOM.query("#bd-pub-li").remove();
|
||||
}
|
||||
|
||||
async _appendButton() {
|
||||
|
|
|
@ -34,9 +34,6 @@ export default new class ComponentPatcher {
|
|||
|
||||
initialize() {
|
||||
Utilities.suppressErrors(this.patchSocial.bind(this), "BD Social Patch")();
|
||||
Utilities.suppressErrors(this.patchGuildPills.bind(this), "BD Guild Pills Patch")();
|
||||
Utilities.suppressErrors(this.patchGuildListItems.bind(this), "BD Guild List Items Patch")();
|
||||
Utilities.suppressErrors(this.patchMessageHeader.bind(this), "BD Message Header Patch")();
|
||||
Utilities.suppressErrors(this.patchMemberList.bind(this), "BD Member List Patch")();
|
||||
Utilities.suppressErrors(this.patchProfile.bind(this), "BD Profile Badges Patch")();
|
||||
}
|
||||
|
@ -75,102 +72,6 @@ export default new class ComponentPatcher {
|
|||
};
|
||||
});
|
||||
}
|
||||
|
||||
patchGuildListItems() {
|
||||
if (this.guildListItemsPatch) return;
|
||||
const ListNavigators = WebpackModules.getByProps("ListNavigatorProvider");
|
||||
const GuildComponent = WebpackModules.find(m => m.type && m.type.toString().includes("guildNode") && m.type.toString().includes("treeitem"));
|
||||
if (!GuildComponent || typeof(GuildComponent.type) !== "function") return this.warn("Failed to get Guild component.");
|
||||
if (!ListNavigators || typeof(ListNavigators.ListNavigatorProvider) !== "function") return this.warn("Failed to get ListNavigatorProvider component.");
|
||||
|
||||
this.guildListItemsPatch = Patcher.after("ComponentPatcher", GuildComponent, "type", (_, [props], returnValue) => {
|
||||
if (!returnValue || !returnValue.props) return;
|
||||
|
||||
try {
|
||||
returnValue.props.className += " bd-guild";
|
||||
if (props.unread) returnValue.props.className += " bd-unread";
|
||||
if (props.selected) returnValue.props.className += " bd-selected";
|
||||
if (props.mediaState.audio) returnValue.props.className += " bd-audio";
|
||||
if (props.mediaState.video) returnValue.props.className += " bd-video";
|
||||
if (props.badge) returnValue.props.className += " bd-badge";
|
||||
if (props.animatable) returnValue.props.className += " bd-animatable";
|
||||
if (props.unavailable) returnValue.props.className += " bd-unavailable";
|
||||
if (props.mediaState.screenshare) returnValue.props.className += " bd-screenshare";
|
||||
if (props.mediaState.liveStage) returnValue.props.className += " bd-live-stage";
|
||||
if (props.muted) returnValue.props.className += " bd-muted";
|
||||
}
|
||||
catch (err) {
|
||||
Logger.error("ComponentPatcher:Guilds", `Error inside BDGuild:`, err);
|
||||
this.guildListItemsPatch();
|
||||
}
|
||||
});
|
||||
|
||||
const {useState} = DiscordModules.React;
|
||||
function useForceUpdate() {
|
||||
const [, setValue] = useState(false);
|
||||
return () => setValue(v => !v); // update the state to force render
|
||||
}
|
||||
|
||||
let hasForced = false;
|
||||
this.cancelForceUpdate = Patcher.after("ComponentPatcher", ListNavigators, "ListNavigatorProvider", (_, __, returnValue) => {
|
||||
if (returnValue.props.value.id !== "guildsnav") return;
|
||||
|
||||
const originalParent = Utilities.findInTree(returnValue, m => m?.props?.className, {walkable: ["children", "props"]});
|
||||
if (!originalParent) return;
|
||||
const original = originalParent.type;
|
||||
originalParent.type = e => {
|
||||
const forceUpdate = useForceUpdate();
|
||||
if (!hasForced) {
|
||||
hasForced = true;
|
||||
setTimeout(() => {
|
||||
forceUpdate();
|
||||
this.cancelForceUpdate();
|
||||
}, 1);
|
||||
}
|
||||
|
||||
return Reflect.apply(original, null, [e]);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
patchGuildPills() {
|
||||
if (this.guildPillPatch) return;
|
||||
const guildPill = WebpackModules.find(m => m?.default?.displayName === "AnimatedHalfPill");
|
||||
if (!guildPill) return;
|
||||
this.guildPillPatch = Patcher.after("ComponentPatcher", guildPill, "default", (_, args, returnValue) => {
|
||||
const props = args[0];
|
||||
if (props.unread) returnValue.props.className += " bd-unread";
|
||||
if (props.selected) returnValue.props.className += " bd-selected";
|
||||
if (props.hovered) returnValue.props.className += " bd-hovered";
|
||||
return returnValue;
|
||||
});
|
||||
}
|
||||
|
||||
patchMessageHeader() {
|
||||
if (this.messageHeaderPatch) return;
|
||||
// const MessageTimestamp = WebpackModules.getModule(m => m?.default?.toString().indexOf("showTimestampOnHover") > -1);
|
||||
// this.messageHeaderPatch = Patcher.after("ComponentPatcher", MessageTimestamp, "default", (_, [{message}], returnValue) => {
|
||||
// const userId = Utilities.getNestedProp(message, "author.id");
|
||||
// if (Developers.indexOf(userId) < 0) return;
|
||||
// if (!returnValue?.type) return;
|
||||
// const orig = returnValue.type;
|
||||
// returnValue.type = function() {
|
||||
// const retVal = Reflect.apply(orig, this, arguments);
|
||||
|
||||
// const children = Utilities.getNestedProp(retVal, "props.children.1.props.children");
|
||||
// if (!Array.isArray(children)) return;
|
||||
|
||||
// children.splice(3, 0,
|
||||
// React.createElement(DeveloperBadge, {
|
||||
// type: "chat"
|
||||
// })
|
||||
// );
|
||||
|
||||
// return retVal;
|
||||
// };
|
||||
|
||||
// });
|
||||
}
|
||||
|
||||
async patchMemberList() {
|
||||
if (this.memberListPatch) return;
|
||||
|
|
|
@ -3,7 +3,8 @@ import {React} from "modules";
|
|||
export default class Globe extends React.Component {
|
||||
render() {
|
||||
const size = this.props.size || "18px";
|
||||
return <svg viewBox="2 2 20 20" fill="#FFFFFF" style={{width: size, height: size}} onClick={this.props.onClick}>
|
||||
const color = this.props.color || "#FFFFFF";
|
||||
return <svg viewBox="2 2 20 20" fill={color} style={{width: size, height: size}} onClick={this.props.onClick}>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zm6.93 6h-2.95c-.32-1.25-.78-2.45-1.38-3.56 1.84.63 3.37 1.91 4.33 3.56zM12 4.04c.83 1.2 1.48 2.53 1.91 3.96h-3.82c.43-1.43 1.08-2.76 1.91-3.96zM4.26 14C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2 0 .68.06 1.34.14 2H4.26zm.82 2h2.95c.32 1.25.78 2.45 1.38 3.56-1.84-.63-3.37-1.9-4.33-3.56zm2.95-8H5.08c.96-1.66 2.49-2.93 4.33-3.56C8.81 5.55 8.35 6.75 8.03 8zM12 19.96c-.83-1.2-1.48-2.53-1.91-3.96h3.82c-.43 1.43-1.08 2.76-1.91 3.96zM14.34 14H9.66c-.09-.66-.16-1.32-.16-2 0-.68.07-1.35.16-2h4.68c.09.65.16 1.32.16 2 0 .68-.07 1.34-.16 2zm.25 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95c-.96 1.65-2.49 2.93-4.33 3.56zM16.36 14c.08-.66.14-1.32.14-2 0-.68-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2h-3.38z"/>
|
||||
</svg>;
|
||||
|
|
Loading…
Reference in New Issue