From 833010fa52c42b44ba3bb9cf6c721eac4a88d2f9 Mon Sep 17 00:00:00 2001
From: sadan <117494111+sadan4@users.noreply.github.com>
Date: Wed, 5 Jun 2024 21:46:03 -0400
Subject: [PATCH 01/17] initial commit
---
src/plugins/customFolderIcons/index.tsx | 170 ++++++++++++++++++++++++
src/plugins/customFolderIcons/style.css | 7 +
src/utils/constants.ts | 4 +
3 files changed, 181 insertions(+)
create mode 100644 src/plugins/customFolderIcons/index.tsx
create mode 100644 src/plugins/customFolderIcons/style.css
diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx
new file mode 100644
index 00000000000..f2d51501aa2
--- /dev/null
+++ b/src/plugins/customFolderIcons/index.tsx
@@ -0,0 +1,170 @@
+/*
+ * Vencord, a Discord client mod
+ * Copyright (c) 2024 Vendicated and contributors
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+import "./style.css";
+
+import { DataStore } from "@api/index";
+import { Devs } from "@utils/constants";
+import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
+import definePlugin from "@utils/types";
+import { Button, Menu, TextInput } from "@webpack/common";
+const DATA_STORE_NAME = "CFI_DATA";
+enum ICON_TYPE {
+ PNG,
+ SVG
+}
+interface folderIcon{
+ type: ICON_TYPE,
+ url: string
+}
+interface config {
+ [key: string]: folderIcon
+}
+let d: config;
+export default definePlugin({
+ start: async ()=>{
+ d = await DataStore.get(DATA_STORE_NAME) || {} as config;
+ },
+ 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.test(e)"
+ }
+ }
+ ],
+ contextMenus: {
+ "guild-context": (c, a) => {
+ if(!("folderId" in a)) return;
+ c.push(makeContextItem(a.folderId));
+ }
+ },
+ commands: [
+ {
+ name: "test",
+ description: "test command for some wack shit",
+ execute: async () => {
+ console.log("asd");
+ }
+ }
+ ],
+ test(e){
+ console.log(e);
+ if(d && e.folderNode.id in d){
+ switch(d[e.folderNode.id].type){
+ case ICON_TYPE.PNG:
+ return (
+
+ );
+ case ICON_TYPE.SVG:
+ return null;
+ }
+ }
+ // TODO: when using the default set the color properly
+ return(
+
+ );
+ }
+});
+const setFolderUrl = async (id: string, url: string) => {
+ console.log(id, url);
+ DataStore.get(DATA_STORE_NAME).then(v => {
+ if(v){
+ v[id] = {
+ type: ICON_TYPE.PNG,
+ url: url
+ };
+ DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
+ handleUpdateError(e);
+ });
+ }else{
+ v = {};
+ v[id] = {
+ type: ICON_TYPE.PNG,
+ url: url
+ };
+ DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
+ handleUpdateError(e);
+ });
+ }
+ }
+ )
+ .catch(e => {
+ handleUpdateError(e);
+ });
+};
+function ImageModal(a: { folderId: string }){
+ let v = "";
+ return(
+ <>
+
+ {
+ v = val;
+ }}
+ placeholder="https://example.com/image.png"
+ >
+
+
+ >
+ );
+}
+function makeContextItem(id: string) {
+ return (
+ {
+ console.log("menu clicked");
+ openModalLazy(async () => {
+ return props => (
+
+
+
+ Set a New Icon.
+
+
+
+
+
+
+ );
+ },
+ {
+ modalKey: "custom-folder-icon"
+ });
+ }}/>
+ );
+}
+function handleUpdateError(e: any) {
+ throw e;
+}
diff --git a/src/plugins/customFolderIcons/style.css b/src/plugins/customFolderIcons/style.css
new file mode 100644
index 00000000000..26400f31424
--- /dev/null
+++ b/src/plugins/customFolderIcons/style.css
@@ -0,0 +1,7 @@
+.customFolderDefaultIcon{
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: var(--custom-folder-item-guild-icon-size);
+ height: var(--custom-folder-item-guild-icon-size);
+}
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index 4e342252690..dcb19979ae4 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -518,6 +518,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "verticalsync",
id: 328165170536775680n
},
+ sadan: {
+ name: "sadan",
+ id: 521819891141967883n
+ },
} satisfies Record);
// iife so #__PURE__ works correctly
From 25b9898c09d357a2560f98f60e57b5722d9b2c85 Mon Sep 17 00:00:00 2001
From: sadan <117494111+sadan4@users.noreply.github.com>
Date: Thu, 6 Jun 2024 21:58:13 -0400
Subject: [PATCH 02/17] fix *some* horrorcode
---
src/plugins/customFolderIcons/index.tsx | 139 ++++++++++++------------
src/plugins/customFolderIcons/style.css | 7 --
2 files changed, 69 insertions(+), 77 deletions(-)
delete mode 100644 src/plugins/customFolderIcons/style.css
diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx
index f2d51501aa2..aacf5d2fb77 100644
--- a/src/plugins/customFolderIcons/index.tsx
+++ b/src/plugins/customFolderIcons/index.tsx
@@ -4,29 +4,26 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-import "./style.css";
-
import { DataStore } from "@api/index";
import { Devs } from "@utils/constants";
import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import definePlugin from "@utils/types";
import { Button, Menu, TextInput } from "@webpack/common";
const DATA_STORE_NAME = "CFI_DATA";
-enum ICON_TYPE {
- PNG,
- SVG
-}
interface folderIcon{
- type: ICON_TYPE,
- url: string
+ url: string,
+}
+interface folderMap {
+ [key: string]: folderIcon | undefined
}
-interface config {
- [key: string]: folderIcon
+interface folderProp {
+ folderId: string;
+ folderColor: number;
}
-let d: config;
+let d: folderMap;
export default definePlugin({
start: async ()=>{
- d = await DataStore.get(DATA_STORE_NAME) || {} as config;
+ d = await DataStore.get(DATA_STORE_NAME) || {} as folderMap;
},
name: "_customFolderIcons",
description: "customize folder icons with any png",
@@ -37,15 +34,15 @@ export default definePlugin({
{
find: ".expandedFolderIconWrapper",
replacement: {
- match: /(return.{0,80}expandedFolderIconWrapper.*,)\(0,..jsxs\)\(.*]}\)/,
- replace: "$1$self.test(e)"
+ match: /(return.{0,80}expandedFolderIconWrapper.*,)(\(0,..jsxs\)\(.*]}\))/,
+ replace: "$1$self.shouldReplace(e)?$self.replace(e):$2"
}
}
],
contextMenus: {
- "guild-context": (c, a) => {
+ "guild-context": (c, a: folderProp) => {
if(!("folderId" in a)) return;
- c.push(makeContextItem(a.folderId));
+ c.push(makeContextItem(a));
}
},
commands: [
@@ -53,68 +50,52 @@ export default definePlugin({
name: "test",
description: "test command for some wack shit",
execute: async () => {
- console.log("asd");
}
}
],
- test(e){
- console.log(e);
- if(d && e.folderNode.id in d){
- switch(d[e.folderNode.id].type){
- case ICON_TYPE.PNG:
- return (
-
- );
- case ICON_TYPE.SVG:
- return null;
- }
+ shouldReplace(e: any){
+ return d && e.folderNode.id in d && d[e.folderNode.id] && d[e.folderNode.id]?.url;
+ },
+ replace(e: any){
+ if(d && d[e.folderNode.id]){
+ return (
+
+ );
}
- // TODO: when using the default set the color properly
- return(
-
- );
}
});
-const setFolderUrl = async (id: string, url: string) => {
- console.log(id, url);
- DataStore.get(DATA_STORE_NAME).then(v => {
- if(v){
- v[id] = {
- type: ICON_TYPE.PNG,
- url: url
- };
- DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
- handleUpdateError(e);
- });
- }else{
- v = {};
- v[id] = {
- type: ICON_TYPE.PNG,
- url: url
- };
- DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
- handleUpdateError(e);
- });
- }
+/**
+ * @param i RGB value
+ * @param a alpha bewteen zero and 1
+ */
+const int2rgba = (i: number, a: number = 1)=>{
+ const b = i & 0xFF,
+ g = (i & 0xFF00) >>> 8,
+ r = (i & 0xFF0000) >>> 16;
+ return `rgba(${[r,g,b].join(",")},${a})`;
+};
+const setFolderUrl = async (a: folderProp, url: string) => {
+ DataStore.get(DATA_STORE_NAME).then(v => {
+ v = v ?? {} as folderMap;
+ v[a.folderId] = {
+ // type: url.endsWith("svg") ? ICON_TYPE.SVG:ICON_TYPE.PNG,
+ url: url,
+ };
+ DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
+ handleUpdateError(e);
+ });
}
)
.catch(e => {
handleUpdateError(e);
});
};
-function ImageModal(a: { folderId: string }){
+
+function ImageModal(folderData: folderProp){
let v = "";
return(
<>
@@ -126,23 +107,34 @@ function ImageModal(a: { folderId: string }){
>
+
+
+
>
);
}
-function makeContextItem(id: string) {
+function makeContextItem(a: folderProp) {
return (
{
- console.log("menu clicked");
openModalLazy(async () => {
return props => (
@@ -154,8 +146,15 @@ function makeContextItem(id: string) {
-
+
+
+ You might have to hover the folder after setting in order for it to refresh.
+
);
},
diff --git a/src/plugins/customFolderIcons/style.css b/src/plugins/customFolderIcons/style.css
deleted file mode 100644
index 26400f31424..00000000000
--- a/src/plugins/customFolderIcons/style.css
+++ /dev/null
@@ -1,7 +0,0 @@
-.customFolderDefaultIcon{
- display: flex;
- justify-content: center;
- align-items: center;
- width: var(--custom-folder-item-guild-icon-size);
- height: var(--custom-folder-item-guild-icon-size);
-}
From ffaca84aa53cefd84b7f33f8afed9fcf562dc9c8 Mon Sep 17 00:00:00 2001
From: sadan <117494111+sadan4@users.noreply.github.com>
Date: Thu, 6 Jun 2024 22:00:50 -0400
Subject: [PATCH 03/17] guh
---
src/plugins/customFolderIcons/index.tsx | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx
index aacf5d2fb77..a162b0479f4 100644
--- a/src/plugins/customFolderIcons/index.tsx
+++ b/src/plugins/customFolderIcons/index.tsx
@@ -82,7 +82,6 @@ const setFolderUrl = async (a: folderProp, url: string) => {
DataStore.get(DATA_STORE_NAME).then(v => {
v = v ?? {} as folderMap;
v[a.folderId] = {
- // type: url.endsWith("svg") ? ICON_TYPE.SVG:ICON_TYPE.PNG,
url: url,
};
DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
From 89c2cd21082f77c0c0c6a15778cc030142ab4bba Mon Sep 17 00:00:00 2001
From: sadan <117494111+sadan4@users.noreply.github.com>
Date: Thu, 6 Jun 2024 22:04:22 -0400
Subject: [PATCH 04/17] fix error handling
---
src/plugins/customFolderIcons/index.tsx | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx
index a162b0479f4..63220df2018 100644
--- a/src/plugins/customFolderIcons/index.tsx
+++ b/src/plugins/customFolderIcons/index.tsx
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
+import { showNotification } from "@api/Notifications";
import { DataStore } from "@api/index";
import { Devs } from "@utils/constants";
import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
@@ -164,5 +165,9 @@ function makeContextItem(a: folderProp) {
);
}
function handleUpdateError(e: any) {
- throw e;
+ showNotification({
+ title: "CustomFolderIcons: Error",
+ body: "An error has occurred. Check the console for more info."
+ });
+ console.error(e);
}
From 3bcbe7e386a40a744fdb86a0c1e4aab8d45de67a Mon Sep 17 00:00:00 2001
From: sadan <117494111+sadan4@users.noreply.github.com>
Date: Thu, 6 Jun 2024 22:40:44 -0400
Subject: [PATCH 05/17] rename vars, minor changes
---
src/plugins/customFolderIcons/index.tsx | 77 ++++++++++++-------------
1 file changed, 36 insertions(+), 41 deletions(-)
diff --git a/src/plugins/customFolderIcons/index.tsx b/src/plugins/customFolderIcons/index.tsx
index 63220df2018..ef69ab601c9 100644
--- a/src/plugins/customFolderIcons/index.tsx
+++ b/src/plugins/customFolderIcons/index.tsx
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
-import { showNotification } from "@api/Notifications";
import { DataStore } from "@api/index";
+import { showNotification } from "@api/Notifications";
import { Devs } from "@utils/constants";
import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import definePlugin from "@utils/types";
@@ -14,20 +14,20 @@ const DATA_STORE_NAME = "CFI_DATA";
interface folderIcon{
url: string,
}
-interface folderMap {
+interface folderStoredData {
[key: string]: folderIcon | undefined
}
interface folderProp {
folderId: string;
folderColor: number;
}
-let d: folderMap;
+let folderData: folderStoredData;
export default definePlugin({
start: async ()=>{
- d = await DataStore.get(DATA_STORE_NAME) || {} as folderMap;
+ folderData = await DataStore.get(DATA_STORE_NAME) || {} as folderStoredData;
},
- name: "_customFolderIcons",
- description: "customize folder icons with any png",
+ name: "CustomFolderIcons",
+ description: "Customize folder icons with any png",
authors: [
Devs.sadan
],
@@ -36,33 +36,28 @@ export default definePlugin({
find: ".expandedFolderIconWrapper",
replacement: {
match: /(return.{0,80}expandedFolderIconWrapper.*,)(\(0,..jsxs\)\(.*]}\))/,
- replace: "$1$self.shouldReplace(e)?$self.replace(e):$2"
+ replace: "$1$self.shouldReplace(arguments[0])?$self.replace(arguments[0]):$2"
}
}
],
contextMenus: {
- "guild-context": (c, a: folderProp) => {
- if(!("folderId" in a)) return;
- c.push(makeContextItem(a));
+ "guild-context": (menuItems, props: folderProp) => {
+ if(!("folderId" in props)) return;
+ menuItems.push(makeContextItem(props));
}
},
- commands: [
- {
- name: "test",
- description: "test command for some wack shit",
- execute: async () => {
- }
- }
- ],
- shouldReplace(e: any){
- return d && e.folderNode.id in d && d[e.folderNode.id] && d[e.folderNode.id]?.url;
+ shouldReplace(props: any){
+ return folderData
+ && props.folderNode.id in folderData
+ && folderData[props.folderNode.id]
+ && folderData[props.folderNode.id]?.url;
},
- replace(e: any){
- if(d && d[e.folderNode.id]){
+ replace(props: any){
+ if(folderData && folderData[props.folderNode.id]){
return (
-
);
@@ -70,22 +65,22 @@ export default definePlugin({
}
});
/**
- * @param i RGB value
- * @param a alpha bewteen zero and 1
+ * @param rgbVal RGB value
+ * @param alpha alpha bewteen zero and 1
*/
-const int2rgba = (i: number, a: number = 1)=>{
- const b = i & 0xFF,
- g = (i & 0xFF00) >>> 8,
- r = (i & 0xFF0000) >>> 16;
- return `rgba(${[r,g,b].join(",")},${a})`;
+const 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})`;
};
-const setFolderUrl = async (a: folderProp, url: string) => {
- DataStore.get(DATA_STORE_NAME).then(v => {
- v = v ?? {} as folderMap;
- v[a.folderId] = {
+const setFolderUrl = async (props: folderProp, url: string) => {
+ DataStore.get(DATA_STORE_NAME).then(data => {
+ data = data ?? {} as folderStoredData;
+ data[props.folderId] = {
url: url,
};
- DataStore.set(DATA_STORE_NAME, v).then(() => { d = v; }).catch(e => {
+ DataStore.set(DATA_STORE_NAME, data).then(() => { folderData = data; }).catch(e => {
handleUpdateError(e);
});
}
@@ -96,18 +91,18 @@ const setFolderUrl = async (a: folderProp, url: string) => {
};
function ImageModal(folderData: folderProp){
- let v = "";
+ let data = "";
return(
<>
- {
- v = val;
+ {
+ data = val;
}}
placeholder="https://example.com/image.png"
>