Compare commits

...

29 commits

Author SHA1 Message Date
sadan4
3efdb6b7bb
Merge 8c6104305b into a015cf96f6 2024-09-19 18:37:13 +02:00
Nuckyz
a015cf96f6
UserVoiceShow: Fix setting name
Some checks are pending
Sync to Codeberg / codeberg (push) Waiting to run
test / test (push) Waiting to run
2024-09-19 13:33:32 -03:00
sadan4
8c6104305b
Discard changes to src/utils/constants.ts 2024-09-14 15:16:27 -04:00
sadan4
50ce282284
Merge branch 'dev' into customFolderIcons 2024-09-14 15:16:10 -04:00
sadan4
2272e1dfaa
Merge branch 'dev' into customFolderIcons 2024-09-02 01:10:02 -04:00
sadan4
bcb0c4100f
Merge branch 'main' into customFolderIcons 2024-08-05 17:12:47 -04:00
sadan4
8a0b8b60b5
Merge branch 'main' into customFolderIcons 2024-07-30 23:13:40 -04:00
sadan
7eeeceea1c
rename and add setting 2024-07-29 23:37:53 -04:00
sadan4
073b561db1
Merge branch 'main' into customFolderIcons 2024-07-29 23:23:52 -04:00
sadan4
487bb264c8
Merge branch 'main' into customFolderIcons 2024-07-17 01:58:52 -04:00
sadan
543d1de570
inline var 2024-07-02 16:01:05 -04:00
sadan4
7cf5fab128
Update README.md 2024-07-02 11:07:12 -04:00
sadan4
eb2ef2298b
remove newline
Co-authored-by: Scyye <97131358+Scyye@users.noreply.github.com>
2024-07-02 10:55:45 -04:00
sadan
f5dffe12c2
fix imports 2024-07-01 23:55:07 -04:00
sadan4
240ce8b07f
Update plugin readme and add images 2024-06-30 00:07:47 -04:00
sadan4
ab7cf5dfa9
Merge branch 'main' into customFolderIcons 2024-06-30 00:02:25 -04:00
sadan
3b969e55ef
bunch of stuff
- fix preview
- fix settings
- update headers
- add readme
2024-06-29 23:56:51 -04:00
sadan
a742cc2b53
complete settings overhaul, still needs work. see FIXME: 2024-06-29 03:04:30 -04:00
sadan
f4ca72c6f6
add settings 2024-06-29 01:46:00 -04:00
sadan4
d9e8a86688
Merge branch 'main' into customFolderIcons 2024-06-29 01:45:33 -04:00
sadan4
253bfa1ea2
Merge branch 'main' into customFolderIcons 2024-06-27 00:45:29 -04:00
sadan
5a96c0bb54
Merge branch 'main' into customFolderIcons 2024-06-19 15:37:59 -04:00
sadan
915e14ddab
add things
- add size slider
- add preview when setting
2024-06-17 13:53:04 -04:00
sadan
a7a461309d
fix bug 2024-06-07 01:20:41 -04:00
sadan
3bcbe7e386
rename vars, minor changes 2024-06-06 22:40:44 -04:00
sadan
89c2cd2108
fix error handling 2024-06-06 22:04:22 -04:00
sadan
ffaca84aa5
guh 2024-06-06 22:00:50 -04:00
sadan
25b9898c09
fix *some* horrorcode 2024-06-06 21:58:13 -04:00
sadan
833010fa52
initial commit 2024-06-05 21:46:03 -04:00
8 changed files with 284 additions and 29 deletions

View file

@ -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)

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 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"
});
}}/>
);
}

View file

@ -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>
);
}
}
});

View file

@ -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;

View file

@ -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})`;
}

View file

@ -8,7 +8,7 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, showToast, Text, Toasts, Tooltip, useCallback, useMemo, UserStore, useStateFromStores } from "@webpack/common"; import { ChannelStore, GuildStore, IconUtils, NavigationRouter, PermissionsBits, PermissionStore, React, showToast, Text, Toasts, Tooltip, useMemo, UserStore, useStateFromStores } from "@webpack/common";
import { Channel } from "discord-types/general"; import { Channel } from "discord-types/general";
const cl = classNameFactory("vc-uvs-"); const cl = classNameFactory("vc-uvs-");
@ -17,7 +17,7 @@ const { selectVoiceChannel } = findByPropsLazy("selectChannel", "selectVoiceChan
const VoiceStateStore = findStoreLazy("VoiceStateStore"); const VoiceStateStore = findStoreLazy("VoiceStateStore");
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
interface IconProps extends React.HTMLAttributes<HTMLDivElement> { interface IconProps extends React.ComponentPropsWithoutRef<"div"> {
size?: number; size?: number;
} }
@ -71,23 +71,18 @@ interface VoiceChannelTooltipProps {
function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) { function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id)); const voiceStates = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStatesForChannel(channel.id));
const users = useMemo( const users = useMemo(
() => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null), () => Object.values<any>(voiceStates).map(voiceState => UserStore.getUser(voiceState.userId)).filter(user => user != null),
[voiceStates] [voiceStates]
); );
const guild = useMemo( const guild = channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId());
() => channel.getGuildId() == null ? undefined : GuildStore.getGuild(channel.getGuildId()), const guildIcon = guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
[channel] id: guild.id,
); icon: guild.icon,
size: 30
const guildIcon = useMemo(() => { });
return guild?.icon == null ? undefined : IconUtils.getGuildIconURL({
id: guild.id,
icon: guild.icon,
size: 30
});
}, [guild]);
return ( return (
<> <>
@ -103,7 +98,7 @@ function VoiceChannelTooltip({ channel }: VoiceChannelTooltipProps) {
<UserSummaryItem <UserSummaryItem
users={users} users={users}
renderIcon={false} renderIcon={false}
max={7} max={13}
size={18} size={18}
/> />
</div> </div>
@ -119,11 +114,14 @@ const clickTimers = {} as Record<string, any>;
export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => { export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChannelIndicatorProps) => {
const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined); const channelId = useStateFromStores([VoiceStateStore], () => VoiceStateStore.getVoiceStateForUser(userId)?.channelId as string | undefined);
const channel = useMemo(() => channelId == null ? undefined : ChannelStore.getChannel(channelId), [channelId]);
const onClick = useCallback((e: React.MouseEvent) => { const channel = channelId == null ? undefined : ChannelStore.getChannel(channelId);
if (channel == null) return null;
function onClick(e: React.MouseEvent) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (channel == null || channelId == null) return; if (channel == null || channelId == null) return;
if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) { if (!PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel)) {
@ -147,18 +145,15 @@ export const VoiceChannelIndicator = ErrorBoundary.wrap(({ userId }: VoiceChanne
delete clickTimers[channelId]; delete clickTimers[channelId];
}, 250); }, 250);
} }
}, [channelId]); }
const isLocked = useMemo(() => { const isLocked = !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
return !PermissionStore.can(PermissionsBits.VIEW_CHANNEL, channel) || !PermissionStore.can(PermissionsBits.CONNECT, channel);
}, [channelId]);
if (channel == null) return null;
return ( return (
<Tooltip <Tooltip
text={<VoiceChannelTooltip channel={channel} />} text={<VoiceChannelTooltip channel={channel} />}
tooltipClassName={cl("tooltip-container")} tooltipClassName={cl("tooltip-container")}
tooltipContentClassName={cl("tooltip-content")}
> >
{props => {props =>
isLocked ? isLocked ?

View file

@ -32,7 +32,7 @@ const settings = definePluginSettings({
default: true, default: true,
restartNeeded: true restartNeeded: true
}, },
showInVoiceMemberList: { showInMemberList: {
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
description: "Show a user's Voice Channel indicator in the member and DMs list", description: "Show a user's Voice Channel indicator in the member and DMs list",
default: true, default: true,
@ -82,12 +82,12 @@ export default definePlugin({
match: /\.subtext,children:.+?}\)\]}\)(?=])/, match: /\.subtext,children:.+?}\)\]}\)(?=])/,
replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})" replace: "$&,$self.VoiceChannelIndicator({userId:arguments[0]?.user?.id})"
}, },
predicate: () => settings.store.showInVoiceMemberList predicate: () => settings.store.showInMemberList
} }
], ],
start() { start() {
if (settings.store.showInVoiceMemberList) { if (settings.store.showInMemberList) {
addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />); addDecorator("UserVoiceShow", ({ user }) => user == null ? null : <VoiceChannelIndicator userId={user.id} />);
} }
}, },

View file

@ -15,7 +15,13 @@
} }
.vc-uvs-tooltip-container { .vc-uvs-tooltip-container {
max-width: 200px; max-width: 300px;
}
.vc-uvs-tooltip-content {
display: flex;
flex-direction: column;
gap: 6px;
} }
.vc-uvs-guild-name { .vc-uvs-guild-name {
@ -31,7 +37,5 @@
.vc-uvs-vc-members { .vc-uvs-vc-members {
display: flex; display: flex;
margin: 8px 0;
flex-direction: row;
gap: 6px; gap: 6px;
} }