From 2105de8ca54b17a852a86efa476a4e575042b5a6 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 9 Oct 2022 19:48:42 +0200 Subject: [PATCH] Add more Webpack Commons & utils --- src/globals.d.ts | 1 + src/utils/discord.ts | 10 ++++++++++ src/utils/misc.tsx | 4 ++++ src/webpack/common.tsx | 10 ++++++++++ 4 files changed, 25 insertions(+) create mode 100644 src/utils/discord.ts diff --git a/src/globals.d.ts b/src/globals.d.ts index 292fa9625..8c5ee1026 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -5,6 +5,7 @@ declare global { export var appSettings: { set(setting: string, v: any): void; }; + export var DiscordNative: any; interface Window { webpackChunkdiscord_app: { diff --git a/src/utils/discord.ts b/src/utils/discord.ts new file mode 100644 index 000000000..53206bbf4 --- /dev/null +++ b/src/utils/discord.ts @@ -0,0 +1,10 @@ +import { Guild } from "discord-types/general"; +import { ChannelStore, SelectedChannelStore, GuildStore } from "../webpack/common"; + +export function getCurrentChannel() { + return ChannelStore.getChannel(SelectedChannelStore.getChannelId()); +} + +export function getCurrentGuild(): Guild | undefined { + return GuildStore.getGuild(getCurrentChannel()?.guild_id); +} diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx index f2228f8de..a7d781aae 100644 --- a/src/utils/misc.tsx +++ b/src/utils/misc.tsx @@ -125,3 +125,7 @@ export function humanFriendlyJoin(elements: any[], mapper: (e: any) => string = export function classes(...classes: string[]) { return classes.join(" "); } + +export function sleep(ms: number): Promise { + return new Promise(r => setTimeout(r, ms)); +} diff --git a/src/webpack/common.tsx b/src/webpack/common.tsx index 1a154893a..b795c0639 100644 --- a/src/webpack/common.tsx +++ b/src/webpack/common.tsx @@ -8,7 +8,12 @@ export const Margins = lazyWebpack(filters.byProps(["marginTop20"])); export let FluxDispatcher: Other.FluxDispatcher; export let React: typeof import("react"); + +export let GuildStore: Stores.GuildStore; export let UserStore: Stores.UserStore; +export let SelectedChannelStore: Stores.SelectedChannelStore; +export let ChannelStore: Stores.ChannelStore; + export const Forms = {} as { FormTitle: Components.FormTitle; FormSection: any; @@ -86,7 +91,12 @@ waitFor(["dispatch", "subscribe"], m => { }; m.subscribe("CONNECTION_OPEN", cb); }); + waitFor(["getCurrentUser", "initialize"], m => UserStore = m); +waitFor("getSortedPrivateChannels", m => ChannelStore = m); +waitFor("getCurrentlySelectedChannelId", m => SelectedChannelStore = m); +waitFor("getGuildCount", m => GuildStore = m); + waitFor(["Hovers", "Looks", "Sizes"], m => Button = m); waitFor(filters.byCode("helpdeskArticleId"), m => Switch = m); waitFor(["Positions", "Colors"], m => Tooltip = m);