Plugin
SpotifyControls
Adds a Spotify player above the account panel
1
import { definePluginSettings } from "@api/Settings";2
import { disableStyle, enableStyle } from "@api/Styles";3
import ErrorBoundary from "@components/ErrorBoundary";4
import { Devs } from "@utils/constants";5
import definePlugin, { OptionType } from "@utils/types";6
7
import hoverOnlyStyle from "./hoverOnly.css?managed";8
import { Player } from "./PlayerComponent";9
10
export const settings = definePluginSettings({11
hoverControls: {12
description: "Show controls on hover",13
type: OptionType.BOOLEAN,14
default: false,15
onChange: v => toggleHoverControls(v)16
},17
useSpotifyUris: {18
type: OptionType.BOOLEAN,19
description: "Open Spotify URIs instead of Spotify URLs. Will only work if you have Spotify installed and might not work on all platforms",20
default: false21
},22
previousButtonRestartsTrack: {23
type: OptionType.BOOLEAN,24
description: "Restart currently playing track when pressing the previous button if playtime is >3s",25
default: true26
}27
});28
29
function toggleHoverControls(value: boolean) {30
(value ? enableStyle : disableStyle)(hoverOnlyStyle);31
}32
33
export default definePlugin({34
name: "SpotifyControls",35
description: "Adds a Spotify player above the account panel",36
tags: ["Media", "Activity"],37
authors: [Devs.Ven, Devs.afn, Devs.KraXen72, Devs.Av32000, Devs.nin0dev],38
settings,39
patches: [40
{41
find: ".DISPLAY_NAME_STYLES_COACHMARK)",42
replacement: {43
// react.jsx)(AccountPanel, { ..., showTaglessAccountPanel: blah })44
match: /(?<=\i\.jsxs?\)\()(\i),{(?=[^}]*?userTag:\i,occluded:)/,45
// react.jsx(WrapperComponent, { VencordOriginal: AccountPanel, ...46
replace: "$self.PanelWrapper,{VencordOriginal:$1,"47
}48
},49
{50
find: ".PLAYER_DEVICES",51
replacement: [{52
// Adds POST and a Marker to the SpotifyAPI (so we can easily find it)53
match: /get:(\i)\.bind\(null,(\i\.\i)\.get\)/,54
replace: "post:$1.bind(null,$2.post),vcSpotifyMarker:1,$&"55
},56
{57
// Spotify Connect API returns status 202 instead of 204 when skipping tracks.58
// Discord rejects 202 which causes the request to send twice. This patch prevents this.59
match: /202===\i\.status/,60
replace: "false",61
}]62
},63
{64
find: 039;repeat:"off"!==039;,65
replacement: [66
{67
// Discord doesn't give you shuffle state and the repeat kind, only a boolean68
match: /repeat:"off"!==(\i),/,69
replace: "shuffle:arguments[2]?.shuffle_state??false,actual_repeat:$1,$&"70
},71
{72
match: /(?<=artists.filter\(\i=>).{0,10}\i\.id\)&&/,73
replace: ""74
}75
]76
},77
],78
79
start: () => toggleHoverControls(settings.store.hoverControls),80
81
PanelWrapper({ VencordOriginal, ...props }) {82
return (83
<>84
<ErrorBoundary85
fallback={() => (86
<div className="vc-spotify-fallback">87
<p>Failed to render Spotify Modal :(</p>88
<p >Check the console for errors</p>89
</div>90
)}91
>92
<Player />93
</ErrorBoundary>94
95
<VencordOriginal {...props} />96
</>97
);98
}99
});100