Update SpotifyControls.plugin.js

This commit is contained in:
Mirco Wittrien 2021-05-03 21:22:44 +02:00
parent 2fd1303424
commit 5d009f70b2
1 changed files with 39 additions and 28 deletions

View File

@ -2,7 +2,7 @@
* @name SpotifyControls * @name SpotifyControls
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.1.3 * @version 1.1.4
* @description Adds a Control Panel while listening to Spotify on a connected Account * @description Adds a Control Panel while listening to Spotify on a connected Account
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,13 +17,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "SpotifyControls", "name": "SpotifyControls",
"author": "DevilBro", "author": "DevilBro",
"version": "1.1.3", "version": "1.1.4",
"description": "Adds a Control Panel while listening to Spotify on a connected Account" "description": "Adds a Control Panel while listening to Spotify on a connected Account"
}, },
"changeLog": { "changeLog": {
"improved": { "fixed": {
"Minimal Mode": "Added a bit of support for BDs minimal mode", "No Cover": "No Cover is no longer black on dark theme"
"No Cover": "Added a placeholder for song without a cover image"
} }
} }
}; };
@ -67,9 +66,10 @@ module.exports = (_ => {
} }
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var _this; var _this;
var controls, starting, lastSong, currentVolume, lastVolume, stopTime, previousIsClicked, previousDoubleTimeout, timelineTimeout, timelineDragging, updateInterval; var controls;
var starting, lastSong, currentVolume, lastVolume, stopTime, previousIsClicked, previousDoubleTimeout;
var timelineTimeout, timelineDragging, updateInterval;
var playbackState = {}; var playbackState = {};
var settings = {}, buttonConfigs = {};
const repeatStates = [ const repeatStates = [
"off", "off",
@ -227,7 +227,7 @@ module.exports = (_ => {
playerSize: playerSize, playerSize: playerSize,
disabled: socketDevice.device.is_restricted, disabled: socketDevice.device.is_restricted,
onClick: _ => { onClick: _ => {
if (previousIsClicked || !settings.doubleBack) { if (previousIsClicked || !_this.settings.general.doubleBack) {
previousIsClicked = false; previousIsClicked = false;
this.request(socketDevice.socket, socketDevice.device, "previous"); this.request(socketDevice.socket, socketDevice.device, "previous");
} }
@ -335,12 +335,12 @@ module.exports = (_ => {
}; };
const SpotifyControlsButtonComponent = class SpotifyControlsButton extends BdApi.React.Component { const SpotifyControlsButtonComponent = class SpotifyControlsButton extends BdApi.React.Component {
render() { render() {
if (!this.props.playerSize || !buttonConfigs[this.props.type] || !buttonConfigs[this.props.type][this.props.playerSize]) return null; if (!this.props.playerSize || !_this.settings.buttons[this.props.type] || !_this.settings.buttons[this.props.type][this.props.playerSize]) return null;
let button = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, { let button = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Button, BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.accountinfobutton, this.props.disabled ? BDFDB.disCN.accountinfobuttondisabled : BDFDB.disCN.accountinfobuttonenabled, this.props.active && BDFDB.disCN._spotifycontrolsbuttonactive), className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.accountinfobutton, this.props.disabled ? BDFDB.disCN.accountinfobuttondisabled : BDFDB.disCN.accountinfobuttonenabled, this.props.active && BDFDB.disCN._spotifycontrolsbuttonactive),
look: BDFDB.LibraryComponents.Button.Looks.BLANK, look: BDFDB.LibraryComponents.Button.Looks.BLANK,
size: BDFDB.LibraryComponents.Button.Sizes.NONE, size: BDFDB.LibraryComponents.Button.Sizes.NONE,
children: _this.defaults.buttonConfigs[this.props.type] && _this.defaults.buttonConfigs[this.props.type].icons ? (_this.defaults.buttonConfigs[this.props.type].icons[this.props.icon] || _this.defaults.buttonConfigs[this.props.type].icons[0]) : "?", children: _this.defaults.buttons[this.props.type] && _this.defaults.buttons[this.props.type].icons ? (_this.defaults.buttons[this.props.type].icons[this.props.icon] || _this.defaults.buttons[this.props.type].icons[0]) : "?",
onClick: this.props.disabled ? _ => {} : this.props.onClick, onClick: this.props.disabled ? _ => {} : this.props.onClick,
onContextMenu: this.props.disabled ? _ => {} : this.props.onContextMenu, onContextMenu: this.props.disabled ? _ => {} : this.props.onContextMenu,
}), "active", "disabled", "renderPopout", "icon", "type", "playerSize")); }), "active", "disabled", "renderPopout", "icon", "type", "playerSize"));
@ -424,11 +424,11 @@ module.exports = (_ => {
_this = this; _this = this;
this.defaults = { this.defaults = {
settings: { general: {
addTimeline: {value: true, description: "Show the Song Timeline in the Controls"}, addTimeline: {value: true, description: "Show the Song Timeline in the Controls"},
doubleBack: {value: true, description: "Requires the User to press the Back Button twice to go to previous Track"} doubleBack: {value: true, description: "Requires the User to press the Back Button twice to go to previous Track"}
}, },
buttonConfigs: { buttons: {
share: {value: {small: false, big: true}, icons: [""], description: "Share"}, share: {value: {small: false, big: true}, icons: [""], description: "Share"},
shuffle: {value: {small: false, big: true}, icons: [""], description: "Shuffle"}, shuffle: {value: {small: false, big: true}, icons: [""], description: "Shuffle"},
previous: {value: {small: true, big: true}, icons: [""], description: "Previous"}, previous: {value: {small: true, big: true}, icons: [""], description: "Previous"},
@ -527,6 +527,7 @@ module.exports = (_ => {
display: block; display: block;
width: 100%; width: 100%;
height: 100%; height: 100%;
color: var(--header-primary);
object-fit: cover; object-fit: cover;
} }
${BDFDB.dotCN._spotifycontrolscovermaximizer} { ${BDFDB.dotCN._spotifycontrolscovermaximizer} {
@ -630,6 +631,19 @@ module.exports = (_ => {
} }
onStart () { onStart () {
// REMOVE 24.04.2021
let oldData = BDFDB.DataUtils.load(this);
if (oldData.settings) {
this.settings.general = oldData.settings;
BDFDB.DataUtils.save(this.settings.general, this, "general");
BDFDB.DataUtils.remove(this, "settings");
}
if (oldData.buttonConfigs) {
this.settings.buttons = oldData.buttonConfigs;
BDFDB.DataUtils.save(this.settings.buttons, this, "buttons");
BDFDB.DataUtils.remove(this, "buttonConfigs");
}
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SpotifyTrackUtils, "getActivity", {after: e => { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SpotifyTrackUtils, "getActivity", {after: e => {
if (e.methodArguments[0] !== false) { if (e.methodArguments[0] !== false) {
if (e.returnValue && e.returnValue.name == "Spotify") this.updatePlayer(e.returnValue); if (e.returnValue && e.returnValue.name == "Spotify") this.updatePlayer(e.returnValue);
@ -675,12 +689,12 @@ module.exports = (_ => {
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings", title: "Settings",
collapseStates: collapseStates, collapseStates: collapseStates,
children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["settings", key], keys: ["general", key],
label: this.defaults.settings[key].description, label: this.defaults.general[key].description,
value: settings[key] value: this.settings.general[key]
})) }))
})); }));
@ -690,13 +704,13 @@ module.exports = (_ => {
children: [BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormTitle, { children: [BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormTitle, {
className: BDFDB.disCN.marginbottom4, className: BDFDB.disCN.marginbottom4,
tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H3, tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H3,
children: "Add control buttons in small and/or big player version: " children: "Add control Buttons in small and/or big Player Version: "
})].concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { })].concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
settings: Object.keys(this.defaults.buttonConfigs[Object.keys(this.defaults.buttonConfigs)[0]].value), settings: Object.keys(this.defaults.buttons[Object.keys(this.defaults.buttons)[0]].value),
data: Object.keys(buttonConfigs).map(key => Object.assign({}, buttonConfigs[key], { data: Object.keys(this.defaults.buttons).map(key => Object.assign({}, this.settings.buttons[key], {
key: key, key: key,
label: this.defaults.buttonConfigs[key].description, label: this.defaults.buttons[key].description,
icons: this.defaults.buttonConfigs[key].icons icons: this.defaults.buttons[key].icons
})), })),
noRemove: true, noRemove: true,
renderLabel: data => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { renderLabel: data => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
@ -719,8 +733,8 @@ module.exports = (_ => {
] ]
}), }),
onCheckboxChange: (value, instance) => { onCheckboxChange: (value, instance) => {
buttonConfigs[instance.props.cardId][instance.props.settingId] = value; this.settings.buttons[instance.props.cardId][instance.props.settingId] = value;
BDFDB.DataUtils.save(buttonConfigs, this, "buttonConfigs"); BDFDB.DataUtils.save(this.settings.buttons, this, "buttons");
this.SettingsUpdated = true; this.SettingsUpdated = true;
} }
})) }))
@ -738,10 +752,7 @@ module.exports = (_ => {
} }
} }
forceUpdateAll () { forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
buttonConfigs = BDFDB.DataUtils.get(this, "buttonConfigs");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.DiscordUtils.rerenderAll(); BDFDB.DiscordUtils.rerenderAll();
} }
@ -766,7 +777,7 @@ module.exports = (_ => {
if (index > -1) children.splice(index - 1, 0, BDFDB.ReactUtils.createElement(SpotifyControlsComponent, { if (index > -1) children.splice(index - 1, 0, BDFDB.ReactUtils.createElement(SpotifyControlsComponent, {
song: BDFDB.LibraryModules.SpotifyTrackUtils.getActivity(false), song: BDFDB.LibraryModules.SpotifyTrackUtils.getActivity(false),
maximized: BDFDB.DataUtils.load(this, "playerState", "maximized"), maximized: BDFDB.DataUtils.load(this, "playerState", "maximized"),
timeline: settings.addTimeline timeline: this.settings.general.addTimeline
}, true)); }, true));
return index > -1; return index > -1;
} }