Compare commits

...

16 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
18 changed files with 146 additions and 76 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "vencord", "name": "vencord",
"private": "true", "private": "true",
"version": "1.3.2", "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

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

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

@ -20,7 +20,7 @@ import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { showToast, Toasts } from "@webpack/common"; import { showToast, Toasts } from "@webpack/common";
import { MouseEvent } from "react"; import type { MouseEvent } from "react";
const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/; const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/; const SpotifyMatcher = /^https:\/\/open\.spotify\.com\/(track|album|artist|playlist|user)\/(.+)(?:\?.+?)?$/;
@ -77,12 +77,12 @@ export default definePlugin({
} }
], ],
async handleLink(data: { href: string; }, event: MouseEvent) { async handleLink(data: { href: string; }, event?: MouseEvent) {
if (!data) return false; if (!data) return false;
let url = data.href; let url = data.href;
if (!IS_WEB && ShortUrlMatcher.test(url)) { if (!IS_WEB && ShortUrlMatcher.test(url)) {
event.preventDefault(); event?.preventDefault();
// CORS jumpscare // CORS jumpscare
url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url); url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url);
} }
@ -96,7 +96,7 @@ export default definePlugin({
const [, type, id] = match; const [, type, id] = match;
VencordNative.native.openExternal(`spotify:${type}:${id}`); VencordNative.native.openExternal(`spotify:${type}:${id}`);
event.preventDefault(); event?.preventDefault();
return true; return true;
} }
@ -106,7 +106,7 @@ export default definePlugin({
if (!SteamMatcher.test(url)) break steam; if (!SteamMatcher.test(url)) break steam;
VencordNative.native.openExternal(`steam://openurl/${url}`); VencordNative.native.openExternal(`steam://openurl/${url}`);
event.preventDefault(); event?.preventDefault();
// Steam does not focus itself so show a toast so it's slightly less confusing // Steam does not focus itself so show a toast so it's slightly less confusing
showToast("Opened link in Steam", Toasts.Type.SUCCESS); showToast("Opened link in Steam", Toasts.Type.SUCCESS);
@ -120,13 +120,13 @@ export default definePlugin({
if (!match) break epic; if (!match) break epic;
VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`); VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`);
event.preventDefault(); event?.preventDefault();
return true; return true;
} }
// in case short url didn't end up being something we can handle // in case short url didn't end up being something we can handle
if (event.defaultPrevented) { if (event?.defaultPrevented) {
window.open(url, "_blank"); window.open(url, "_blank");
return true; return true;
} }

View File

@ -50,7 +50,7 @@ export async function onRelationshipRemove({ relationship: { type, id } }: Relat
() => openUserProfile(user.id) () => openUserProfile(user.id)
); );
break; break;
case RelationshipType.FRIEND_REQUEST: case RelationshipType.INCOMING_REQUEST:
if (settings.store.friendRequestCancels) if (settings.store.friendRequestCancels)
notify( notify(
`A friend request from ${getUniqueUsername(user)} has been removed.`, `A friend request from ${getUniqueUsername(user)} has been removed.`,

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

@ -80,7 +80,10 @@ export async function syncAndRunChecks() {
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)
@ -164,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

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

@ -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;
@ -472,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"
@ -483,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,7 +21,6 @@ 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 { openImageModal } from "@utils/discord";
import { classes, copyWithToast } from "@utils/misc"; import { classes, copyWithToast } from "@utils/misc";
@ -254,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;
@ -289,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>
@ -303,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>
))} ))}
@ -321,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

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

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

@ -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({