diff --git a/src/core/plugins/quickinstall/forumPost.tsx b/src/core/plugins/quickinstall/forumPost.tsx index ad6fb7e..4285ad0 100644 --- a/src/core/plugins/quickinstall/forumPost.tsx +++ b/src/core/plugins/quickinstall/forumPost.tsx @@ -5,13 +5,7 @@ import { installTheme, removeTheme, themes } from "@lib/addons/themes"; import { findAssetId } from "@lib/api/assets"; import { isThemeSupported } from "@lib/api/native/loader"; import { after } from "@lib/api/patcher"; -import { - HTTP_REGEX_MULTI, - VD_DISCORD_SERVER_ID, - VD_PLUGINS_CHANNEL_ID, - VD_PROXY_PREFIX, - VD_THEMES_CHANNEL_ID, -} from "@lib/utils/constants"; +import { HTTP_REGEX_MULTI, KETTU_DISCORD_SERVER_ID, KETTU_PLUGINS_CHANNEL_ID, KETTU_THEMES_CHANNEL_ID, VD_DISCORD_SERVER_ID, VD_PLUGINS_CHANNEL_ID, VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID } from "@lib/utils/constants"; import { lazyDestructure } from "@lib/utils/lazy"; import { Button } from "@metro/common/components"; import { findByProps, findByPropsLazy } from "@metro/wrappers"; @@ -22,91 +16,74 @@ type PostType = "Plugin" | "Theme"; // const ForumPostLongPressActionSheet = findByNameProxy("ForumPostLongPressActionSheet", false); // const { ActionSheetRow } = findByPropsProxy("ActionSheetRow"); -const { useFirstForumPostMessage } = lazyDestructure(() => - findByProps("useFirstForumPostMessage"), -); +const { useFirstForumPostMessage } = lazyDestructure(() => findByProps("useFirstForumPostMessage")); const forumReactions = findByPropsLazy("MostCommonForumPostReaction"); const postMap = { - Plugin: { - storage: VdPluginManager.plugins, - urlsFilter: (url: string) => url.startsWith(VD_PROXY_PREFIX), - installOrRemove: (url: string) => { - const isInstalled = postMap.Plugin.storage[url]; - return isInstalled - ? VdPluginManager.removePlugin(url) - : VdPluginManager.installPlugin(url); + Plugin: { + storage: VdPluginManager.plugins, + urlsFilter: (url: string) => url.startsWith(VD_PROXY_PREFIX), + installOrRemove: (url: string) => { + const isInstalled = postMap.Plugin.storage[url]; + return isInstalled ? VdPluginManager.removePlugin(url) : VdPluginManager.installPlugin(url); + } }, - }, - Theme: { - storage: themes, - urlsFilter: (url: string) => url.endsWith(".json"), - installOrRemove: (url: string) => { - const isInstalled = postMap.Theme.storage[url]; - return isInstalled ? removeTheme(url) : installTheme(url); - }, - }, + Theme: { + storage: themes, + urlsFilter: (url: string) => url.endsWith(".json"), + installOrRemove: (url: string) => { + const isInstalled = postMap.Theme.storage[url]; + return isInstalled ? removeTheme(url) : installTheme(url); + }, + } }; -function useExtractThreadContent( - thread: any, - _firstMessage = null, - actionSheet = false, -): [PostType, string] | void { - if (thread.guild_id !== VD_DISCORD_SERVER_ID) return; +function useExtractThreadContent(thread: any, _firstMessage = null, actionSheet = false): ([PostType, string]) | void { + if (thread.guild_id !== KETTU_DISCORD_SERVER_ID && thread.guild_id !== VD_DISCORD_SERVER_ID) return; - // Determine what type of addon this is. - let postType: PostType; - if (thread.parent_id === VD_PLUGINS_CHANNEL_ID) { - postType = "Plugin"; - } else if (thread.parent_id === VD_THEMES_CHANNEL_ID && isThemeSupported()) { - postType = "Theme"; - } else return; + // Determine what type of addon this is. + let postType: PostType; + if (thread.parent_id === KETTU_PLUGINS_CHANNEL_ID || thread.parent_id === VD_PLUGINS_CHANNEL_ID) { + postType = "Plugin"; + } else if ((thread.parent_id === KETTU_THEMES_CHANNEL_ID || thread.parent_id === VD_THEMES_CHANNEL_ID) && isThemeSupported()) { + postType = "Theme"; + } else return; - const { firstMessage } = actionSheet - ? useFirstForumPostMessage(thread) - : { firstMessage: _firstMessage }; + const { firstMessage } = actionSheet ? useFirstForumPostMessage(thread) : { firstMessage: _firstMessage }; - const urls = firstMessage?.content - ?.match(HTTP_REGEX_MULTI) - ?.filter(postMap[postType].urlsFilter); - if (!urls || !urls[0]) return; + const urls = firstMessage?.content?.match(HTTP_REGEX_MULTI)?.filter(postMap[postType].urlsFilter); + if (!urls || !urls[0]) return; - // Sync with lib/managers/plugins - if (postType === "Plugin" && !urls[0].endsWith("/")) urls[0] += "/"; + // Sync with lib/managers/plugins + if (postType === "Plugin" && !urls[0].endsWith("/")) urls[0] += "/"; - return [postType, urls[0]]; + return [postType, urls[0]]; } -function useInstaller( - thread: any, - firstMessage = null, - actionSheet = false, -): [true] | [false, PostType, boolean, boolean, () => Promise] { - const [postType, url] = - useExtractThreadContent(thread, firstMessage, actionSheet) ?? []; +function useInstaller(thread: any, firstMessage = null, actionSheet = false): [true] | [false, PostType, boolean, boolean, () => Promise] { + const [postType, url] = useExtractThreadContent(thread, firstMessage, actionSheet) ?? []; - useProxy(VdPluginManager.plugins); - useProxy(themes); + useProxy(VdPluginManager.plugins); + useProxy(themes); - const [isInstalling, setIsInstalling] = React.useState(false); + const [isInstalling, setIsInstalling] = React.useState(false); - if (!postType || !url) return [true]; + if (!postType || !url) return [true]; - const isInstalled = Boolean(postMap[postType].storage[url]); + const isInstalled = Boolean(postMap[postType].storage[url]); - const installOrRemove = async () => { - setIsInstalling(true); - try { - await postMap[postType].installOrRemove(url); - } catch (e: any) { - showToast(e.message, findAssetId("Small")); - } finally { - setIsInstalling(false); - } - }; + const installOrRemove = async () => { + setIsInstalling(true); + try { + await postMap[postType].installOrRemove(url); + } catch (e: any) { + showToast(e.message, findAssetId("Small")); + } finally { + setIsInstalling(false); + } + }; - return [false, postType, isInstalled, isInstalling, installOrRemove]; + return [false, postType, isInstalled, isInstalling, installOrRemove]; } // // apparently broken??? @@ -127,43 +104,33 @@ function useInstaller( // ); // }); -const installButtonPatch = () => - after( - "MostCommonForumPostReaction", - forumReactions, - ([{ thread, firstMessage }], res) => { - const [shouldReturn, _, installed, loading, installOrRemove] = - useInstaller(thread, firstMessage, true); - if (shouldReturn) return; +const installButtonPatch = () => after("MostCommonForumPostReaction", forumReactions, ([{ thread, firstMessage }], res) => { + const [shouldReturn, _, installed, loading, installOrRemove] = useInstaller(thread, firstMessage, true); + if (shouldReturn) return; - return ( - <> - {res} - + return <> + {res} +