Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Vendicated/Vencord into disc…
Browse files Browse the repository at this point in the history
…ord-types
  • Loading branch information
ryan-0324 committed Sep 22, 2024
2 parents f2e13f2 + db5fe2a commit c894a2b
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Margins } from "@utils/margins";
import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { OptionType, type PluginOptionNumber } from "@utils/types";
import { Forms, TextInput, useEffect, useState } from "@webpack/common";

Expand Down Expand Up @@ -54,7 +56,8 @@ export function SettingNumericComponent({ option, pluginSettings, definedSetting

return (
<Forms.FormSection>
<Forms.FormTitle>{option.description}</Forms.FormTitle>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
<Forms.FormText className={Margins.bottom20} type="description">{option.description}</Forms.FormText>
<TextInput
type="number"
pattern="-?[0-9]+"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Margins } from "@utils/margins";
import { wordsFromCamel, wordsToTitle } from "@utils/text";
import type { PluginOptionSelect } from "@utils/types";
import { Forms, Select, useEffect, useState } from "@webpack/common";

Expand Down Expand Up @@ -45,7 +47,8 @@ export function SettingSelectComponent({ option, pluginSettings, definedSettings

return (
<Forms.FormSection>
<Forms.FormTitle>{option.description}</Forms.FormTitle>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
<Forms.FormText className={Margins.bottom16} type="description">{option.description}</Forms.FormText>
<Select
isDisabled={option.disabled?.call(definedSettings) ?? false}
options={option.options}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Margins } from "@utils/margins";
import { wordsFromCamel, wordsToTitle } from "@utils/text";
import type { PluginOptionSlider } from "@utils/types";
import { Forms, Slider, useEffect, useState } from "@webpack/common";

Expand Down Expand Up @@ -52,7 +54,8 @@ export function SettingSliderComponent({ option, pluginSettings, definedSettings

return (
<Forms.FormSection>
<Forms.FormTitle>{option.description}</Forms.FormTitle>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
<Forms.FormText className={Margins.bottom20} type="description">{option.description}</Forms.FormText>
<Slider
disabled={option.disabled?.call(definedSettings) ?? false}
markers={option.markers}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { Margins } from "@utils/margins";
import { wordsFromCamel, wordsToTitle } from "@utils/text";
import type { PluginOptionString } from "@utils/types";
import { Forms, TextInput, useEffect, useState } from "@webpack/common";

Expand All @@ -41,7 +43,8 @@ export function SettingTextComponent({ option, pluginSettings, definedSettings,

return (
<Forms.FormSection>
<Forms.FormTitle>{option.description}</Forms.FormTitle>
<Forms.FormTitle>{wordsToTitle(wordsFromCamel(id))}</Forms.FormTitle>
<Forms.FormText className={Margins.bottom20} type="description">{option.description}</Forms.FormText>
<TextInput
type="text"
value={state}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/consoleJanitor/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ConsoleJanitor

Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and noisy/spammy logging messages.
Disables annoying console messages/errors. This plugin mainly removes errors/warnings that happen all the time and Discord logger messages.

Some of the disabled messages include the "notosans-400-normalitalic" error and MessageActionCreators, Routing/Utils loggers.
One of the disabled messages is the "Window state not initialized" warning, for example.
62 changes: 31 additions & 31 deletions src/plugins/consoleJanitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import definePlugin, { OptionType, StartAt } from "@utils/types";

const Noop = () => { };
const NoopLogger = {
Expand All @@ -22,10 +22,12 @@ const NoopLogger = {
fileOnly: Noop
};

const logAllow = new Set();

const settings = definePluginSettings({
disableNoisyLoggers: {
disableLoggers: {
type: OptionType.BOOLEAN,
description: "Disable noisy loggers like the MessageActionCreators",
description: "Disables Discords loggers",
default: false,
restartNeeded: true
},
Expand All @@ -34,16 +36,35 @@ const settings = definePluginSettings({
description: "Disable the Spotify logger, which leaks account information and access token",
default: true,
restartNeeded: true
},
whitelistedLoggers: {
type: OptionType.STRING,
description: "Semi colon separated list of loggers to allow even if others are hidden",
default: "GatewaySocket; Routing/Utils",
onChange(newVal: string) {
logAllow.clear();
newVal.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
}
}
});

export default definePlugin({
name: "ConsoleJanitor",
description: "Disables annoying console messages/errors",
authors: [Devs.Nuckyz],
authors: [Devs.Nuckyz, Devs.sadan],
settings,

startAt: StartAt.Init,
start() {
logAllow.clear();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
this.settings.store.whitelistedLoggers?.split(";").map(x => x.trim()).forEach(logAllow.add.bind(logAllow));
},

NoopLogger: () => NoopLogger,
shouldLog(logger: string) {
return logAllow.has(logger);
},

patches: [
{
Expand Down Expand Up @@ -103,34 +124,13 @@ export default definePlugin({
replace: ""
}
},
...[
'("MessageActionCreators")', '("ChannelMessages")',
'("Routing/Utils")', '("RTCControlSocket")',
'("ConnectionEventFramerateReducer")', '("RTCLatencyTestManager")',
'("OverlayBridgeStore")', '("RPCServer:WSS")', '("RPCServer:IPC")'
].map(logger => ({
find: logger,
predicate: () => settings.store.disableNoisyLoggers,
all: true,
replacement: {
match: new RegExp(String.raw`new \i\.\i${logger.replaceAll(/[()]/g, "\\$&")}`),
replace: `$self.NoopLogger${logger}`
}
})),
// Patches discords generic logger function
{
find: '"Experimental codecs: "',
predicate: () => settings.store.disableNoisyLoggers,
find: "Σ:",
predicate: () => settings.store.disableLoggers,
replacement: {
match: /new \i\.\i\("Connection\("\.concat\(\i,"\)"\)\)/,
replace: "$self.NoopLogger()"
}
},
{
find: '"_handleLocalVideoDisabled: ',
predicate: () => settings.store.disableNoisyLoggers,
replacement: {
match: /new \i\.\i\("RTCConnection\("\.concat.+?\)\)(?=,)/,
replace: "$self.NoopLogger()"
match: /(?<=&&)(?=console)/,
replace: "$self.shouldLog(arguments[0])&&"
}
},
{
Expand All @@ -141,5 +141,5 @@ export default definePlugin({
replace: "$self.NoopLogger()"
}
}
]
],
});
1 change: 1 addition & 0 deletions src/plugins/copyFileContents/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vc-cfc-button {
color: var(--interactive-normal);
cursor: pointer;
padding-left: 4px;
}

.vc-cfc-button:hover {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/crashHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default definePlugin({
}
if (settings.store.attemptToNavigateToHome) {
try {
RouterUtils.transitionTo("/channels/@me");
RouterUtils.transitionToGuild("@me");
} catch (err) {
CrashHandlerLogger.debug("Failed to navigate to home", err);
}
Expand Down
18 changes: 7 additions & 11 deletions src/plugins/keepCurrentChannel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import * as DataStore from "@api/DataStore";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { ChannelStore, RouterUtils, SelectedChannelStore, SelectedGuildStore } from "@webpack/common";
import { ChannelRouter, SelectedChannelStore, SelectedGuildStore } from "@webpack/common";

export interface LogoutAction {
type: "LOGOUT";
Expand All @@ -40,11 +40,6 @@ interface PreviousChannel {
let isSwitchingAccount = false;
let previousCache: PreviousChannel | undefined;

function attemptToNavigateToChannel(guildId: string | null, channelId: string) {
if (ChannelStore.hasChannel(channelId))
RouterUtils.transitionTo(`/channels/${guildId ?? "@me"}/${channelId}`);
}

export default definePlugin({
name: "KeepCurrentChannel",
description: "Attempt to navigate to the channel you were in before switching accounts or loading Discord.",
Expand All @@ -56,10 +51,11 @@ export default definePlugin({
},

CONNECTION_OPEN() {
if (isSwitchingAccount) {
isSwitchingAccount = false;
if (previousCache?.channelId)
attemptToNavigateToChannel(previousCache.guildId, previousCache.channelId);
if (!isSwitchingAccount) return;
isSwitchingAccount = false;

if (previousCache?.channelId) {
ChannelRouter.transitionToChannel(previousCache.channelId);
}
},

Expand All @@ -84,7 +80,7 @@ export default definePlugin({

await DataStore.set("KeepCurrentChannel_previousData", previousCache);
} else if (previousCache.channelId) {
attemptToNavigateToChannel(previousCache.guildId, previousCache.channelId);
ChannelRouter.transitionToChannel(previousCache.channelId);
}
}
});
14 changes: 14 additions & 0 deletions src/plugins/openInApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ export default definePlugin({
replace: "true$1VencordNative.native.openExternal"
}
},
{
find: "no artist ids in metadata",
predicate: () => !IS_DISCORD_DESKTOP && pluginSettings.store.spotify,
replacement: [
{
match: /\i\.\i\.isProtocolRegistered\(\)/g,
replace: "true"
},
{
match: /!\(0,\i\.isDesktop\)\(\)/,
replace: "false"
}
]
},
{
find: ".CONNECTED_ACCOUNT_VIEWED,",
replacement: {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/replaceGoogleSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Flex, Menu } from "@webpack/common";

const DefaultEngines = {
Google: "https://www.google.com/search?q=",
DuckDuckGo: "https://duckduckgo.com/",
DuckDuckGo: "https://duckduckgo.com/?q=",
Brave: "https://search.brave.com/search?q=",
Bing: "https://www.bing.com/search?q=",
Yahoo: "https://search.yahoo.com/search?p=",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/reviewDB/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default definePlugin({
}
},
{
find: ".PANEL,interactionType:",
find: 'location:"UserProfilePanel"',
replacement: {
match: /{profileType:\i\.\i\.PANEL,children:\[/,
replace: "$&$self.BiteSizeReviewsButton({user:arguments[0].user}),"
Expand Down
40 changes: 36 additions & 4 deletions src/plugins/roleColorEverywhere/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { makeRange } from "@components/PluginSettings/components";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack";
import { ChannelStore, GuildMemberStore, GuildStore } from "@webpack/common";

const useMessageNickAndColor = findByCodeLazy('"Result cannot be null because the message is not null"');

const settings = definePluginSettings({
chatMentions: {
type: OptionType.BOOLEAN,
Expand All @@ -46,13 +50,21 @@ const settings = definePluginSettings({
default: true,
description: "Show role colors in the reactors list",
restartNeeded: true
}
},
messageSaturation: {
type: OptionType.SLIDER,
description: "Intensity of message coloring. 0 to disable.",
markers: makeRange(0, 100, 10),
default: 30,
// This is called only once at startup, but late enough that the store is initialized.
get restartNeeded(): boolean { return settings.store.messageSaturation === 0; }
},
});


export default definePlugin({
name: "RoleColorEverywhere",
authors: [Devs.KingFish, Devs.lewisakura, Devs.AutumnVN],
authors: [Devs.KingFish, Devs.lewisakura, Devs.AutumnVN, Devs.Kyuuhachi],
description: "Adds the top role color anywhere possible",
patches: [
// Chat Mentions
Expand Down Expand Up @@ -114,7 +126,15 @@ export default definePlugin({
replace: "$&,style:{color:$self.getColor($2?.id,$1)}"
},
predicate: () => settings.store.reactorsList,
}
},
{
find: '.Messages.MESSAGE_EDITED,")"',
replacement: {
match: /(?<=isUnsupported\]:(\i)\.isUnsupported\}\),)(?=children:\[)/,
replace: "style:{color:$self.useMessageColor($1)},"
},
predicate: () => settings.store.messageSaturation !== 0,
},
],
settings,

Expand Down Expand Up @@ -147,5 +167,17 @@ export default definePlugin({
color: this.getColor(userId, { guildId })
}
};
}
},

useMessageColor(message: any) {
try {
const { messageSaturation } = settings.use(["messageSaturation"]);
const author = useMessageNickAndColor(message);
if (author.colorString !== undefined && messageSaturation !== 0)
return `color-mix(in oklab, ${author.colorString} ${messageSaturation}%, var(--text-normal))`;
} catch (e) {
console.error("[RCE] failed to get message color", e);
}
return undefined;
},
});
Loading

0 comments on commit c894a2b

Please sign in to comment.