add folder icons by sadan (#274)
Some checks are pending
Test / Test (push) Waiting to run
Release / Build Equicord (push) Waiting to run

* fixed and added custom folder icons by sadan

* better regex

* better regex

* Fixes

---------

Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
vMohammad 2025-05-30 19:12:34 +03:00 committed by GitHub
parent 64a429cfbd
commit db7447a93d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 243 additions and 1 deletions

View file

@ -11,7 +11,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
### Extra included plugins
<details>
<summary>182 additional plugins</summary>
<summary>183 additional plugins</summary>
### All Platforms
@ -41,6 +41,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
- CommandPalette by Ethan
- CopyStickerLinks by Byeoon
- CopyUserMention by Cortex & castdrian
- CustomFolderIcons by sadan
- CustomSounds by TheKodeToad & SpikeHD
- CustomTimestamps by Rini & nvhrr
- CustomUserColors by mochienya

View file

@ -0,0 +1,124 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import { Button, Menu, Slider, TextInput, useState } from "@webpack/common";
import { folderIconsData, settings } from "./settings";
import { folderProp, int2rgba, setFolderData } from "./util";
export function ImageModal(folderProps: folderProp) {
const [data, setData] = useState(((settings.store.folderIcons ?? {}) as folderIconsData)[folderProps.folderId]?.url ?? "");
const [size, setSize] = useState(100);
return (
<>
<TextInput
// this looks like a horrorshow
defaultValue={data}
onChange={(val, _n) => {
setData(val);
}}
placeholder="https://example.com/image.png"
>
</TextInput>
<RenderPreview folderProps={folderProps} url={data} size={size} />
{data && <>
<div style={{
color: "#FFF"
}}>Change the size of the folder icon</div>
<Slider
initialValue={100}
onValueChange={(v: number) => {
setSize(v);
}}
maxValue={200}
minValue={25}
// [25, 200]
markers={Array.apply(0, Array(176)).map((_, i) => i + 25)}
stickToMarkers={true}
keyboardStep={1}
renderMarker={() => null} />
</>}
<Button onClick={() => {
setFolderData(folderProps, {
url: data,
size: size
});
closeModal("custom-folder-icon");
}}
>
Save
</Button>
<hr />
<Button onClick={() => {
// INFO: unset button
const folderSettings = settings.store.folderIcons as folderIconsData;
if (folderSettings[folderProps.folderId]) {
folderSettings[folderProps.folderId] = null;
}
closeModal("custom-folder-icon");
}}>
Unset
</Button>
<hr />
</>
);
}
export function RenderPreview({ folderProps, url, size }: { folderProps: folderProp; url: string; size: number; }) {
if (!url) return null;
return (
<div className="test1234" style={{
width: "20vh",
height: "20vh",
overflow: "hidden",
// 16/48
borderRadius: "33%",
backgroundColor: int2rgba(folderProps.folderColor, 0.4),
display: "flex",
justifyContent: "center",
alignItems: "center"
}}>
<img alt="" src={url} width={`${size}%`} height={`${size}%`} />
</div>
);
}
export function makeContextItem(a: folderProp) {
return (
<Menu.MenuItem
id="custom-folder-icons"
key="custom-folder-icons"
label="Change Icon"
action={() => {
openModalLazy(async () => {
return props => (
<ModalRoot {...props}>
<ModalHeader >
<div style={{
color: "white"
}}>
Set a New Icon.
</div>
</ModalHeader>
<ModalContent>
<ImageModal folderId={a.folderId} folderColor={a.folderColor} />
</ModalContent>
<div style={{
color: "white",
margin: "2.5%",
marginTop: "1%"
}}>
You might have to hover the folder after setting in order for it to refresh.
</div>
</ModalRoot>
);
},
{
modalKey: "custom-folder-icon"
});
}} />
);
}

View file

@ -0,0 +1,58 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import { makeContextItem } from "./components";
import { folderIconsData, settings } from "./settings";
import { folderProp, int2rgba } from "./util";
export default definePlugin({
name: "CustomFolderIcons",
description: "Customize folder icons with any png",
authors: [EquicordDevs.sadan],
settings,
patches: [
{
find: ".folderButtonInner",
replacement: {
match: /(\(0,\i\.jsx\)\(\i,\{folderNode:(\i),hovered:\i,sorting:\i\}\))/,
replace: "($self.shouldReplace({folderNode:$2})?$self.replace({folderNode:$2}):$1)"
}
},
],
contextMenus: {
"guild-context": (menuItems, props: folderProp) => {
if (!("folderId" in props)) return;
menuItems.push(makeContextItem(props));
}
},
shouldReplace(props: any): boolean {
return !!((settings.store.folderIcons as folderIconsData)?.[props.folderNode.id]?.url);
},
replace(props: any) {
const folderSettings = (settings.store.folderIcons as folderIconsData);
if (folderSettings && folderSettings[props.folderNode.id]) {
const data = folderSettings[props.folderNode.id];
return (
<div
style={{
backgroundColor: int2rgba(props.folderNode.color, +settings.store.solidIcon || .4),
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100%"
}}
>
<img alt="" src={data!.url} width={`${data!.size ?? 100}%`} height={`${data!.size ?? 100}%`}
/>
</div>
);
}
}
});

View file

@ -0,0 +1,28 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { OptionType } from "@utils/types";
export interface folderIcon {
url: string,
size: number,
}
export type folderIconsData = Record<string, folderIcon | null>;
export const settings = definePluginSettings({
solidIcon: {
type: OptionType.BOOLEAN,
default: false,
description: "Use a solid background on the background of the image"
},
folderIcons: {
type: OptionType.COMPONENT,
hidden: true,
description: "folder icon settings",
component: () => <></>
}
});

View file

@ -0,0 +1,31 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { folderIcon, folderIconsData, settings } from "./settings";
export async function setFolderData(props: folderProp, newData: folderIcon) {
if (!settings.store.folderIcons) {
settings.store.folderIcons = {};
}
const folderSettings = (settings.store.folderIcons as folderIconsData);
folderSettings[props.folderId] = newData;
}
export interface folderProp {
folderId: string;
folderColor: number;
}
/**
* @param rgbVal RGB value
* @param alpha alpha bewteen zero and 1
*/
export function int2rgba(rgbVal: number, alpha: number = 1) {
const b = rgbVal & 0xFF,
g = (rgbVal & 0xFF00) >>> 8,
r = (rgbVal & 0xFF0000) >>> 16;
return `rgba(${[r, g, b].join(",")},${alpha})`;
}