feat: Add Kettu constants
This commit is contained in:
parent
63994f9caf
commit
a59b3b95e9
3 changed files with 81 additions and 110 deletions
|
|
@ -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,9 +16,7 @@ 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 = {
|
||||
|
|
@ -33,10 +25,8 @@ const postMap = {
|
|||
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);
|
||||
},
|
||||
return isInstalled ? VdPluginManager.removePlugin(url) : VdPluginManager.installPlugin(url);
|
||||
}
|
||||
},
|
||||
Theme: {
|
||||
storage: themes,
|
||||
|
|
@ -45,31 +35,23 @@ const postMap = {
|
|||
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) {
|
||||
if (thread.parent_id === KETTU_PLUGINS_CHANNEL_ID || thread.parent_id === VD_PLUGINS_CHANNEL_ID) {
|
||||
postType = "Plugin";
|
||||
} else if (thread.parent_id === VD_THEMES_CHANNEL_ID && isThemeSupported()) {
|
||||
} 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);
|
||||
const urls = firstMessage?.content?.match(HTTP_REGEX_MULTI)?.filter(postMap[postType].urlsFilter);
|
||||
if (!urls || !urls[0]) return;
|
||||
|
||||
// Sync with lib/managers/plugins
|
||||
|
|
@ -78,13 +60,8 @@ function useExtractThreadContent(
|
|||
return [postType, urls[0]];
|
||||
}
|
||||
|
||||
function useInstaller(
|
||||
thread: any,
|
||||
firstMessage = null,
|
||||
actionSheet = false,
|
||||
): [true] | [false, PostType, boolean, boolean, () => Promise<void>] {
|
||||
const [postType, url] =
|
||||
useExtractThreadContent(thread, firstMessage, actionSheet) ?? [];
|
||||
function useInstaller(thread: any, firstMessage = null, actionSheet = false): [true] | [false, PostType, boolean, boolean, () => Promise<void>] {
|
||||
const [postType, url] = useExtractThreadContent(thread, firstMessage, actionSheet) ?? [];
|
||||
|
||||
useProxy(VdPluginManager.plugins);
|
||||
useProxy(themes);
|
||||
|
|
@ -127,17 +104,11 @@ function useInstaller(
|
|||
// </ActionsSection>);
|
||||
// });
|
||||
|
||||
const installButtonPatch = () =>
|
||||
after(
|
||||
"MostCommonForumPostReaction",
|
||||
forumReactions,
|
||||
([{ thread, firstMessage }], res) => {
|
||||
const [shouldReturn, _, installed, loading, installOrRemove] =
|
||||
useInstaller(thread, firstMessage, true);
|
||||
const installButtonPatch = () => after("MostCommonForumPostReaction", forumReactions, ([{ thread, firstMessage }], res) => {
|
||||
const [shouldReturn, _, installed, loading, installOrRemove] = useInstaller(thread, firstMessage, true);
|
||||
if (shouldReturn) return;
|
||||
|
||||
return (
|
||||
<>
|
||||
return <>
|
||||
{res}
|
||||
<ErrorBoundary>
|
||||
<Button
|
||||
|
|
@ -148,22 +119,18 @@ const installButtonPatch = () =>
|
|||
variant={installed ? "secondary" : "primary"}
|
||||
text={installed ? Strings.UNINSTALL : Strings.INSTALL}
|
||||
onPress={installOrRemove}
|
||||
icon={findAssetId(
|
||||
installed ? "ic_message_delete" : "DownloadIcon",
|
||||
)}
|
||||
icon={findAssetId(installed ? "ic_message_delete" : "DownloadIcon")}
|
||||
style={{ marginLeft: 8 }}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
</>
|
||||
);
|
||||
},
|
||||
);
|
||||
</>;
|
||||
});
|
||||
|
||||
export default () => {
|
||||
const patches = [
|
||||
// actionSheetPatch(),
|
||||
installButtonPatch(),
|
||||
installButtonPatch()
|
||||
];
|
||||
|
||||
return () => patches.map((p) => p());
|
||||
return () => patches.map(p => p());
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { installTheme } from "@lib/addons/themes";
|
|||
import { findAssetId } from "@lib/api/assets";
|
||||
import { isThemeSupported } from "@lib/api/native/loader";
|
||||
import { after, instead } from "@lib/api/patcher";
|
||||
import { VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID } from "@lib/utils/constants";
|
||||
import { VD_PROXY_PREFIX, VD_THEMES_CHANNEL_ID, KETTU_THEMES_CHANNEL_ID } from "@lib/utils/constants";
|
||||
import { lazyDestructure } from "@lib/utils/lazy";
|
||||
import { channels } from "@metro/common";
|
||||
import { byMutableProp } from "@metro/filters";
|
||||
|
|
@ -72,7 +72,8 @@ export default () => {
|
|||
// Make clicking on theme links only work in #themes, should there be a theme proxy in the future, this can be removed.
|
||||
if (
|
||||
urlType === "theme" &&
|
||||
getChannel(getChannelId())?.parent_id !== VD_THEMES_CHANNEL_ID
|
||||
getChannel(getChannelId())?.parent_id !== VD_THEMES_CHANNEL_ID &&
|
||||
getChannel(getChannelId())?.parent_id !== KETTU_THEMES_CHANNEL_ID
|
||||
)
|
||||
return orig.apply(this, args);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,5 +11,8 @@ export const OFFICIAL_PLUGINS_REPO_URL =
|
|||
|
||||
export const VD_PROXY_PREFIX = "https://vd-plugins.github.io/proxy";
|
||||
export const VD_DISCORD_SERVER_ID = "1427396621905432699";
|
||||
export const VD_PLUGINS_CHANNEL_ID = "1091880384561684561";
|
||||
export const VD_THEMES_CHANNEL_ID = "1091880434939482202";
|
||||
export const VD_PLUGINS_CHANNEL_ID = "1432796541210333284";
|
||||
export const VD_THEMES_CHANNEL_ID = "1408405946434195540";
|
||||
export const KETTU_DISCORD_SERVER_ID = "1368145952266911755";
|
||||
export const KETTU_PLUGINS_CHANNEL_ID = "1432796541210333284";
|
||||
export const KETTU_THEMES_CHANNEL_ID = "1408405946434195540";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue