Skip to content

Commit

Permalink
feat(Always Animate): at least made it enableable
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico040 committed May 21, 2024
1 parent 334b0ea commit 1dba51a
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugins/always-animate/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Always Animate",
"description": "Always animates guild icons and avatars.",
"authors": [
{
"name": "Cynosphere",
"id": "150745989836308480"
},
{
"name": "Rico040",
"id": "619474349845643275"
}
],
"main": "src/index.ts",
"vendetta": {
"icon": "icon-qs-gifs"
}
}
92 changes: 92 additions & 0 deletions plugins/always-animate/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {before, after} from "@vendetta/patcher";
import {findByName, findByProps} from "@vendetta/metro";
import {findInReactTree} from "@vendetta/utils";

const Avatar = findByProps("getStatusSize");
const DisplayBanner = findByName("DisplayBanner", false);
const ImageResolver = findByProps("getAvatarDecorationURL", "default");
const RowManager = findByName("RowManager");

const patches: Function[] = [];

export const onLoad = () => {
// Guild Icons
if (typeof findByName("GuildIcon").prototype.render !== "undefined") {
const GuildIcon = findByName("GuildIcon");
patches.push(
before("render", GuildIcon.prototype, function () {
this.props.animate = true;
})
);
} else {
const GuildIcon = findByName("GuildIcon", false);
patches.push(
before("default", GuildIcon, ([props]) => {
props.animate = true;
})
);
}

// Avatars (not used by chat)
patches.push(
before("type", Avatar.default, function ([props]) {
props.animate = true;
})
);

// Profile Banners (bypasses GIF playback option)
patches.push(
after("default", DisplayBanner, function (args, ret) {
const ClickWrapperProps = findInReactTree(
ret,
(x) => x.accessibilityRole == "image" && x.onPress != null
);
const Banner = findInReactTree(
ClickWrapperProps,
(x) => x.type?.name == "ProfileBanner"
);
if (
Banner &&
Banner.key.endsWith("-false") &&
Banner.props.bannerSource?.uri?.indexOf("/a_") > -1
) {
ClickWrapperProps.onPress();
}
})
);

// Catch-all
patches.push(
before("getAvatarDecorationURL", ImageResolver, ([props]) => {
props.canAnimate = true;
})
);
patches.push(
before("getUserAvatarURL", ImageResolver, (args) => {
args[1] = true;
})
);
patches.push(
before("getGuildMemberAvatarURLSimple", ImageResolver, ([props]) => {
props.canAnimate = true;
})
);

// Chat (iOS only?)
patches.push(
after("generate", RowManager.prototype, ([row], ret) => {
if (row.rowType !== 1) return;

const {message} = ret;
if (message.avatarURL?.indexOf("a_") > -1) {
message.avatarURL = message.avatarURL.replace(".webp", ".gif");
}
})
);
};

export const onUnload = () => {
for (const unpatch of patches) {
unpatch?.();
}
};

0 comments on commit 1dba51a

Please sign in to comment.