SpotifyActivityToggle: Don't Use Settings

This commit is contained in:
thororen1234 2025-09-05 08:13:29 -04:00
parent 0aaf5daff2
commit 2aa47af0c9
No known key found for this signature in database
2 changed files with 50 additions and 50 deletions

View file

@ -4,12 +4,11 @@
* 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 definePlugin from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { Constants, React, RestAPI } from "@webpack/common";
import { Constants, React, RestAPI, useEffect, useState } from "@webpack/common";
const Button = findComponentByCodeLazy(".NONE,disabled:", ".PANEL_BUTTON");
@ -35,55 +34,54 @@ function makeSpotifyIcon(enabled: boolean) {
);
}
async function setSpotifyActivity(value: boolean) {
const { body } = await RestAPI.get({
url: Constants.Endpoints.CONNECTIONS
});
if (!body) return;
const spotifyId = body.find(conn => conn.type === "spotify")?.id;
await RestAPI.patch({
url: Constants.Endpoints.CONNECTION("spotify", spotifyId),
body: {
show_activity: value,
},
});
}
function SpotifyActivityToggleButton() {
const { spotifyConnection } = settings.store;
const [loading, setLoading] = useState(true);
const [id, setId] = useState<string | null>(null);
const [showActivity, setShowActivity] = useState<boolean | null>(null);
useEffect(() => {
(async () => {
const { body } = await RestAPI.get({
url: Constants.Endpoints.CONNECTIONS,
});
if (!body) return;
const spotifyConn = body.find(c => c.type === "spotify");
if (spotifyConn) {
setId(spotifyConn.id);
setShowActivity(spotifyConn.show_activity);
}
setLoading(false);
})();
}, []);
if (loading || !id || showActivity === null) return null;
return (
<Button
tooltipText={spotifyConnection ? "Turn off Spotify activity" : "Turn on Spotify activity"}
icon={makeSpotifyIcon(spotifyConnection)}
tooltipText={showActivity ? "Turn off Spotify activity" : "Turn on Spotify activity"}
icon={makeSpotifyIcon(showActivity)}
role="switch"
aria-checked={spotifyConnection}
redGlow={!spotifyConnection}
aria-checked={showActivity}
redGlow={!showActivity}
onClick={async () => {
const newValue = !spotifyConnection;
settings.store.spotifyConnection = newValue;
setSpotifyActivity(newValue);
const newValue = !showActivity;
setShowActivity(newValue);
await RestAPI.patch({
url: Constants.Endpoints.CONNECTION("spotify", id),
body: {
show_activity: newValue,
},
});
}}
/>
);
}
const settings = definePluginSettings({
spotifyConnection: {
type: OptionType.BOOLEAN,
description: "Show Spotify activity",
default: false,
onChange: async value => setSpotifyActivity(value),
}
});
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}",

View file

@ -44,19 +44,21 @@ export default definePlugin({
description: "If unread messages are sent by a user in DMs multiple times, you'll only receive one audio ping. Read the messages to reset the limit",
authors: [Devs.ProffDea],
settings,
patches: [{
find: ".getDesktopType()===",
replacement: [
{
match: /(\i\.\i\.getDesktopType\(\)===\i\.\i\.NEVER)\)/,
replace: "$&if(!$self.isPrivateChannelRead(arguments[0]?.message))return;else "
},
{
match: /sound:(\i\?\i:void 0,volume:\i,onClick)/,
replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1"
}
]
}],
patches: [
{
find: ".getDesktopType()===",
replacement: [
{
match: /(\i\.\i\.getDesktopType\(\)===\i\.\i\.NEVER)\)/,
replace: "$&if(!$self.isPrivateChannelRead(arguments[0]?.message))return;else "
},
{
match: /sound:(\i\?\i:void 0,volume:\i,onClick)/,
replace: "sound:!$self.isPrivateChannelRead(arguments[0]?.message)?undefined:$1"
}
]
}
],
isPrivateChannelRead(message: MessageJSON) {
const ignoreList = settings.store.ignoreUsers.split(", ").filter(Boolean);
if (ignoreList.includes(message.author.id)) return true;