spotifyActivityToggle

This commit is contained in:
thororen1234 2025-05-04 01:41:56 -04:00
parent 0327fd5204
commit 02acf08ab2
No known key found for this signature in database
2 changed files with 86 additions and 1 deletions

View file

@ -143,7 +143,8 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
- Signature by Ven, Rini, ImBanana, KrystalSkull
- Slap by Korbo
- SoundBoardLogger by Moxxie, fres, echo, maintained by thororen
- - SplitLargeMessages by Reycko
- SplitLargeMessages by Reycko
- SpotifyActivityToggle by thororen
- SpotifyLyrics by Joona
- StatsfmPresence by Crxa
- StatusPresets by iamme

View file

@ -0,0 +1,84 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2025 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { Constants, React, RestAPI } from "@webpack/common";
const Button = findComponentByCodeLazy(".NONE,disabled:", ".PANEL_BUTTON");
function makeSpotifyIcon(enabled: boolean) {
return (
<svg width="20" height="20" viewBox="0 0 50 50">
<path
fill={!enabled ? "var(--status-danger)" : "currentColor"}
d="M25.009,1.982C12.322,1.982,2,12.304,2,24.991S12.322,48,25.009,48s23.009-10.321,23.009-23.009S37.696,1.982,25.009,1.982z M34.748,35.333c-0.289,0.434-0.765,0.668-1.25,0.668c-0.286,0-0.575-0.081-0.831-0.252C30.194,34.1,26,33,22.5,33.001 c-3.714,0.002-6.498,0.914-6.526,0.923c-0.784,0.266-1.635-0.162-1.897-0.948s0.163-1.636,0.949-1.897 c0.132-0.044,3.279-1.075,7.474-1.077C26,30,30.868,30.944,34.332,33.253C35.022,33.713,35.208,34.644,34.748,35.333z M37.74,29.193 c-0.325,0.522-0.886,0.809-1.459,0.809c-0.31,0-0.624-0.083-0.906-0.26c-4.484-2.794-9.092-3.385-13.062-3.35 c-4.482,0.04-8.066,0.895-8.127,0.913c-0.907,0.258-1.861-0.272-2.12-1.183c-0.259-0.913,0.272-1.862,1.184-2.12 c0.277-0.079,3.854-0.959,8.751-1c4.465-0.037,10.029,0.61,15.191,3.826C37.995,27.328,38.242,28.388,37.74,29.193z M40.725,22.013 C40.352,22.647,39.684,23,38.998,23c-0.344,0-0.692-0.089-1.011-0.275c-5.226-3.068-11.58-3.719-15.99-3.725 c-0.021,0-0.042,0-0.063,0c-5.333,0-9.44,0.938-9.481,0.948c-1.078,0.247-2.151-0.419-2.401-1.495 c-0.25-1.075,0.417-2.149,1.492-2.4C11.729,16.01,16.117,15,21.934,15c0.023,0,0.046,0,0.069,0 c4.905,0.007,12.011,0.753,18.01,4.275C40.965,19.835,41.284,21.061,40.725,22.013z"
/>
</svg>
);
}
function SpotifyActivityToggleButton() {
const { spotifyConnection } = settings.store;
const setSpotifyConnection = value => settings.store.spotifyConnection = value;
return (
<Button
tooltipText={spotifyConnection ? "Turn off Spotify activity" : "Turn on Spotify activity"}
icon={makeSpotifyIcon(spotifyConnection)}
role="switch"
aria-checked={spotifyConnection}
redGlow={!spotifyConnection}
onClick={async () => {
const newValue = !spotifyConnection;
setSpotifyConnection(newValue);
const { body } = await RestAPI.get({
url: Constants.Endpoints.CONNECTIONS
});
const spotifyId = body.find(conn => conn.type === "spotify")?.id;
await RestAPI.patch({
url: Constants.Endpoints.CONNECTION("spotify", spotifyId),
body: {
show_activity: newValue,
},
});
}}
/>
);
}
const settings = definePluginSettings({
spotifyConnection: {
type: OptionType.BOOLEAN,
description: "Show Spotify activity",
default: false,
hidden: true
}
});
export default definePlugin({
name: "SpotifyActivityToggle",
description: "Adds a toggle button for Spotify activity visibility.",
authors: [EquicordDevs.thororen],
settings,
patches: [
{
find: "#{intl::ACCOUNT_SPEAKING_WHILE_MUTED}",
replacement: {
match: /className:\i\.buttons,.{0,50}children:\[/,
replace: "$&$self.SpotifyActivityToggleButton(),"
}
}
],
SpotifyActivityToggleButton: ErrorBoundary.wrap(SpotifyActivityToggleButton, { noop: true }),
});