Compare commits

..

44 Commits

Author SHA1 Message Date
V
bea7a1711e Bump to v1.3.4 2023-07-08 03:40:31 +02:00
Lewis Crichton
e52ae62441 feat(cloud): support multiple user accounts (#1382)
Co-authored-by: V <vendicated@riseup.net>
2023-07-08 03:36:59 +02:00
V
7cd1d4c60f translate: Add context menu item; fix MLE compatibility 2023-07-08 03:30:16 +02:00
V
2a318e390e QuickCss: Fix wrongly applying quickcss when editing while disabled 2023-07-08 03:13:32 +02:00
V
7c7723bfb1 Plugin Settings: Use Switches for booleans 2023-07-08 03:04:58 +02:00
dolfies
2db0e71e5b fix(RelationshipNotifier): Ignore user-actioned friend requests (#1390) 2023-07-08 02:37:32 +02:00
Ryan Cao
cde8074f44 feat(ClearURLs): add Threads share link tracking param (#1384) 2023-07-08 02:34:16 +02:00
Nuckyz
8b1630bc99 Fix ShowAllMessageButtons (#1392)
Co-authored-by: V <vendicated@riseup.net>
2023-07-08 02:33:37 +02:00
V
bf34b2ae43 Bump to v1.3.3 2023-07-06 01:26:31 +02:00
V
cb5f23d9b5 ProxyLazy: Limit attempts 2023-07-06 00:54:49 +02:00
V
cd2cbfa0ef ShowHiddenChannels: Fix crashing on canary 2023-07-06 00:43:43 +02:00
Ryan Cao
232e340fab fix: send notification when settings are manually synced (#1378)
Co-authored-by: V <vendicated@riseup.net>
2023-07-04 15:59:42 +00:00
V
8027daa2b0 Fix types 2023-07-04 17:58:32 +02:00
Ryan Cao
0f7b9f588e perf(cloud sync): minify synced settings (#1377) 2023-07-04 17:57:28 +02:00
V
93482ac2a5 SpotifyControls: improve open in app capabilities & styles 2023-07-04 17:53:17 +02:00
V
994c3b3c92 OpenInApp: Fix bot buttons 2023-07-04 17:52:52 +02:00
V
c696c186e8 WebKeybinds: Fix scope 2023-07-02 01:23:51 +02:00
V
30d5e2108f Bump to 1.3.2 2023-07-02 01:22:53 +02:00
V
1eabd1b701 WebKeybinds: Fix broken zoom on vesktop 2023-07-02 01:22:37 +02:00
V
1cbf2b43e1 Fix Badges 2023-07-02 01:17:02 +02:00
V
4c197d5d51 New Plugin: WebKeyBinds 2023-07-02 01:08:06 +02:00
V
f89027f46a Bump to 1.3.1 2023-06-30 17:08:57 +02:00
V
07a0ebb1d2 PronounDB: Fix crash when having pronouns in profile disabled 2023-06-30 17:08:43 +02:00
V
f09b44b0d5 VcNarrator: Ignore stage channels 2023-06-30 15:55:20 +02:00
V
b607eebcb7 ImageZoom: Add square lens option 2023-06-30 15:50:56 +02:00
V
0936ca2985 ValidUser: Fix mentions with ! (<@!...>) 2023-06-30 15:43:21 +02:00
V
13bde79ec8 PronounDB: Fix profile patch, add pronoun source to tooltip 2023-06-30 15:39:33 +02:00
V
b592defaaf OpenInApp: Add Epic Games; properly respect settings 2023-06-30 15:16:42 +02:00
V
73354973a3 OpenInApp: Support steam; integrate with SpotifyControls & ShowConnections 2023-06-29 16:15:07 +02:00
V
e12c0e546c PronounDB: Fix crash 2023-06-29 14:28:16 +02:00
V
088a8bd1b6 OpenInApp: Support profile activity on web & profile connection 2023-06-29 05:02:13 +02:00
V
51adb26d01 New plugin: OpenInApp - Open spotify urls in spotify app 2023-06-29 04:33:35 +02:00
Nuckyz
cb980a1cad Fix broken SHC patches (#1360) 2023-06-28 03:45:16 +00:00
V
69b10c1f07 Bump to 1.3.0 2023-06-27 23:12:56 +02:00
alexia
8e9ba7c7ee PronounDB: fix caching not respecting user preference (#1344) 2023-06-27 22:46:52 +02:00
Commandtechno
12e3c9234d ViewIcons: Fix animated server pfps & profile edit button (#1350)
fixes #1236
2023-06-27 22:41:52 +02:00
Sammy
1d8dcef394 InvisibleChat: fix indicator & crashes (#1356) 2023-06-27 22:41:33 +02:00
Syncx
4fe2845234 ImageZoom: add nearest neighbour (#1341) 2023-06-27 22:41:19 +02:00
V
5e71ed286e PronounDB: Strip newlines from Discord Pronouns (Discord is stupid) 2023-06-25 19:08:18 +02:00
V
5edbd2391d Fix build 2023-06-25 18:33:44 +02:00
ActuallyTheSun
8472c3823e feat(🗿): ignore blocked users (#1327)
Co-authored-by: V <vendicated@riseup.net>
2023-06-25 18:31:39 +02:00
V
2103e52115 WebContextMenus: Support all text areas 2023-06-25 18:22:36 +02:00
Nuckyz
afbfb641e8 Fix IgnoreActivities broken patch (#1337) 2023-06-25 09:57:18 +00:00
V
d7ac418e05 Fix some plugins displaying legacy discriminators (username#0000) 2023-06-23 18:09:43 +02:00
48 changed files with 659 additions and 192 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.2.9", "version": "1.3.4",
"description": "The cutest Discord client mod", "description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme", "homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": { "bugs": {

View File

@ -151,7 +151,6 @@ async function parseFile(fileName: string) {
case "required": case "required":
case "enabledByDefault": case "enabledByDefault":
data[key] = value.kind === SyntaxKind.TrueKeyword; data[key] = value.kind === SyntaxKind.TrueKeyword;
if (!data[key] && value.kind !== SyntaxKind.FalseKeyword) throw fail(`${key} is not a boolean literal`);
break; break;
} }
} }

View File

@ -58,4 +58,10 @@ export default {
getVersions: () => process.versions as Partial<NodeJS.ProcessVersions>, getVersions: () => process.versions as Partial<NodeJS.ProcessVersions>,
openExternal: (url: string) => invoke<void>(IpcEvents.OPEN_EXTERNAL, url) openExternal: (url: string) => invoke<void>(IpcEvents.OPEN_EXTERNAL, url)
}, },
pluginHelpers: {
OpenInApp: {
resolveRedirect: (url: string) => invoke<string>(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, url),
},
}
}; };

View File

@ -16,8 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { wordsFromCamel, wordsToTitle } from "@utils/text";
import { PluginOptionBoolean } from "@utils/types"; import { PluginOptionBoolean } from "@utils/types";
import { Forms, React, Select } from "@webpack/common"; import { Forms, React, Switch } from "@webpack/common";
import { ISettingElementProps } from "."; import { ISettingElementProps } from ".";
@ -31,11 +32,6 @@ export function SettingBooleanComponent({ option, pluginSettings, definedSetting
onError(error !== null); onError(error !== null);
}, [error]); }, [error]);
const options = [
{ label: "Enabled", value: true, default: def === true },
{ label: "Disabled", value: false, default: typeof def === "undefined" || def === false },
];
function handleChange(newValue: boolean): void { function handleChange(newValue: boolean): void {
const isValid = option.isValid?.call(definedSettings, newValue) ?? true; const isValid = option.isValid?.call(definedSettings, newValue) ?? true;
if (typeof isValid === "string") setError(isValid); if (typeof isValid === "string") setError(isValid);
@ -49,18 +45,17 @@ export function SettingBooleanComponent({ option, pluginSettings, definedSetting
return ( return (
<Forms.FormSection> <Forms.FormSection>
<Forms.FormTitle>{option.description}</Forms.FormTitle> <Switch
<Select value={state}
isDisabled={option.disabled?.call(definedSettings) ?? false} onChange={handleChange}
options={options} note={option.description}
placeholder={option.placeholder ?? "Select an option"} disabled={option.disabled?.call(definedSettings) ?? false}
maxVisibleItems={5}
closeOnSelect={true}
select={handleChange}
isSelected={v => v === state}
serialize={v => String(v)}
{...option.componentProps} {...option.componentProps}
/> hideBorder
style={{ marginBottom: "0.5em" }}
>
{wordsToTitle(wordsFromCamel(id))}
</Switch>
{error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>} {error && <Forms.FormText style={{ color: "var(--text-danger)" }}>{error}</Forms.FormText>}
</Forms.FormSection> </Forms.FormSection>
); );

View File

@ -86,7 +86,7 @@ function SettingsSyncSection() {
<Button <Button
size={Button.Sizes.SMALL} size={Button.Sizes.SMALL}
disabled={!sectionEnabled} disabled={!sectionEnabled}
onClick={() => putCloudSettings()} onClick={() => putCloudSettings(true)}
>Sync to Cloud</Button> >Sync to Cloud</Button>
<Tooltip text="This will overwrite your local settings with the ones on the cloud. Use wisely!"> <Tooltip text="This will overwrite your local settings with the ones on the cloud. Use wisely!">
{({ onMouseLeave, onMouseEnter }) => ( {({ onMouseLeave, onMouseEnter }) => (

View File

@ -17,6 +17,7 @@
*/ */
import "./updater"; import "./updater";
import "./ipcPlugins";
import { debounce } from "@utils/debounce"; import { debounce } from "@utils/debounce";
import { IpcEvents } from "@utils/IpcEvents"; import { IpcEvents } from "@utils/IpcEvents";

46
src/main/ipcPlugins.ts Normal file
View File

@ -0,0 +1,46 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { IpcEvents } from "@utils/IpcEvents";
import { ipcMain } from "electron";
import { request } from "https";
// #region OpenInApp
// These links don't support CORS, so this has to be native
const validRedirectUrls = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
function getRedirect(url: string) {
return new Promise<string>((resolve, reject) => {
const req = request(new URL(url), { method: "HEAD" }, res => {
resolve(
res.headers.location
? getRedirect(res.headers.location)
: url
);
});
req.on("error", reject);
req.end();
});
}
ipcMain.handle(IpcEvents.OPEN_IN_APP__RESOLVE_REDIRECT, async (_, url: string) => {
if (!validRedirectUrls.test(url)) return url;
return getRedirect(url);
});
// #endregion

View File

@ -31,7 +31,8 @@ export const ALLOWED_PROTOCOLS = [
"https:", "https:",
"http:", "http:",
"steam:", "steam:",
"spotify:" "spotify:",
"com.epicgames.launcher:",
]; ];
export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla"); export const IS_VANILLA = /* @__PURE__ */ process.argv.includes("--vanilla");

View File

@ -80,8 +80,8 @@ export default definePlugin({
find: "Messages.PROFILE_USER_BADGES,role:", find: "Messages.PROFILE_USER_BADGES,role:",
replacement: [ replacement: [
{ {
match: /(?<=(\i)\.isTryItOutFlow,)(.{0,300})null==\i\?void 0:(\i)\.getBadges\(\)/, match: /&&(\i)\.push\(\{id:"premium".+?\}\);/,
replace: (_, props, restCode, badgesMod) => `vencordProps=${props},${restCode}Vencord.Api.Badges._getBadges(vencordProps).concat(${badgesMod}?.getBadges()??[])`, replace: "$&$1.unshift(...Vencord.Api.Badges._getBadges(arguments[0]));",
}, },
{ {
// alt: "", aria-hidden: false, src: originalSrc // alt: "", aria-hidden: false, src: originalSrc

View File

@ -135,4 +135,5 @@ export const defaultRules = [
"utm_campaign", "utm_campaign",
"utm_term", "utm_term",
"si@open.spotify.com", "si@open.spotify.com",
"igshid",
]; ];

View File

@ -45,7 +45,7 @@ function ToggleIconOff() {
className={RegisteredGamesClasses.overlayToggleIconOff} className={RegisteredGamesClasses.overlayToggleIconOff}
height="24" height="24"
width="24" width="24"
viewBox="0 0 32 26" viewBox="0 2.2 32 26"
aria-hidden={true} aria-hidden={true}
role="img" role="img"
> >
@ -77,7 +77,7 @@ function ToggleIconOn({ forceWhite }: { forceWhite?: boolean; }) {
className={RegisteredGamesClasses.overlayToggleIconOn} className={RegisteredGamesClasses.overlayToggleIconOn}
height="24" height="24"
width="24" width="24"
viewBox="0 0 32 26" viewBox="0 2.2 32 26"
> >
<path <path
className={forceWhite ? "" : RegisteredGamesClasses.fill} className={forceWhite ? "" : RegisteredGamesClasses.fill}
@ -119,7 +119,7 @@ function ToggleActivityComponentWithBackground({ activity }: { activity: Ignored
return ( return (
<div <div
className={`${TryItOutClasses.tryItOutBadge} ${BaseShapeRoundClasses.baseShapeRound}`} className={`${TryItOutClasses.tryItOutBadge} ${BaseShapeRoundClasses.baseShapeRound}`}
style={{ padding: "0px 2px" }} style={{ padding: "0px 2px", height: 28 }}
> >
<ToggleActivityComponent activity={activity} forceWhite={true} /> <ToggleActivityComponent activity={activity} forceWhite={true} />
</div> </div>
@ -157,10 +157,16 @@ export default definePlugin({
}, },
{ {
find: ".overlayBadge", find: ".overlayBadge",
replacement: { replacement: [
match: /(?<=\(\)\.badgeContainer.+?(\i)\.name}\):null)/, {
replace: (_, props) => `,$self.renderToggleActivityButton(${props})` match: /(?<=\(\)\.badgeContainer,children:).{0,50}?name:(\i)\.name.+?null/,
replace: (m, props) => `[${m},$self.renderToggleActivityButton(${props})]`
},
{
match: /(?<=\(\)\.badgeContainer,children:).{0,50}?name:(\i\.application)\.name.+?null/,
replace: (m, props) => `${m},$self.renderToggleActivityButton(${props})`
} }
]
}, },
{ {
find: '.displayName="LocalActivityStore"', find: '.displayName="LocalActivityStore"',

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { classNameFactory } from "@api/Styles";
import { FluxDispatcher, React, useRef, useState } from "@webpack/common"; import { FluxDispatcher, React, useRef, useState } from "@webpack/common";
import { ELEMENT_ID } from "../constants"; import { ELEMENT_ID } from "../constants";
@ -33,6 +34,8 @@ export interface MagnifierProps {
instance: any; instance: any;
} }
const cl = classNameFactory("vc-imgzoom-");
export const Magnifier: React.FC<MagnifierProps> = ({ instance, size: initialSize, zoom: initalZoom }) => { export const Magnifier: React.FC<MagnifierProps> = ({ instance, size: initialSize, zoom: initalZoom }) => {
const [ready, setReady] = useState(false); const [ready, setReady] = useState(false);
@ -156,7 +159,7 @@ export const Magnifier: React.FC<MagnifierProps> = ({ instance, size: initialSiz
return ( return (
<div <div
className="vc-imgzoom-lens" className={cl("lens", { "nearest-neighbor": settings.store.nearestNeighbour, square: settings.store.square })}
style={{ style={{
opacity, opacity,
width: size.current + "px", width: size.current + "px",

View File

@ -23,7 +23,7 @@ import { makeRange } from "@components/PluginSettings/components";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { debounce } from "@utils/debounce"; import { debounce } from "@utils/debounce";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { Menu, React, ReactDOM } from "@webpack/common"; import { ContextMenu, Menu, React, ReactDOM } from "@webpack/common";
import type { Root } from "react-dom/client"; import type { Root } from "react-dom/client";
import { Magnifier, MagnifierProps } from "./components/Magnifier"; import { Magnifier, MagnifierProps } from "./components/Magnifier";
@ -50,6 +50,18 @@ export const settings = definePluginSettings({
default: true, default: true,
}, },
nearestNeighbour: {
type: OptionType.BOOLEAN,
description: "Use Nearest Neighbour Interpolation when scaling images",
default: false,
},
square: {
type: OptionType.BOOLEAN,
description: "Make the lens square",
default: false,
},
zoom: { zoom: {
description: "Zoom of the lens", description: "Zoom of the lens",
type: OptionType.SLIDER, type: OptionType.SLIDER,
@ -78,9 +90,17 @@ export const settings = definePluginSettings({
const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => { const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
children.push( children.push(
<Menu.MenuGroup id="image-zoom"> <Menu.MenuGroup id="image-zoom">
{/* thanks SpotifyControls */} <Menu.MenuCheckboxItem
id="vc-square"
label="Square Lens"
checked={settings.store.square}
action={() => {
settings.store.square = !settings.store.square;
ContextMenu.close();
}}
/>
<Menu.MenuControlItem <Menu.MenuControlItem
id="zoom" id="vc-zoom"
label="Zoom" label="Zoom"
control={(props, ref) => ( control={(props, ref) => (
<Menu.MenuSliderControl <Menu.MenuSliderControl
@ -94,7 +114,7 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
)} )}
/> />
<Menu.MenuControlItem <Menu.MenuControlItem
id="size" id="vc-size"
label="Lens Size" label="Lens Size"
control={(props, ref) => ( control={(props, ref) => (
<Menu.MenuSliderControl <Menu.MenuSliderControl
@ -108,7 +128,7 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = children => () => {
)} )}
/> />
<Menu.MenuControlItem <Menu.MenuControlItem
id="zoom-speed" id="vc-zoom-speed"
label="Zoom Speed" label="Zoom Speed"
control={(props, ref) => ( control={(props, ref) => (
<Menu.MenuSliderControl <Menu.MenuSliderControl

View File

@ -11,6 +11,14 @@
pointer-events: none; pointer-events: none;
} }
.vc-imgzoom-square {
border-radius: 0;
}
.vc-imgzoom-nearest-neighbor > img {
image-rendering: pixelated; /* https://googlechrome.github.io/samples/image-rendering-pixelated/index.html */
}
/* make the carousel take up less space so we can click the backdrop and exit out of it */ /* make the carousel take up less space so we can click the backdrop and exit out of it */
[class|="carouselModal"] { [class|="carouselModal"] {
height: fit-content; height: fit-content;

View File

@ -132,7 +132,7 @@ export default definePlugin({
find: ".Messages.MESSAGE_EDITED,", find: ".Messages.MESSAGE_EDITED,",
replacement: { replacement: {
match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm, match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm,
replace: "try {$1 && $self.INV_REGEX.test($1.content[0]) ? $1.content.push($self.indicator()) : null } catch {};$&" replace: "try {$1 && $self.INV_REGEX.test($1.message.content) ? $1.content.push($self.indicator()) : null } catch {};$&"
} }
}, },
{ {
@ -200,8 +200,11 @@ export default definePlugin({
}, },
}); });
if (urlCheck?.length) if (urlCheck?.length) {
message.embeds.push(await this.getEmbed(new URL(urlCheck[0]))); const embed = await this.getEmbed(new URL(urlCheck[0]));
if (embed)
message.embeds.push(embed);
}
this.updateMessage(message); this.updateMessage(message);
}, },

View File

@ -21,7 +21,7 @@ import { makeRange } from "@components/PluginSettings/components/SettingSliderCo
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { sleep } from "@utils/misc"; import { sleep } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { SelectedChannelStore, UserStore } from "@webpack/common"; import { RelationshipStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message, ReactionEmoji } from "discord-types/general"; import { Message, ReactionEmoji } from "discord-types/general";
interface IMessageCreate { interface IMessageCreate {
@ -37,6 +37,7 @@ interface IReactionAdd {
optimistic: boolean; optimistic: boolean;
channelId: string; channelId: string;
messageId: string; messageId: string;
messageAuthorId: string;
userId: "195136840355807232"; userId: "195136840355807232";
emoji: ReactionEmoji; emoji: ReactionEmoji;
} }
@ -71,6 +72,11 @@ const settings = definePluginSettings({
description: "Ignore bots", description: "Ignore bots",
type: OptionType.BOOLEAN, type: OptionType.BOOLEAN,
default: true default: true
},
ignoreBlocked: {
description: "Ignore blocked users",
type: OptionType.BOOLEAN,
default: true
} }
}); });
@ -85,6 +91,7 @@ export default definePlugin({
if (optimistic || type !== "MESSAGE_CREATE") return; if (optimistic || type !== "MESSAGE_CREATE") return;
if (message.state === "SENDING") return; if (message.state === "SENDING") return;
if (settings.store.ignoreBots && message.author?.bot) return; if (settings.store.ignoreBots && message.author?.bot) return;
if (settings.store.ignoreBlocked && RelationshipStore.isBlocked(message.author?.id)) return;
if (!message.content) return; if (!message.content) return;
if (channelId !== SelectedChannelStore.getChannelId()) return; if (channelId !== SelectedChannelStore.getChannelId()) return;
@ -96,9 +103,10 @@ export default definePlugin({
} }
}, },
MESSAGE_REACTION_ADD({ optimistic, type, channelId, userId, emoji }: IReactionAdd) { MESSAGE_REACTION_ADD({ optimistic, type, channelId, userId, messageAuthorId, emoji }: IReactionAdd) {
if (optimistic || type !== "MESSAGE_REACTION_ADD") return; if (optimistic || type !== "MESSAGE_REACTION_ADD") return;
if (settings.store.ignoreBots && UserStore.getUser(userId)?.bot) return; if (settings.store.ignoreBots && UserStore.getUser(userId)?.bot) return;
if (settings.store.ignoreBlocked && RelationshipStore.isBlocked(messageAuthorId)) return;
if (channelId !== SelectedChannelStore.getChannelId()) return; if (channelId !== SelectedChannelStore.getChannelId()) return;
const name = emoji.name.toLowerCase(); const name = emoji.name.toLowerCase();

147
src/plugins/openInApp.ts Normal file
View File

@ -0,0 +1,147 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { showToast, Toasts } from "@webpack/common";
import type { MouseEvent } from "react";
const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/;
const SteamMatcher = /^https:\/\/(steamcommunity\.com|(?:help|store)\.steampowered\.com)\/.+$/;
const EpicMatcher = /^https:\/\/store\.epicgames\.com\/(.+)$/;
const settings = definePluginSettings({
spotify: {
type: OptionType.BOOLEAN,
description: "Open Spotify links in the Spotify app",
default: true,
},
steam: {
type: OptionType.BOOLEAN,
description: "Open Steam links in the Steam app",
default: true,
},
epic: {
type: OptionType.BOOLEAN,
description: "Open Epic Games links in the Epic Games Launcher",
default: true,
}
});
export default definePlugin({
name: "OpenInApp",
description: "Open Spotify, Steam and Epic Games URLs in their respective apps instead of your browser",
authors: [Devs.Ven],
settings,
patches: [
{
find: '"MaskedLinkStore"',
replacement: {
match: /return ((\i)\.apply\(this,arguments\))(?=\}function \i.{0,200}\.trusted)/,
replace: "return $self.handleLink(...arguments).then(handled => handled || $1)"
}
},
// Make Spotify profile activity links open in app on web
{
find: "WEB_OPEN(",
predicate: () => !IS_DISCORD_DESKTOP && settings.store.spotify,
replacement: {
match: /\i\.\i\.isProtocolRegistered\(\)(.{0,100})window.open/g,
replace: "true$1VencordNative.native.openExternal"
}
},
{
find: ".CONNECTED_ACCOUNT_VIEWED,",
replacement: {
match: /(?<=href:\i,onClick:function\(\)\{)(?=return \i=(\i)\.type,.{0,50}CONNECTED_ACCOUNT_VIEWED)/,
replace: "$self.handleAccountView(arguments[0],$1.type,$1.id);"
}
}
],
async handleLink(data: { href: string; }, event?: MouseEvent) {
if (!data) return false;
let url = data.href;
if (!IS_WEB && ShortUrlMatcher.test(url)) {
event?.preventDefault();
// CORS jumpscare
url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url);
}
spotify: {
if (!settings.store.spotify) break spotify;
const match = SpotifyMatcher.exec(url);
if (!match) break spotify;
const [, type, id] = match;
VencordNative.native.openExternal(`spotify:${type}:${id}`);
event?.preventDefault();
return true;
}
steam: {
if (!settings.store.steam) break steam;
if (!SteamMatcher.test(url)) break steam;
VencordNative.native.openExternal(`steam://openurl/${url}`);
event?.preventDefault();
// Steam does not focus itself so show a toast so it's slightly less confusing
showToast("Opened link in Steam", Toasts.Type.SUCCESS);
return true;
}
epic: {
if (!settings.store.epic) break epic;
const match = EpicMatcher.exec(url);
if (!match) break epic;
VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`);
event?.preventDefault();
return true;
}
// in case short url didn't end up being something we can handle
if (event?.defaultPrevented) {
window.open(url, "_blank");
return true;
}
return false;
},
handleAccountView(event: { preventDefault(): void; }, platformType: string, userId: string) {
if (platformType === "spotify" && settings.store.spotify) {
VencordNative.native.openExternal(`spotify:user:${userId}`);
event.preventDefault();
} else if (platformType === "steam" && settings.store.steam) {
VencordNative.native.openExternal(`steam://openurl/https://steamcommunity.com/profiles/${userId}`);
showToast("Opened link in Steam", Toasts.Type.SUCCESS);
event.preventDefault();
}
}
});

View File

@ -19,6 +19,7 @@
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { InfoIcon, OwnerCrownIcon } from "@components/Icons"; import { InfoIcon, OwnerCrownIcon } from "@components/Icons";
import { getUniqueUsername } from "@utils/discord";
import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common"; import { ContextMenu, FluxDispatcher, GuildMemberStore, Menu, PermissionsBits, Text, Tooltip, useEffect, UserStore, useState, useStateFromStores } from "@webpack/common";
import type { Guild } from "discord-types/general"; import type { Guild } from "discord-types/general";
@ -136,7 +137,7 @@ function RolesAndUsersPermissionsComponent({ permissions, guild, modalProps, hea
permission.type === PermissionType.Role permission.type === PermissionType.Role
? role?.name || "Unknown Role" ? role?.name || "Unknown Role"
: permission.type === PermissionType.User : permission.type === PermissionType.User
? user?.tag || "Unknown User" ? (user && getUniqueUsername(user)) || "Unknown User"
: ( : (
<Flex style={{ gap: "0.2em", justifyItems: "center" }}> <Flex style={{ gap: "0.2em", justifyItems: "center" }}>
@owner @owner

View File

@ -52,7 +52,7 @@ export function CompactPronounsChatComponentWrapper({ message }: { message: Mess
} }
function PronounsChatComponent({ message }: { message: Message; }) { function PronounsChatComponent({ message }: { message: Message; }) {
const result = useFormattedPronouns(message.author.id); const [result] = useFormattedPronouns(message.author.id);
return result return result
? ( ? (
@ -64,7 +64,7 @@ function PronounsChatComponent({ message }: { message: Message; }) {
} }
export function CompactPronounsChatComponent({ message }: { message: Message; }) { export function CompactPronounsChatComponent({ message }: { message: Message; }) {
const result = useFormattedPronouns(message.author.id); const [result] = useFormattedPronouns(message.author.id);
return result return result
? ( ? (

View File

@ -26,6 +26,11 @@ import { CompactPronounsChatComponentWrapper, PronounsChatComponentWrapper } fro
import { useProfilePronouns } from "./pronoundbUtils"; import { useProfilePronouns } from "./pronoundbUtils";
import { settings } from "./settings"; import { settings } from "./settings";
const PRONOUN_TOOLTIP_PATCH = {
match: /text:(.{0,10}.Messages\.USER_PROFILE_PRONOUNS)(?=,)/,
replace: '$& + (typeof vcPronounSource !== "undefined" ? ` (${vcPronounSource})` : "")'
};
export default definePlugin({ export default definePlugin({
name: "PronounDB", name: "PronounDB",
authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven], authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven],
@ -50,18 +55,24 @@ export default definePlugin({
// Patch the profile popout username header to use our pronoun hook instead of Discord's pronouns // Patch the profile popout username header to use our pronoun hook instead of Discord's pronouns
{ {
find: ".userTagNoNickname", find: ".userTagNoNickname",
replacement: { replacement: [
match: /=(\i)\.pronouns/, {
replace: "=$self.useProfilePronouns($1.user.id,$1.pronouns)" match: /,(\i)=(\i)\.pronouns/,
} replace: ",[$1,vcPronounSource]=$self.useProfilePronouns($2.user.id)"
},
PRONOUN_TOOLTIP_PATCH
]
}, },
// Patch the profile modal username header to use our pronoun hook instead of Discord's pronouns // Patch the profile modal username header to use our pronoun hook instead of Discord's pronouns
{ {
find: ".USER_PROFILE_ACTIVITY", find: ".USER_PROFILE_ACTIVITY",
replacement: { replacement: [
match: /\).showPronouns/, {
replace: ").showPronouns||true;const vcPronounce=$self.useProfilePronouns(arguments[0].user.id,arguments[0].displayProfile?.pronouns);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce" match: /getGlobalName\(\i\);(?<=displayProfile.{0,200})/,
} replace: "$&const [vcPronounce,vcPronounSource]=$self.useProfilePronouns(arguments[0].user.id);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce;"
},
PRONOUN_TOOLTIP_PATCH
]
} }
], ],

View File

@ -29,6 +29,9 @@ import { PronounCode, PronounMapping, PronounsResponse } from "./types";
const UserProfileStore = findStoreLazy("UserProfileStore"); const UserProfileStore = findStoreLazy("UserProfileStore");
type PronounsWithSource = [string | null, string];
const EmptyPronouns: PronounsWithSource = [null, ""];
export const enum PronounsFormat { export const enum PronounsFormat {
Lowercase = "LOWERCASE", Lowercase = "LOWERCASE",
Capitalized = "CAPITALIZED" Capitalized = "CAPITALIZED"
@ -62,45 +65,48 @@ function getDiscordPronouns(id: string) {
); );
} }
export function useFormattedPronouns(id: string, discordPronouns: string = getDiscordPronouns(id)): string | null { export function useFormattedPronouns(id: string): PronounsWithSource {
const [result] = useAwaiter(() => fetchPronouns(id, discordPronouns), { // Discord is so stupid you can put tons of newlines in pronouns
fallbackValue: getCachedPronouns(id, discordPronouns), const discordPronouns = getDiscordPronouns(id)?.trim().replace(NewLineRe, " ");
const [result] = useAwaiter(() => fetchPronouns(id), {
fallbackValue: getCachedPronouns(id),
onError: e => console.error("Fetching pronouns failed: ", e) onError: e => console.error("Fetching pronouns failed: ", e)
}); });
if (result && result !== "unspecified") if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns)
return Object.hasOwn(PronounMapping, result) return [discordPronouns, "Discord"];
? formatPronouns(result) // PronounDB
: result; // Discord
return null; if (result && result !== "unspecified")
return [formatPronouns(result), "PronounDB"];
return [discordPronouns, "Discord"];
} }
export function useProfilePronouns(id: string, discordPronouns: string) { export function useProfilePronouns(id: string): PronounsWithSource {
const pronouns = useFormattedPronouns(id, discordPronouns); const pronouns = useFormattedPronouns(id);
if (!settings.store.showInProfile) return null; if (!settings.store.showInProfile) return EmptyPronouns;
if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return null; if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return EmptyPronouns;
return pronouns; return pronouns;
} }
// Gets the cached pronouns, if you're too impatient for a promise! const NewLineRe = /\n+/g;
export function getCachedPronouns(id: string, discordPronouns: string): string | null {
if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns)
return discordPronouns;
// Gets the cached pronouns, if you're too impatient for a promise!
export function getCachedPronouns(id: string): string | null {
const cached = cache[id]; const cached = cache[id];
if (cached && cached !== "unspecified") return cached; if (cached && cached !== "unspecified") return cached;
return discordPronouns || cached || null; return cached || null;
} }
// Fetches the pronouns for one id, returning a promise that resolves if it was cached, or once the request is completed // Fetches the pronouns for one id, returning a promise that resolves if it was cached, or once the request is completed
export function fetchPronouns(id: string, discordPronouns: string): Promise<string> { export function fetchPronouns(id: string): Promise<string> {
return new Promise(res => { return new Promise(res => {
const cached = getCachedPronouns(id, discordPronouns); const cached = getCachedPronouns(id);
if (cached) return res(cached); if (cached) return res(cached);
// If there is already a request added, then just add this callback to it // If there is already a request added, then just add this callback to it

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { getUniqueUsername, openUserProfile } from "@utils/discord";
import { UserUtils } from "@webpack/common"; import { UserUtils } from "@webpack/common";
import settings from "./settings"; import settings from "./settings";
@ -43,11 +44,19 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat
switch (type) { switch (type) {
case RelationshipType.FRIEND: case RelationshipType.FRIEND:
if (settings.store.friends) if (settings.store.friends)
notify(`${user.tag} removed you as a friend.`, user.getAvatarURL(undefined, undefined, false)); notify(
`${getUniqueUsername(user)} removed you as a friend.`,
user.getAvatarURL(undefined, undefined, false),
() => openUserProfile(user.id)
);
break; break;
case RelationshipType.FRIEND_REQUEST: case RelationshipType.INCOMING_REQUEST:
if (settings.store.friendRequestCancels) if (settings.store.friendRequestCancels)
notify(`A friend request from ${user.tag} has been removed.`, user.getAvatarURL(undefined, undefined, false)); notify(
`A friend request from ${getUniqueUsername(user)} has been removed.`,
user.getAvatarURL(undefined, undefined, false),
() => openUserProfile(user.id)
);
break; break;
} }
} }

View File

@ -58,5 +58,7 @@ export const enum ChannelType {
export const enum RelationshipType { export const enum RelationshipType {
FRIEND = 1, FRIEND = 1,
FRIEND_REQUEST = 3, BLOCKED = 2,
INCOMING_REQUEST = 3,
OUTGOING_REQUEST = 4,
} }

View File

@ -18,6 +18,7 @@
import { DataStore, Notices } from "@api/index"; import { DataStore, Notices } from "@api/index";
import { showNotification } from "@api/Notifications"; import { showNotification } from "@api/Notifications";
import { getUniqueUsername, openUserProfile } from "@utils/discord";
import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common";
import settings from "./settings"; import settings from "./settings";
@ -69,30 +70,42 @@ export async function syncAndRunChecks() {
const user = await UserUtils.fetchUser(id).catch(() => void 0); const user = await UserUtils.fetchUser(id).catch(() => void 0);
if (user) if (user)
notify(`You are no longer friends with ${user.tag}.`, user.getAvatarURL(undefined, undefined, false)); notify(
`You are no longer friends with ${getUniqueUsername(user)}.`,
user.getAvatarURL(undefined, undefined, false),
() => openUserProfile(user.id)
);
} }
} }
if (settings.store.friendRequestCancels && oldFriends?.requests?.length) { if (settings.store.friendRequestCancels && oldFriends?.requests?.length) {
for (const id of oldFriends.requests) { for (const id of oldFriends.requests) {
if (friends.requests.includes(id)) continue; if (
friends.requests.includes(id) ||
[RelationshipType.FRIEND, RelationshipType.BLOCKED, RelationshipType.OUTGOING_REQUEST].includes(RelationshipStore.getRelationshipType(id))
) continue;
const user = await UserUtils.fetchUser(id).catch(() => void 0); const user = await UserUtils.fetchUser(id).catch(() => void 0);
if (user) if (user)
notify(`Friend request from ${user.tag} has been revoked.`, user.getAvatarURL(undefined, undefined, false)); notify(
`Friend request from ${getUniqueUsername(user)} has been revoked.`,
user.getAvatarURL(undefined, undefined, false),
() => openUserProfile(user.id)
);
} }
} }
} }
} }
export function notify(text: string, icon?: string) { export function notify(text: string, icon?: string, onClick?: () => void) {
if (settings.store.notices) if (settings.store.notices)
Notices.showNotice(text, "OK", () => Notices.popNotice()); Notices.showNotice(text, "OK", () => Notices.popNotice());
showNotification({ showNotification({
title: "Relationship Notifier", title: "Relationship Notifier",
body: text, body: text,
icon icon,
onClick
}); });
} }
@ -154,7 +167,7 @@ export async function syncFriends() {
case RelationshipType.FRIEND: case RelationshipType.FRIEND:
friends.friends.push(id); friends.friends.push(id);
break; break;
case RelationshipType.FRIEND_REQUEST: case RelationshipType.INCOMING_REQUEST:
friends.requests.push(id); friends.requests.push(id);
break; break;
} }

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { openUserProfile } from "@utils/discord";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { LazyComponent } from "@utils/react"; import { LazyComponent } from "@utils/react";
import { filters, findBulk } from "@webpack"; import { filters, findBulk } from "@webpack";
@ -24,7 +25,7 @@ import { Alerts, moment, Timestamp, UserStore } from "@webpack/common";
import { Review, ReviewType } from "../entities"; import { Review, ReviewType } from "../entities";
import { deleteReview, reportReview } from "../reviewDbApi"; import { deleteReview, reportReview } from "../reviewDbApi";
import { settings } from "../settings"; import { settings } from "../settings";
import { canDeleteReview, cl, openUserProfileModal, showToast } from "../utils"; import { canDeleteReview, cl, showToast } from "../utils";
import { DeleteButton, ReportButton } from "./MessageButton"; import { DeleteButton, ReportButton } from "./MessageButton";
import ReviewBadge from "./ReviewBadge"; import ReviewBadge from "./ReviewBadge";
@ -49,7 +50,7 @@ export default LazyComponent(() => {
return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) { return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) {
function openModal() { function openModal() {
openUserProfileModal(review.sender.discordID); openUserProfile(review.sender.discordID);
} }
function delReview() { function delReview() {

View File

@ -20,24 +20,13 @@ import { classNameFactory } from "@api/Styles";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { openModal } from "@utils/modal"; import { openModal } from "@utils/modal";
import { findByProps } from "@webpack"; import { findByProps } from "@webpack";
import { FluxDispatcher, React, SelectedChannelStore, Toasts, UserUtils } from "@webpack/common"; import { React, Toasts } from "@webpack/common";
import { Review, UserType } from "./entities"; import { Review, UserType } from "./entities";
import { settings } from "./settings"; import { settings } from "./settings";
export const cl = classNameFactory("vc-rdb-"); export const cl = classNameFactory("vc-rdb-");
export async function openUserProfileModal(userId: string) {
await UserUtils.fetchUser(userId);
await FluxDispatcher.dispatch({
type: "USER_PROFILE_MODAL_OPEN",
userId,
channelId: SelectedChannelStore.getChannelId(),
analyticsLocation: "Explosive Hotel"
});
}
export function authorize(callback?: any) { export function authorize(callback?: any) {
const { OAuth2AuthorizeModal } = findByProps("OAuth2AuthorizeModal"); const { OAuth2AuthorizeModal } = findByProps("OAuth2AuthorizeModal");

View File

@ -28,8 +28,8 @@ export default definePlugin({
{ {
find: ".Messages.MESSAGE_UTILITIES_A11Y_LABEL", find: ".Messages.MESSAGE_UTILITIES_A11Y_LABEL",
replacement: { replacement: {
// isExpanded: V, (?<=,V = shiftKeyDown && !H...;) // isExpanded: V, (?<=,V = shiftKeyDown && !H...,|;)
match: /isExpanded:(\i),(?<=,\1=\i&&(!.+);.+?)/, match: /isExpanded:(\i),(?<=,\1=\i&&(?=(!.+?)[,;]).+?)/,
replace: "isExpanded:$2," replace: "isExpanded:$2,"
} }
} }

View File

@ -147,6 +147,13 @@ function CompactConnectionComponent({ connection, theme }: { connection: Connect
className="vc-user-connection" className="vc-user-connection"
href={url} href={url}
target="_blank" target="_blank"
onClick={e => {
if (Vencord.Plugins.isPluginEnabled("OpenInApp")) {
const OpenInApp = Vencord.Plugins.plugins.OpenInApp as any as typeof import("../openInApp").default;
// handleLink will .preventDefault() if applicable
OpenInApp.handleLink(e.currentTarget, e);
}
}}
> >
{img} {img}
</a> </a>

View File

@ -29,7 +29,7 @@ import type { Channel, Role } from "discord-types/general";
import HiddenChannelLockScreen, { setChannelBeginHeaderComponent } from "./components/HiddenChannelLockScreen"; import HiddenChannelLockScreen, { setChannelBeginHeaderComponent } from "./components/HiddenChannelLockScreen";
const ChannelListClasses = findByPropsLazy("channelName", "subtitle", "modeMuted", "iconContainer"); const ChannelListClasses = findByPropsLazy("channelEmoji", "unread", "icon");
export const VIEW_CHANNEL = 1n << 10n; export const VIEW_CHANNEL = 1n << 10n;
const CONNECT = 1n << 20n; const CONNECT = 1n << 20n;
@ -342,32 +342,27 @@ export default definePlugin({
] ]
}, },
{ {
find: "Guild voice channel without guild id.", find: "useNotificationSettingsItem: channel cannot be undefined",
replacement: [ replacement: [
{ {
// Render our HiddenChannelLockScreen component instead of the main stage channel component // Render our HiddenChannelLockScreen component instead of the main stage channel component
match: /Guild voice channel without guild id.+?children:(?<=(\i)\.getGuildId\(\).+?)(?=.{0,20}?}\)}function)/, match: /"124px".+?children:(?<=var (\i)=\i\.channel.+?)(?=.{0,20}?}\)}function)/,
replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?$self.HiddenChannelLockScreen(${channel}):` replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?$self.HiddenChannelLockScreen(${channel}):`
}, },
{ {
// Disable useless components for the HiddenChannelLockScreen of stage channels // Disable useless components for the HiddenChannelLockScreen of stage channels
match: /render(?!Header).{0,30}?:(?<=(\i)\.getGuildId\(\).+?Guild voice channel without guild id.+?)/g, match: /render(?:BottomLeft|BottomCenter|BottomRight|ChatToasts):(?<=var (\i)=\i\.channel.+?)/g,
replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?null:` replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?null:`
}, },
// Prevent Discord from replacing our route if we aren't connected to the stage channel
{
match: /(?=!\i&&!\i&&!\i.{0,80}?(\i)\.getGuildId\(\).{0,50}?Guild voice channel without guild id)(?<=if\()/,
replace: (_, channel) => `!$self.isHiddenChannel(${channel})&&`
},
{ {
// Disable gradients for the HiddenChannelLockScreen of stage channels // Disable gradients for the HiddenChannelLockScreen of stage channels
match: /Guild voice channel without guild id.+?disableGradients:(?<=(\i)\.getGuildId\(\).+?)/, match: /"124px".+?disableGradients:(?<=(\i)\.getGuildId\(\).+?)/,
replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})||` replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})||`
}, },
{ {
// Disable strange styles applied to the header for the HiddenChannelLockScreen of stage channels // Disable strange styles applied to the header for the HiddenChannelLockScreen of stage channels
match: /Guild voice channel without guild id.+?style:(?<=(\i)\.getGuildId\(\).+?)/, match: /"124px".+?style:(?<=(\i)\.getGuildId\(\).+?)/,
replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?undefined:` replace: (m, channel) => `${m}$self.isHiddenChannel(${channel})?void 0:`
}, },
{ {
// Remove the divider and amount of users in stage channel components for the HiddenChannelLockScreen // Remove the divider and amount of users in stage channel components for the HiddenChannelLockScreen
@ -376,7 +371,7 @@ export default definePlugin({
}, },
{ {
// Remove the open chat button for the HiddenChannelLockScreen // Remove the open chat button for the HiddenChannelLockScreen
match: /"recents".+?null,(?=.+?channelId:(\i)\.id,showRequestToSpeakSidebar)/, match: /"recents".+?&&(?=\(.+?channelId:(\i)\.id,showRequestToSpeakSidebar)/,
replace: (m, channel) => `${m}!$self.isHiddenChannel(${channel})&&` replace: (m, channel) => `${m}!$self.isHiddenChannel(${channel})&&`
} }
], ],
@ -477,7 +472,7 @@ export default definePlugin({
HiddenChannelLockScreen: (channel: any) => <HiddenChannelLockScreen channel={channel} />, HiddenChannelLockScreen: (channel: any) => <HiddenChannelLockScreen channel={channel} />,
LockIcon: () => ( LockIcon: ErrorBoundary.wrap(() => (
<svg <svg
className={ChannelListClasses.icon} className={ChannelListClasses.icon}
height="18" height="18"
@ -488,7 +483,7 @@ export default definePlugin({
> >
<path className="shc-evenodd-fill-current-color" d="M17 11V7C17 4.243 14.756 2 12 2C9.242 2 7 4.243 7 7V11C5.897 11 5 11.896 5 13V20C5 21.103 5.897 22 7 22H17C18.103 22 19 21.103 19 20V13C19 11.896 18.103 11 17 11ZM12 18C11.172 18 10.5 17.328 10.5 16.5C10.5 15.672 11.172 15 12 15C12.828 15 13.5 15.672 13.5 16.5C13.5 17.328 12.828 18 12 18ZM15 11H9V7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V11Z" /> <path className="shc-evenodd-fill-current-color" d="M17 11V7C17 4.243 14.756 2 12 2C9.242 2 7 4.243 7 7V11C5.897 11 5 11.896 5 13V20C5 21.103 5.897 22 7 22H17C18.103 22 19 21.103 19 20V13C19 11.896 18.103 11 17 11ZM12 18C11.172 18 10.5 17.328 10.5 16.5C10.5 15.672 11.172 15 12 15C12.828 15 13.5 15.672 13.5 16.5C13.5 17.328 12.828 18 12 18ZM15 11H9V7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V11Z" />
</svg> </svg>
), ), { noop: true }),
HiddenChannelIcon: ErrorBoundary.wrap(() => ( HiddenChannelIcon: ErrorBoundary.wrap(() => (
<Tooltip text="Hidden Channel"> <Tooltip text="Hidden Channel">

View File

@ -21,8 +21,8 @@ import "./spotifyStyles.css";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons"; import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons";
import { Link } from "@components/Link";
import { debounce } from "@utils/debounce"; import { debounce } from "@utils/debounce";
import { openImageModal } from "@utils/discord";
import { classes, copyWithToast } from "@utils/misc"; import { classes, copyWithToast } from "@utils/misc";
import { ContextMenu, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common"; import { ContextMenu, FluxDispatcher, Forms, Menu, React, useEffect, useState, useStateFromStores } from "@webpack/common";
@ -231,7 +231,7 @@ function AlbumContextMenu({ track }: { track: Track; }) {
id="view-cover" id="view-cover"
label="View Album Cover" label="View Album Cover"
// trolley // trolley
action={() => (Vencord.Plugins.plugins.ViewIcons as any).openImage(track.album.image.url)} action={() => openImageModal(track.album.image.url)}
icon={ImageIcon} icon={ImageIcon}
/> />
<Menu.MenuControlItem <Menu.MenuControlItem
@ -253,6 +253,16 @@ function AlbumContextMenu({ track }: { track: Track; }) {
); );
} }
function makeLinkProps(name: string, condition: unknown, path: string) {
if (!condition) return {};
return {
role: "link",
onClick: () => SpotifyStore.openExternal(path),
onContextMenu: makeContextMenu(name, path)
} satisfies React.HTMLAttributes<HTMLElement>;
}
function Info({ track }: { track: Track; }) { function Info({ track }: { track: Track; }) {
const img = track?.album?.image; const img = track?.album?.image;
@ -288,12 +298,8 @@ function Info({ track }: { track: Track; }) {
variant="text-sm/semibold" variant="text-sm/semibold"
id={cl("song-title")} id={cl("song-title")}
className={cl("ellipoverflow")} className={cl("ellipoverflow")}
role={track.id ? "link" : undefined}
title={track.name} title={track.name}
onClick={track.id ? () => { {...makeLinkProps("Song", track.id, `/track/${track.id}`)}
SpotifyStore.openExternal(`/track/${track.id}`);
} : void 0}
onContextMenu={track.id ? makeContextMenu("Song", `/track/${track.id}`) : void 0}
> >
{track.name} {track.name}
</Forms.FormText> </Forms.FormText>
@ -302,16 +308,14 @@ function Info({ track }: { track: Track; }) {
by&nbsp; by&nbsp;
{track.artists.map((a, i) => ( {track.artists.map((a, i) => (
<React.Fragment key={a.name}> <React.Fragment key={a.name}>
<Link <span
className={cl("artist")} className={cl("artist")}
disabled={!a.id}
href={`https://open.spotify.com/artist/${a.id}`}
style={{ fontSize: "inherit" }} style={{ fontSize: "inherit" }}
title={a.name} title={a.name}
onContextMenu={makeContextMenu("Artist", `/artist/${a.id}`)} {...makeLinkProps("Artist", a.id, `/artist/${a.id}`)}
> >
{a.name} {a.name}
</Link> </span>
{i !== track.artists.length - 1 && <span className={cl("comma")}>{", "}</span>} {i !== track.artists.length - 1 && <span className={cl("comma")}>{", "}</span>}
</React.Fragment> </React.Fragment>
))} ))}
@ -320,17 +324,15 @@ function Info({ track }: { track: Track; }) {
{track.album.name && ( {track.album.name && (
<Forms.FormText variant="text-sm/normal" className={cl("ellipoverflow")}> <Forms.FormText variant="text-sm/normal" className={cl("ellipoverflow")}>
on&nbsp; on&nbsp;
<Link id={cl("album-title")} <span
href={`https://open.spotify.com/album/${track.album.id}`} id={cl("album-title")}
target="_blank"
className={cl("album")} className={cl("album")}
disabled={!track.album.id}
style={{ fontSize: "inherit" }} style={{ fontSize: "inherit" }}
title={track.album.name} title={track.album.name}
onContextMenu={makeContextMenu("Album", `/album/${track.album.id}`)} {...makeLinkProps("Album", track.album.id, `/album/${track.album.id}`)}
> >
{track.album.name} {track.album.name}
</Link> </span>
</Forms.FormText> </Forms.FormText>
)} )}
</div> </div>

View File

@ -89,7 +89,7 @@ export const SpotifyStore = proxyLazy(() => {
public isSettingPosition = false; public isSettingPosition = false;
public openExternal(path: string) { public openExternal(path: string) {
const url = Settings.plugins.SpotifyControls.useSpotifyUris const url = Settings.plugins.SpotifyControls.useSpotifyUris || Vencord.Plugins.isPluginEnabled("OpenInApp")
? "spotify:" + path.replaceAll("/", (_, idx) => idx === 0 ? "" : ":") ? "spotify:" + path.replaceAll("/", (_, idx) => idx === 0 ? "" : ":")
: "https://open.spotify.com" + path; : "https://open.spotify.com" + path;

View File

@ -131,8 +131,8 @@
color: var(--header-secondary); color: var(--header-secondary);
} }
.vc-spotify-artist:hover, .vc-spotify-artist[role="link"]:hover,
#vc-spotify-album-title:hover, #vc-spotify-album-title[role="link"]:hover,
#vc-spotify-song-title[role="link"]:hover { #vc-spotify-song-title[role="link"]:hover {
text-decoration: underline; text-decoration: underline;
cursor: pointer; cursor: pointer;

View File

@ -44,6 +44,9 @@ export function TranslationAccessory({ message }: { message: Message; }) {
const [translation, setTranslation] = useState<TranslationValue>(); const [translation, setTranslation] = useState<TranslationValue>();
useEffect(() => { useEffect(() => {
// Ignore MessageLinkEmbeds messages
if ((message as any).vencordEmbeddedBy) return;
TranslationSetters.set(message.id, setTranslation); TranslationSetters.set(message.id, setTranslation);
return () => void TranslationSetters.delete(message.id); return () => void TranslationSetters.delete(message.id);

View File

@ -18,19 +18,39 @@
import "./styles.css"; import "./styles.css";
import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
import { addAccessory, removeAccessory } from "@api/MessageAccessories"; import { addAccessory, removeAccessory } from "@api/MessageAccessories";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents"; import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { addButton, removeButton } from "@api/MessagePopover"; import { addButton, removeButton } from "@api/MessagePopover";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { ChannelStore } from "@webpack/common"; import { ChannelStore, Menu } from "@webpack/common";
import { settings } from "./settings"; import { settings } from "./settings";
import { TranslateChatBarIcon, TranslateIcon } from "./TranslateIcon"; import { TranslateChatBarIcon, TranslateIcon } from "./TranslateIcon";
import { handleTranslate, TranslationAccessory } from "./TranslationAccessory"; import { handleTranslate, TranslationAccessory } from "./TranslationAccessory";
import { translate } from "./utils"; import { translate } from "./utils";
const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }) => () => {
if (!message.content) return;
const group = findGroupChildrenByChildId("copy-text", children);
if (!group) return;
group.splice(group.findIndex(c => c?.props?.id === "copy-text") + 1, 0, (
<Menu.MenuItem
id="vc-trans"
label="Translate"
icon={TranslateIcon}
action={async () => {
const trans = await translate("received", message.content);
handleTranslate(message.id, trans);
}}
/>
));
};
export default definePlugin({ export default definePlugin({
name: "Translate", name: "Translate",
description: "Translate messages with Google Translate", description: "Translate messages with Google Translate",
@ -53,6 +73,8 @@ export default definePlugin({
start() { start() {
addAccessory("vc-translation", props => <TranslationAccessory message={props.message} />); addAccessory("vc-translation", props => <TranslationAccessory message={props.message} />);
addContextMenuPatch("message", messageCtxPatch);
addButton("vc-translate", message => { addButton("vc-translate", message => {
if (!message.content) return null; if (!message.content) return null;
@ -78,6 +100,7 @@ export default definePlugin({
stop() { stop() {
removePreSendListener(this.preSend); removePreSendListener(this.preSend);
removeContextMenuPatch("message", messageCtxPatch);
removeButton("vc-translate"); removeButton("vc-translate");
removeAccessory("vc-translation"); removeAccessory("vc-translation");
}, },

View File

@ -19,13 +19,13 @@
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { openUserProfile } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByCodeLazy } from "@webpack"; import { findByCodeLazy } from "@webpack";
import { GuildMemberStore, React, RelationshipStore, SelectedChannelStore } from "@webpack/common"; import { GuildMemberStore, React, RelationshipStore } from "@webpack/common";
import { User } from "discord-types/general"; import { User } from "discord-types/general";
const Avatar = findByCodeLazy(".typingIndicatorRef", "svg"); const Avatar = findByCodeLazy(".typingIndicatorRef", "svg");
const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
const settings = definePluginSettings({ const settings = definePluginSettings({
showAvatars: { showAvatars: {
@ -64,15 +64,7 @@ const TypingUser = ErrorBoundary.wrap(function ({ user, guildId }: Props) {
<strong <strong
role="button" role="button"
onClick={() => { onClick={() => {
openProfile({ openUserProfile(user.id);
userId: user.id,
guildId,
channelId: SelectedChannelStore.getChannelId(),
analyticsLocation: {
page: guildId ? "Guild Channel" : "DM Channel",
section: "Profile Popout"
}
});
}} }}
style={{ style={{
display: "grid", display: "grid",

View File

@ -75,7 +75,7 @@ function MentionWrapper({ data, UserMention, RoleMention, parse, props }: Mentio
const mention = children?.[0]?.props?.children; const mention = children?.[0]?.props?.children;
if (typeof mention !== "string") return; if (typeof mention !== "string") return;
const id = mention.match(/<@(\d+)>/)?.[1]; const id = mention.match(/<@!?(\d+)>/)?.[1];
if (!id) return; if (!id) return;
if (fetching.has(id)) if (fetching.has(id))

View File

@ -156,6 +156,8 @@ export default definePlugin({
const myChanId = SelectedChannelStore.getVoiceChannelId(); const myChanId = SelectedChannelStore.getVoiceChannelId();
const myId = UserStore.getCurrentUser().id; const myId = UserStore.getCurrentUser().id;
if (ChannelStore.getChannel(myChanId!)?.type === 13 /* Stage Channel */) return;
for (const state of voiceStates) { for (const state of voiceStates) {
const { userId, channelId, oldChannelId } = state; const { userId, channelId, oldChannelId } = state;
const isMe = userId === myId; const isMe = userId === myId;

View File

@ -35,7 +35,7 @@ interface UserContextProps {
} }
interface GuildContextProps { interface GuildContextProps {
guild: Guild; guild?: Guild;
} }
const settings = definePluginSettings({ const settings = definePluginSettings({
@ -100,7 +100,8 @@ const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: U
action={() => openImage(BannerStore.getGuildMemberAvatarURLSimple({ action={() => openImage(BannerStore.getGuildMemberAvatarURLSimple({
userId: user.id, userId: user.id,
avatar: memberAvatar, avatar: memberAvatar,
guildId guildId,
canAnimate: true
}, true))} }, true))}
icon={ImageIcon} icon={ImageIcon}
/> />
@ -109,7 +110,10 @@ const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: U
)); ));
}; };
const GuildContext: NavContextMenuPatchCallback = (children, { guild: { id, icon, banner } }: GuildContextProps) => () => { const GuildContext: NavContextMenuPatchCallback = (children, { guild }: GuildContextProps) => () => {
if(!guild) return;
const { id, icon, banner } = guild;
if (!banner && !icon) return; if (!banner && !icon) return;
children.splice(-1, 0, ( children.splice(-1, 0, (
@ -181,8 +185,8 @@ export default definePlugin({
// style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl, // style: { backgroundImage: shouldShowBanner ? "url(".concat(bannerUrl,
match: /style:\{(?=backgroundImage:(\i&&\i)\?"url\("\.concat\((\i),)/, match: /style:\{(?=backgroundImage:(\i&&\i)\?"url\("\.concat\((\i),)/,
replace: replace:
// onClick: () => shouldShowBanner && openImage(bannerUrl), style: { cursor: shouldShowBanner ? "pointer" : void 0, // onClick: () => shouldShowBanner && ev.target.style.backgroundImage && openImage(bannerUrl), style: { cursor: shouldShowBanner ? "pointer" : void 0,
'onClick:()=>$1&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,' 'onClick:ev=>$1&&ev.target.style.backgroundImage&&$self.openImage($2),style:{cursor:$1?"pointer":void 0,'
} }
}, },
{ {

View File

@ -47,9 +47,10 @@ const settings = definePluginSettings({
export default definePlugin({ export default definePlugin({
name: "WebContextMenus", name: "WebContextMenus",
description: "Re-adds context menus missing in the web version of Discord: Images, ChatInputBar, Links, 'Copy Link', 'Open Link', 'Copy Image', 'Save Image'", description: "Re-adds context menus missing in the web version of Discord: Links & Images (Copy/Open Link/Image), Text Area (Copy, Cut, Paste, SpellCheck)",
authors: [Devs.Ven], authors: [Devs.Ven],
enabledByDefault: true, enabledByDefault: true,
required: IS_VENCORD_DESKTOP,
settings, settings,
@ -146,36 +147,30 @@ export default definePlugin({
} }
}, },
{ {
find: ':"command-suggestions"', find: 'navId:"textarea-context"',
all: true,
predicate: () => settings.store.addBack, predicate: () => settings.store.addBack,
replacement: [ replacement: [
{
// desktopOnlyEntries = makeEntries(), spellcheckChildren = desktopOnlyEntries[0], languageChildren = desktopOnlyEntries[1]
match: /\i=.{0,30}text:\i,target:\i,onHeightUpdate:\i\}\),2\),(\i)=\i\[0\],(\i)=\i\[1\]/,
// set spellcheckChildren & languageChildren to empty arrays, so just in case patch 3 fails, we don't
// reference undefined variables
replace: "$1=[],$2=[]",
},
{ {
// if (!IS_DESKTOP) return null; // if (!IS_DESKTOP) return null;
match: /if\(!\i\.\i\)return null;/, match: /if\(!\i\.\i\)return null;/,
replace: "" replace: ""
}, },
{
// do not add menu items for entries removed in patch 1. Using a lookbehind for group 1 is slow,
// so just capture and add back
match: /("submit-button".+?)(\(0,\i\.jsx\)\(\i\.MenuGroup,\{children:\i\}\),){2}/,
replace: "$1"
},
{ {
// Change calls to DiscordNative.clipboard to us instead // Change calls to DiscordNative.clipboard to us instead
match: /\b\i\.default\.(copy|cut|paste)/g, match: /\b\i\.default\.(copy|cut|paste)/g,
replace: "$self.$1" replace: "$self.$1"
} }
] ]
},
{
find: '"add-to-dictionary"',
predicate: () => settings.store.addBack,
replacement: {
match: /var \i=\i\.text,/,
replace: "return [null,null];$&"
}
} }
// TODO: Maybe add spellcheck for VencordDesktop
], ],
async copyImage(url: string) { async copyImage(url: string) {

View File

@ -0,0 +1,79 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findLazy, mapMangledModuleLazy } from "@webpack";
import { ComponentDispatch, FluxDispatcher, NavigationRouter, SelectedGuildStore, SettingsRouter } from "@webpack/common";
const GuildNavBinds = mapMangledModuleLazy("mod+alt+down", {
CtrlTab: m => m.binds?.at(-1) === "ctrl+tab",
CtrlShiftTab: m => m.binds?.at(-1) === "ctrl+shift+tab",
});
const DigitBinds = findLazy(m => m.binds?.[0] === "mod+1");
export default definePlugin({
name: "WebKeybinds",
description: "Re-adds keybinds missing in the web version of Discord: ctrl+t, ctrl+shift+t, ctrl+tab, ctrl+shift+tab, ctrl+1-9, ctrl+,",
authors: [Devs.Ven],
enabledByDefault: true,
onKey(e: KeyboardEvent) {
const hasCtrl = e.ctrlKey || (e.metaKey && navigator.platform.includes("Mac"));
if (hasCtrl) switch (e.key) {
case "t":
case "T":
e.preventDefault();
if (e.shiftKey) {
if (SelectedGuildStore.getGuildId()) NavigationRouter.transitionToGuild("@me");
ComponentDispatch.safeDispatch("TOGGLE_DM_CREATE");
} else {
FluxDispatcher.dispatch({
type: "QUICKSWITCHER_SHOW",
query: "",
queryMode: null
});
}
break;
case ",":
e.preventDefault();
SettingsRouter.open("My Account");
break;
case "Tab":
const handler = e.shiftKey ? GuildNavBinds.CtrlShiftTab : GuildNavBinds.CtrlTab;
handler.action(e);
break;
default:
if (e.key >= "1" && e.key <= "9") {
e.preventDefault();
DigitBinds.action(e, `mod+${e.key}`);
}
break;
}
},
start() {
document.addEventListener("keydown", this.onKey);
},
stop() {
document.removeEventListener("keydown", this.onKey);
}
});

View File

@ -30,4 +30,6 @@ export const enum IpcEvents {
UPDATE = "VencordUpdate", UPDATE = "VencordUpdate",
BUILD = "VencordBuild", BUILD = "VencordBuild",
OPEN_MONACO_EDITOR = "VencordOpenMonacoEditor", OPEN_MONACO_EDITOR = "VencordOpenMonacoEditor",
OPEN_IN_APP__RESOLVE_REDIRECT = "VencordOIAResolveRedirect",
} }

View File

@ -28,15 +28,39 @@ import { openModal } from "./modal";
export const cloudLogger = new Logger("Cloud", "#39b7e0"); export const cloudLogger = new Logger("Cloud", "#39b7e0");
export const getCloudUrl = () => new URL(Settings.cloud.url); export const getCloudUrl = () => new URL(Settings.cloud.url);
const cloudUrlOrigin = () => getCloudUrl().origin;
const getUserId = () => {
const id = UserStore.getCurrentUser()?.id;
if (!id) throw new Error("User not yet logged in");
return id;
};
export async function getAuthorization() { export async function getAuthorization() {
const secrets = await DataStore.get<Record<string, string>>("Vencord_cloudSecret") ?? {}; const secrets = await DataStore.get<Record<string, string>>("Vencord_cloudSecret") ?? {};
return secrets[getCloudUrl().origin];
const origin = cloudUrlOrigin();
// we need to migrate from the old format here
if (secrets[origin]) {
await DataStore.update<Record<string, string>>("Vencord_cloudSecret", secrets => {
secrets ??= {};
// use the current user ID
secrets[`${origin}:${getUserId()}`] = secrets[origin];
delete secrets[origin];
return secrets;
});
// since this doesn't update the original object, we'll early return the existing authorization
return secrets[origin];
}
return secrets[`${origin}:${getUserId()}`];
} }
async function setAuthorization(secret: string) { async function setAuthorization(secret: string) {
await DataStore.update<Record<string, string>>("Vencord_cloudSecret", secrets => { await DataStore.update<Record<string, string>>("Vencord_cloudSecret", secrets => {
secrets ??= {}; secrets ??= {};
secrets[getCloudUrl().origin] = secret; secrets[`${cloudUrlOrigin()}:${getUserId()}`] = secret;
return secrets; return secrets;
}); });
} }
@ -44,7 +68,7 @@ async function setAuthorization(secret: string) {
export async function deauthorizeCloud() { export async function deauthorizeCloud() {
await DataStore.update<Record<string, string>>("Vencord_cloudSecret", secrets => { await DataStore.update<Record<string, string>>("Vencord_cloudSecret", secrets => {
secrets ??= {}; secrets ??= {};
delete secrets[getCloudUrl().origin]; delete secrets[`${cloudUrlOrigin()}:${getUserId()}`];
return secrets; return secrets;
}); });
} }
@ -117,8 +141,7 @@ export async function authorizeCloud() {
} }
export async function getCloudAuth() { export async function getCloudAuth() {
const userId = UserStore.getCurrentUser().id;
const secret = await getAuthorization(); const secret = await getAuthorization();
return window.btoa(`${secret}:${userId}`); return window.btoa(`${secret}:${getUserId()}`);
} }

View File

@ -17,9 +17,9 @@
*/ */
import { MessageObject } from "@api/MessageEvents"; import { MessageObject } from "@api/MessageEvents";
import { findByPropsLazy, findLazy } from "@webpack"; import { findByCodeLazy, findByPropsLazy, findLazy } from "@webpack";
import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore } from "@webpack/common"; import { ChannelStore, ComponentDispatch, GuildStore, MaskedLink, ModalImageClasses, PrivateChannelsStore, SelectedChannelStore, SelectedGuildStore, UserUtils } from "@webpack/common";
import { Guild, Message } from "discord-types/general"; import { Guild, Message, User } from "discord-types/general";
import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal"; import { ImageModal, ModalRoot, ModalSize, openModal } from "./modal";
@ -99,3 +99,28 @@ export function openImageModal(url: string, props?: Partial<React.ComponentProps
</ModalRoot> </ModalRoot>
)); ));
} }
const openProfile = findByCodeLazy("friendToken", "USER_PROFILE_MODAL_OPEN");
export async function openUserProfile(id: string) {
const user = await UserUtils.fetchUser(id);
if (!user) throw new Error("No such user: " + id);
const guildId = SelectedGuildStore.getGuildId();
openProfile({
userId: id,
guildId,
channelId: SelectedChannelStore.getChannelId(),
analyticsLocation: {
page: guildId ? "Guild Channel" : "DM Channel",
section: "Profile Popout"
}
});
}
/**
* Get the unique username for a user. Returns user.username for pomelo people, user.tag otherwise
*/
export function getUniqueUsername(user: User) {
return user.discriminator === "0" ? user.username : user.tag;
}

View File

@ -27,8 +27,8 @@ const unconfigurable = ["arguments", "caller", "prototype"];
const handler: ProxyHandler<any> = {}; const handler: ProxyHandler<any> = {};
const GET_KEY = Symbol.for("vencord.lazy.get"); const kGET = Symbol.for("vencord.lazy.get");
const CACHED_KEY = Symbol.for("vencord.lazy.cached"); const kCACHE = Symbol.for("vencord.lazy.cached");
for (const method of [ for (const method of [
"apply", "apply",
@ -46,11 +46,11 @@ for (const method of [
"setPrototypeOf" "setPrototypeOf"
]) { ]) {
handler[method] = handler[method] =
(target: any, ...args: any[]) => Reflect[method](target[GET_KEY](), ...args); (target: any, ...args: any[]) => Reflect[method](target[kGET](), ...args);
} }
handler.ownKeys = target => { handler.ownKeys = target => {
const v = target[GET_KEY](); const v = target[kGET]();
const keys = Reflect.ownKeys(v); const keys = Reflect.ownKeys(v);
for (const key of unconfigurable) { for (const key of unconfigurable) {
if (!keys.includes(key)) keys.push(key); if (!keys.includes(key)) keys.push(key);
@ -62,7 +62,7 @@ handler.getOwnPropertyDescriptor = (target, p) => {
if (typeof p === "string" && unconfigurable.includes(p)) if (typeof p === "string" && unconfigurable.includes(p))
return Reflect.getOwnPropertyDescriptor(target, p); return Reflect.getOwnPropertyDescriptor(target, p);
const descriptor = Reflect.getOwnPropertyDescriptor(target[GET_KEY](), p); const descriptor = Reflect.getOwnPropertyDescriptor(target[kGET](), p);
if (descriptor) Object.defineProperty(target, p, descriptor); if (descriptor) Object.defineProperty(target, p, descriptor);
return descriptor; return descriptor;
@ -72,15 +72,22 @@ handler.getOwnPropertyDescriptor = (target, p) => {
* Wraps the result of {@see makeLazy} in a Proxy you can consume as if it wasn't lazy. * Wraps the result of {@see makeLazy} in a Proxy you can consume as if it wasn't lazy.
* On first property access, the lazy is evaluated * On first property access, the lazy is evaluated
* @param factory lazy factory * @param factory lazy factory
* @param attempts how many times to try to evaluate the lazy before giving up
* @returns Proxy * @returns Proxy
* *
* Note that the example below exists already as an api, see {@link findByPropsLazy} * Note that the example below exists already as an api, see {@link findByPropsLazy}
* @example const mod = proxyLazy(() => findByProps("blah")); console.log(mod.blah); * @example const mod = proxyLazy(() => findByProps("blah")); console.log(mod.blah);
*/ */
export function proxyLazy<T>(factory: () => T): T { export function proxyLazy<T>(factory: () => T, attempts = 5): T {
const proxyDummy: { (): void;[CACHED_KEY]?: T;[GET_KEY](): T; } = Object.assign(function () { }, { let tries = 0;
[CACHED_KEY]: void 0, const proxyDummy = Object.assign(function () { }, {
[GET_KEY]: () => proxyDummy[CACHED_KEY] ??= factory(), [kCACHE]: void 0 as T | undefined,
[kGET]() {
if (!proxyDummy[kCACHE] && attempts > tries++) {
proxyDummy[kCACHE] = factory();
}
return proxyDummy[kCACHE];
}
}); });
return new Proxy(proxyDummy, handler) as any; return new Proxy(proxyDummy, handler) as any;

View File

@ -27,8 +27,12 @@ export async function toggle(isEnabled: boolean) {
if (isEnabled) { if (isEnabled) {
style = document.createElement("style"); style = document.createElement("style");
style.id = "vencord-custom-css"; style.id = "vencord-custom-css";
document.head.appendChild(style); document.documentElement.appendChild(style);
VencordNative.quickCss.addChangeListener(css => style.textContent = css); VencordNative.quickCss.addChangeListener(css => {
style.textContent = css;
// At the time of writing this, changing textContent resets the disabled state
style.disabled = !Settings.useQuickCss;
});
style.textContent = await VencordNative.quickCss.get(); style.textContent = await VencordNative.quickCss.get();
} }
} else } else
@ -39,7 +43,7 @@ async function initThemes() {
if (!themesStyle) { if (!themesStyle) {
themesStyle = document.createElement("style"); themesStyle = document.createElement("style");
themesStyle.id = "vencord-themes"; themesStyle.id = "vencord-themes";
document.head.appendChild(themesStyle); document.documentElement.appendChild(themesStyle);
} }
const { themeLinks } = Settings; const { themeLinks } = Settings;

View File

@ -41,10 +41,10 @@ export async function importSettings(data: string) {
throw new Error("Invalid Settings. Is this even a Vencord Settings file?"); throw new Error("Invalid Settings. Is this even a Vencord Settings file?");
} }
export async function exportSettings() { export async function exportSettings({ minify }: { minify?: boolean; } = {}) {
const settings = JSON.parse(VencordNative.settings.get()); const settings = JSON.parse(VencordNative.settings.get());
const quickCss = await VencordNative.quickCss.get(); const quickCss = await VencordNative.quickCss.get();
return JSON.stringify({ settings, quickCss }, null, 4); return JSON.stringify({ settings, quickCss }, null, minify ? undefined : 4);
} }
export async function downloadSettingsBackup() { export async function downloadSettingsBackup() {
@ -121,8 +121,8 @@ export async function uploadSettingsBackup(showToast = true): Promise<void> {
// Cloud settings // Cloud settings
const cloudSettingsLogger = new Logger("Cloud:Settings", "#39b7e0"); const cloudSettingsLogger = new Logger("Cloud:Settings", "#39b7e0");
export async function putCloudSettings() { export async function putCloudSettings(manual?: boolean) {
const settings = await exportSettings(); const settings = await exportSettings({ minify: true });
try { try {
const res = await fetch(new URL("/v1/settings", getCloudUrl()), { const res = await fetch(new URL("/v1/settings", getCloudUrl()), {
@ -149,6 +149,14 @@ export async function putCloudSettings() {
VencordNative.settings.set(JSON.stringify(PlainSettings, null, 4)); VencordNative.settings.set(JSON.stringify(PlainSettings, null, 4));
cloudSettingsLogger.info("Settings uploaded to cloud successfully"); cloudSettingsLogger.info("Settings uploaded to cloud successfully");
if (manual) {
showNotification({
title: "Cloud Settings",
body: "Synchronized settings to the cloud!",
noPersist: true,
});
}
} catch (e: any) { } catch (e: any) {
cloudSettingsLogger.error("Failed to sync up", e); cloudSettingsLogger.error("Failed to sync up", e);
showNotification({ showNotification({

View File

@ -20,14 +20,23 @@ import { Channel } from "discord-types/general";
import { FluxDispatcher, FluxEvents } from "./utils"; import { FluxDispatcher, FluxEvents } from "./utils";
type GenericFunction = (...args: any[]) => any;
export class FluxStore { export class FluxStore {
constructor(dispatcher: FluxDispatcher, eventHandlers?: Partial<Record<FluxEvents, (data: any) => void>>); constructor(dispatcher: FluxDispatcher, eventHandlers?: Partial<Record<FluxEvents, (data: any) => void>>);
addChangeListener(callback: () => void): void;
addReactChangeListener(callback: () => void): void;
removeChangeListener(callback: () => void): void;
removeReactChangeListener(callback: () => void): void;
emitChange(): void; emitChange(): void;
getDispatchToken(): string; getDispatchToken(): string;
getName(): string; getName(): string;
initialize(): void; initialize(): void;
initializeIfNeeded(): void; initializeIfNeeded(): void;
registerActionHandlers: GenericFunction;
syncWith: GenericFunction;
waitFor: GenericFunction;
__getLocalVars(): Record<string, any>; __getLocalVars(): Record<string, any>;
} }

View File

@ -77,6 +77,17 @@ export const Toasts = {
} }
}; };
/**
* Show a simple toast. If you need more options, use Toasts.show manually
*/
export function showToast(message: string, type = ToastType.MESSAGE) {
Toasts.show({
id: Toasts.genId(),
message,
type
});
}
export const UserUtils = { export const UserUtils = {
fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise<User>, fetchUser: findByCodeLazy(".USER(", "getUser") as (id: string) => Promise<User>,
}; };