CustomUserColors: Fix Some Readability

This commit is contained in:
thororen1234 2025-06-14 13:05:15 -04:00
parent f614b92a7a
commit 7e2b8c1904
No known key found for this signature in database
5 changed files with 26 additions and 12 deletions

View file

@ -62,6 +62,7 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: {
}; };
export function getCustomColorString(userId: string, withHash?: boolean): string | undefined { export function getCustomColorString(userId: string, withHash?: boolean): string | undefined {
if (!userId) return;
if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return; if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return;
if (withHash) return `#${colors[userId]}`; if (withHash) return `#${colors[userId]}`;
return colors[userId]; return colors[userId];

View file

@ -79,5 +79,6 @@ export async function installExt(id: string) {
.catch(err => console.error(`Failed to extract extension ${id}`, err)); .catch(err => console.error(`Failed to extract extension ${id}`, err));
} }
session.defaultSession.loadExtension(extDir); // @ts-expect-error Electron 36 Deprecates session.defaultSession.loadExtension()
session.defaultSession.extensions ? session.defaultSession.extensions.loadExtension(extDir) : session.defaultSession.loadExtension(extDir);
} }

View file

@ -109,13 +109,18 @@ export default definePlugin({
const id = context?.user?.id; const id = context?.user?.id;
const colorString = context?.colorString; const colorString = context?.colorString;
const color = calculateNameColorForUser(id); const color = calculateNameColorForUser(id);
const customColor = id && Settings.plugins.CustomUserColors.enabled ? getCustomColorString(id, true) : null;
if ( if (Settings.plugins.CustomUserColors.enabled) {
(settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) || const customColor = getCustomColorString(id, true);
(settings.store.applyColorOnlyToUsersWithoutColor && colorString) if (customColor) return customColor;
) return customColor ?? colorString; }
return customColor ?? color; if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) {
return colorString;
}
return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
? color
: colorString;
} }
}); });

View file

@ -165,8 +165,10 @@ export default definePlugin({
getColorString(userId: string, channelOrGuildId: string) { getColorString(userId: string, channelOrGuildId: string) {
try { try {
if (Settings.plugins.CustomUserColors.enabled) if (Settings.plugins.CustomUserColors.enabled) {
return getCustomColorString(userId, true); const customColor = getCustomColorString(userId, true);
if (customColor) return customColor;
}
const guildId = ChannelStore.getChannel(channelOrGuildId)?.guild_id ?? GuildStore.getGuild(channelOrGuildId)?.id; const guildId = ChannelStore.getChannel(channelOrGuildId)?.guild_id ?? GuildStore.getGuild(channelOrGuildId)?.id;
if (guildId == null) return null; if (guildId == null) return null;

View file

@ -60,10 +60,15 @@ interface Props {
guildId: string; guildId: string;
} }
function typingUserColor(guildId: string, userId: string) { function typingUserColor(guildId: string, userId: string): string | undefined {
if (!settings.store.showRoleColors) return; if (!settings.store.showRoleColors) return;
const customColor = Settings.plugins.CustomUserColors.enabled ? getCustomColorString(userId, true) : null;
return customColor ?? GuildMemberStore.getMember(guildId, userId)?.colorString; if (Settings.plugins.CustomUserColors.enabled) {
const customColor = getCustomColorString(userId, true);
if (customColor) return customColor;
}
return GuildMemberStore.getMember(guildId, userId)?.colorString;
} }
const TypingUser = ErrorBoundary.wrap(function ({ user, guildId }: Props) { const TypingUser = ErrorBoundary.wrap(function ({ user, guildId }: Props) {