Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Plugin: Custom folder icons #2558

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
833010f
initial commit
sadan4 Jun 6, 2024
25b9898
fix *some* horrorcode
sadan4 Jun 7, 2024
ffaca84
guh
sadan4 Jun 7, 2024
89c2cd2
fix error handling
sadan4 Jun 7, 2024
3bcbe7e
rename vars, minor changes
sadan4 Jun 7, 2024
a7a4613
fix bug
sadan4 Jun 7, 2024
915e14d
add things
sadan4 Jun 17, 2024
5a96c0b
Merge branch 'main' into customFolderIcons
sadan4 Jun 19, 2024
253bfa1
Merge branch 'main' into customFolderIcons
sadan4 Jun 27, 2024
d9e8a86
Merge branch 'main' into customFolderIcons
sadan4 Jun 29, 2024
f4ca72c
add settings
sadan4 Jun 29, 2024
a742cc2
complete settings overhaul, still needs work. see FIXME:
sadan4 Jun 29, 2024
3b969e5
bunch of stuff
sadan4 Jun 30, 2024
ab7cf5d
Merge branch 'main' into customFolderIcons
sadan4 Jun 30, 2024
240ce8b
Update plugin readme and add images
sadan4 Jun 30, 2024
f5dffe1
fix imports
sadan4 Jul 2, 2024
eb2ef22
remove newline
sadan4 Jul 2, 2024
7cf5fab
Update README.md
sadan4 Jul 2, 2024
543d1de
inline var
sadan4 Jul 2, 2024
487bb26
Merge branch 'main' into customFolderIcons
sadan4 Jul 17, 2024
073b561
Merge branch 'main' into customFolderIcons
sadan4 Jul 30, 2024
7eeecee
rename and add setting
sadan4 Jul 30, 2024
8a0b8b6
Merge branch 'main' into customFolderIcons
sadan4 Jul 31, 2024
bcb0c41
Merge branch 'main' into customFolderIcons
sadan4 Aug 5, 2024
2272e1d
Merge branch 'dev' into customFolderIcons
sadan4 Sep 2, 2024
50ce282
Merge branch 'dev' into customFolderIcons
sadan4 Sep 14, 2024
8c61043
Discard changes to src/utils/constants.ts
sadan4 Sep 14, 2024
3a930b3
Merge branch 'dev' into customFolderIcons
sadan4 Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/plugins/customFolderIcons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CustomFolderIcons

Allows you to set custom images/svgs as folder icons

Available as "Change Icon" in the folder context menu

![the context menu with the "Change Icon" button](https://github.com/sadan4/Vencord/assets/117494111/3dfb843c-6964-4ac3-a0b9-8772569953d3)

![an image of some example custom folder icons](https://github.com/sadan4/Vencord/assets/117494111/c5324ab1-3b7a-4286-8cb5-41c0ceb2ea44)

![the modal used to customize the folder icons](https://github.com/sadan4/Vencord/assets/117494111/1426d350-56db-4687-8052-6c1b1ce873a1)



124 changes: 124 additions & 0 deletions src/plugins/customFolderIcons/components.tsx
Original file line number Diff line number Diff line change
@@ -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 settings, { folderIconsData } 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 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"
});
}}/>
);
}
60 changes: 60 additions & 0 deletions src/plugins/customFolderIcons/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";

import { makeContextItem } from "./components";
import settings, { folderIconsData } from "./settings";
import { folderProp, int2rgba } from "./util";

export default definePlugin({
settings,
name: "CustomFolderIcons",
description: "Customize folder icons with any png",
authors: [
Devs.sadan
],
patches: [
{
find: ".expandedFolderIconWrapper",
replacement: {
match: /(return.{0,80}expandedFolderIconWrapper.*,)(\(0,..jsxs\)\(.*]}\))/,
replace: "$1$self.shouldReplace(arguments[0])?$self.replace(arguments[0]):$2"
}
}
],
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 src={data!.url} width={`${data!.size ?? 100}%`} height={`${data!.size ?? 100}%`}
/>
</div>
);
}
}
});
29 changes: 29 additions & 0 deletions src/plugins/customFolderIcons/settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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>;

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: () => <></>
}
});
export default settings;
29 changes: 29 additions & 0 deletions src/plugins/customFolderIcons/util.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 sadan
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import settings, { folderIcon, folderIconsData } 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})`;
}