rename vars, minor changes

This commit is contained in:
sadan 2024-06-06 22:40:44 -04:00
parent 89c2cd2108
commit 3bcbe7e386
No known key found for this signature in database

View file

@ -4,8 +4,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import { showNotification } from "@api/Notifications";
import { DataStore } from "@api/index"; import { DataStore } from "@api/index";
import { showNotification } from "@api/Notifications";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import { closeModal, ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -14,20 +14,20 @@ const DATA_STORE_NAME = "CFI_DATA";
interface folderIcon{ interface folderIcon{
url: string, url: string,
} }
interface folderMap { interface folderStoredData {
[key: string]: folderIcon | undefined [key: string]: folderIcon | undefined
} }
interface folderProp { interface folderProp {
folderId: string; folderId: string;
folderColor: number; folderColor: number;
} }
let d: folderMap; let folderData: folderStoredData;
export default definePlugin({ export default definePlugin({
start: async ()=>{ start: async ()=>{
d = await DataStore.get(DATA_STORE_NAME) || {} as folderMap; folderData = await DataStore.get(DATA_STORE_NAME) || {} as folderStoredData;
}, },
name: "_customFolderIcons", name: "CustomFolderIcons",
description: "customize folder icons with any png", description: "Customize folder icons with any png",
authors: [ authors: [
Devs.sadan Devs.sadan
], ],
@ -36,33 +36,28 @@ export default definePlugin({
find: ".expandedFolderIconWrapper", find: ".expandedFolderIconWrapper",
replacement: { replacement: {
match: /(return.{0,80}expandedFolderIconWrapper.*,)(\(0,..jsxs\)\(.*]}\))/, 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: { contextMenus: {
"guild-context": (c, a: folderProp) => { "guild-context": (menuItems, props: folderProp) => {
if(!("folderId" in a)) return; if(!("folderId" in props)) return;
c.push(makeContextItem(a)); menuItems.push(makeContextItem(props));
} }
}, },
commands: [ shouldReplace(props: any){
{ return folderData
name: "test", && props.folderNode.id in folderData
description: "test command for some wack shit", && folderData[props.folderNode.id]
execute: async () => { && folderData[props.folderNode.id]?.url;
}
}
],
shouldReplace(e: any){
return d && e.folderNode.id in d && d[e.folderNode.id] && d[e.folderNode.id]?.url;
}, },
replace(e: any){ replace(props: any){
if(d && d[e.folderNode.id]){ if(folderData && folderData[props.folderNode.id]){
return ( return (
<img src={d[e.folderNode.id]!.url} width={"100%"} height={"100%"} <img src={folderData[props.folderNode.id]!.url} width={"100%"} height={"100%"}
style={{ style={{
backgroundColor: int2rgba(e.folderNode.color, .4) backgroundColor: int2rgba(props.folderNode.color, .4)
}} }}
/> />
); );
@ -70,22 +65,22 @@ export default definePlugin({
} }
}); });
/** /**
* @param i RGB value * @param rgbVal RGB value
* @param a alpha bewteen zero and 1 * @param alpha alpha bewteen zero and 1
*/ */
const int2rgba = (i: number, a: number = 1)=>{ const int2rgba = (rgbVal: number, alpha: number = 1)=>{
const b = i & 0xFF, const b = rgbVal & 0xFF,
g = (i & 0xFF00) >>> 8, g = (rgbVal & 0xFF00) >>> 8,
r = (i & 0xFF0000) >>> 16; r = (rgbVal & 0xFF0000) >>> 16;
return `rgba(${[r,g,b].join(",")},${a})`; return `rgba(${[r,g,b].join(",")},${alpha})`;
}; };
const setFolderUrl = async (a: folderProp, url: string) => { const setFolderUrl = async (props: folderProp, url: string) => {
DataStore.get<folderMap>(DATA_STORE_NAME).then(v => { DataStore.get<folderStoredData>(DATA_STORE_NAME).then(data => {
v = v ?? {} as folderMap; data = data ?? {} as folderStoredData;
v[a.folderId] = { data[props.folderId] = {
url: url, 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); handleUpdateError(e);
}); });
} }
@ -96,18 +91,18 @@ const setFolderUrl = async (a: folderProp, url: string) => {
}; };
function ImageModal(folderData: folderProp){ function ImageModal(folderData: folderProp){
let v = ""; let data = "";
return( return(
<> <>
<hr /> <hr />
<TextInput onChange={(val, n) => { <TextInput onChange={(val, n) => {
v = val; data = val;
}} }}
placeholder="https://example.com/image.png" placeholder="https://example.com/image.png"
> >
</TextInput> </TextInput>
<Button onClick={() => { <Button onClick={() => {
setFolderUrl(folderData, v); setFolderUrl(folderData, data);
closeModal("custom-folder-icon"); closeModal("custom-folder-icon");
}} }}
> >
@ -118,7 +113,7 @@ function ImageModal(folderData: folderProp){
DataStore.get(DATA_STORE_NAME).then(v => { DataStore.get(DATA_STORE_NAME).then(v => {
if(!v) return; if(!v) return;
v[folderData.folderId] = undefined; v[folderData.folderId] = undefined;
d = v; folderData = v;
}); });
closeModal("custom-folder-icon"); closeModal("custom-folder-icon");
}}> }}>