Compare commits

..

8 Commits

Author SHA1 Message Date
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
8 changed files with 60 additions and 44 deletions

View File

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

View File

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

View File

@ -20,7 +20,7 @@ import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { showToast, Toasts } from "@webpack/common";
import { MouseEvent } from "react";
import type { MouseEvent } from "react";
const ShortUrlMatcher = /^https:\/\/(spotify\.link|s\.team)\/.+$/;
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;
let url = data.href;
if (!IS_WEB && ShortUrlMatcher.test(url)) {
event.preventDefault();
event?.preventDefault();
// CORS jumpscare
url = await VencordNative.pluginHelpers.OpenInApp.resolveRedirect(url);
}
@ -96,7 +96,7 @@ export default definePlugin({
const [, type, id] = match;
VencordNative.native.openExternal(`spotify:${type}:${id}`);
event.preventDefault();
event?.preventDefault();
return true;
}
@ -106,7 +106,7 @@ export default definePlugin({
if (!SteamMatcher.test(url)) break steam;
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
showToast("Opened link in Steam", Toasts.Type.SUCCESS);
@ -120,13 +120,13 @@ export default definePlugin({
if (!match) break epic;
VencordNative.native.openExternal(`com.epicgames.launcher://store/${match[1]}`);
event.preventDefault();
event?.preventDefault();
return true;
}
// in case short url didn't end up being something we can handle
if (event.defaultPrevented) {
if (event?.defaultPrevented) {
window.open(url, "_blank");
return true;
}

View File

@ -29,7 +29,7 @@ import type { Channel, Role } from "discord-types/general";
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;
const CONNECT = 1n << 20n;
@ -472,7 +472,7 @@ export default definePlugin({
HiddenChannelLockScreen: (channel: any) => <HiddenChannelLockScreen channel={channel} />,
LockIcon: () => (
LockIcon: ErrorBoundary.wrap(() => (
<svg
className={ChannelListClasses.icon}
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" />
</svg>
),
), { noop: true }),
HiddenChannelIcon: ErrorBoundary.wrap(() => (
<Tooltip text="Hidden Channel">

View File

@ -21,7 +21,6 @@ import "./spotifyStyles.css";
import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex";
import { ImageIcon, LinkIcon, OpenExternalIcon } from "@components/Icons";
import { Link } from "@components/Link";
import { debounce } from "@utils/debounce";
import { openImageModal } from "@utils/discord";
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; }) {
const img = track?.album?.image;
@ -289,12 +298,8 @@ function Info({ track }: { track: Track; }) {
variant="text-sm/semibold"
id={cl("song-title")}
className={cl("ellipoverflow")}
role={track.id ? "link" : undefined}
title={track.name}
onClick={track.id ? () => {
SpotifyStore.openExternal(`/track/${track.id}`);
} : void 0}
onContextMenu={track.id ? makeContextMenu("Song", `/track/${track.id}`) : void 0}
{...makeLinkProps("Song", track.id, `/track/${track.id}`)}
>
{track.name}
</Forms.FormText>
@ -303,16 +308,14 @@ function Info({ track }: { track: Track; }) {
by&nbsp;
{track.artists.map((a, i) => (
<React.Fragment key={a.name}>
<Link
<span
className={cl("artist")}
disabled={!a.id}
href={`https://open.spotify.com/artist/${a.id}`}
style={{ fontSize: "inherit" }}
title={a.name}
onContextMenu={makeContextMenu("Artist", `/artist/${a.id}`)}
{...makeLinkProps("Artist", a.id, `/artist/${a.id}`)}
>
{a.name}
</Link>
</span>
{i !== track.artists.length - 1 && <span className={cl("comma")}>{", "}</span>}
</React.Fragment>
))}
@ -321,17 +324,15 @@ function Info({ track }: { track: Track; }) {
{track.album.name && (
<Forms.FormText variant="text-sm/normal" className={cl("ellipoverflow")}>
on&nbsp;
<Link id={cl("album-title")}
href={`https://open.spotify.com/album/${track.album.id}`}
target="_blank"
<span
id={cl("album-title")}
className={cl("album")}
disabled={!track.album.id}
style={{ fontSize: "inherit" }}
title={track.album.name}
onContextMenu={makeContextMenu("Album", `/album/${track.album.id}`)}
{...makeLinkProps("Album", track.album.id, `/album/${track.album.id}`)}
>
{track.album.name}
</Link>
</span>
</Forms.FormText>
)}
</div>

View File

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

View File

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

View File

@ -41,10 +41,10 @@ export async function importSettings(data: string) {
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 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() {
@ -121,8 +121,8 @@ export async function uploadSettingsBackup(showToast = true): Promise<void> {
// Cloud settings
const cloudSettingsLogger = new Logger("Cloud:Settings", "#39b7e0");
export async function putCloudSettings() {
const settings = await exportSettings();
export async function putCloudSettings(manual?: boolean) {
const settings = await exportSettings({ minify: true });
try {
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));
cloudSettingsLogger.info("Settings uploaded to cloud successfully");
if (manual) {
showNotification({
title: "Cloud Settings",
body: "Synchronized settings to the cloud!",
noPersist: true,
});
}
} catch (e: any) {
cloudSettingsLogger.error("Failed to sync up", e);
showNotification({