Skip to content

Commit 522c04d

Browse files
committed
[ 1.0.26 ] * Added playerBackgroundImageSize config option that specifies the size of the player background image. Defaults to "100% 100%"; More info can be found on the [wiki docs](https://github.com/thlucas1/spotifyplus_card/wiki/Configuration-Options#playerbackgroundimagesize).
1 parent 82971d1 commit 522c04d

File tree

8 files changed

+134
-34
lines changed

8 files changed

+134
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Change are listed in reverse chronological order (newest to oldest).
66

77
<span class="changelog">
88

9+
###### [ 1.0.26 ] - 2024/12/24
10+
11+
* Added `playerBackgroundImageSize` config option that specifies the size of the player background image. Defaults to "100% 100%"; More info can be found on the [wiki docs](https://github.com/thlucas1/spotifyplus_card/wiki/Configuration-Options#playerbackgroundimagesize).
12+
913
###### [ 1.0.25 ] - 2024/12/23
1014

1115
* Ability to play track favorites starting from selected favorite track, which will now automatically add the following tracks (up to 50) to the player queue. Prior to this, only the selected track would play and then play would stop. Note that the 50 track limitation is a Spotify Web API limit.

SpotifyPlusCard.njsproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,9 @@
141141
<TypeScriptCompile Include="src\components\userpreset-actions.ts" />
142142
<TypeScriptCompile Include="src\editor\category-browser-editor.ts" />
143143
<TypeScriptCompile Include="src\editor\episode-fav-browser-editor.ts" />
144-
<TypeScriptCompile Include="src\events\category-display.ts">
145-
<SubType>Code</SubType>
146-
</TypeScriptCompile>
147-
<TypeScriptCompile Include="src\events\filter-section-media.ts">
148-
<SubType>Code</SubType>
149-
</TypeScriptCompile>
144+
<TypeScriptCompile Include="src\editor\player-general-editor.ts" />
145+
<TypeScriptCompile Include="src\events\category-display.ts" />
146+
<TypeScriptCompile Include="src\events\filter-section-media.ts" />
150147
<TypeScriptCompile Include="src\events\search-media.ts" />
151148
<TypeScriptCompile Include="src\sections\category-browser.ts" />
152149
<TypeScriptCompile Include="src\sections\episode-fav-browser.ts" />

src/components/player-body-track.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ export class PlayerBodyTrack extends PlayerBodyBase {
429429

430430
try {
431431

432+
// if editing the card, then don't bother updating actions as we will not
433+
// display the actions dialog.
434+
if (this.isCardInEditPreview) {
435+
return false;
436+
}
437+
432438
// process actions that don't require a progress indicator.
433439
if (action == Actions.AlbumCopyPresetToClipboard) {
434440

src/constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css } from 'lit';
22

33
/** current version of the card. */
4-
export const CARD_VERSION = '1.0.25';
4+
export const CARD_VERSION = '1.0.26';
55

66
/** SpotifyPlus integration domain identifier. */
77
export const DOMAIN_SPOTIFYPLUS = 'spotifyplus';
@@ -49,6 +49,9 @@ export const PLAYER_CONTROLS_BACKGROUND_COLOR_DEFAULT = '#000000BB';
4949
/** default size of the icons in the Player controls area. */
5050
export const PLAYER_CONTROLS_ICON_SIZE_DEFAULT = '2.0rem';
5151

52+
/** default size of the player background image. */
53+
export const PLAYER_BACKGROUND_IMAGE_SIZE_DEFAULT = "100% 100%";
54+
5255

5356
export const listStyle = css`
5457
.list {

src/editor/player-editor.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@ import { choose } from 'lit/directives/choose.js';
66
// our imports.
77
import { BaseEditor } from './base-editor';
88
import './editor-form';
9+
import './player-general-editor';
910
import './player-header-editor';
1011
import './player-controls-editor';
1112
import './player-volume-editor';
1213

1314
/** Configuration area editor sections enum. */
1415
enum ConfigArea {
16+
GENERAL = 'General',
1517
HEADER = 'Header',
1618
CONTROLS = 'Controls',
1719
VOLUME = 'Volume',
1820
}
1921

2022
/** Configuration area editor section keys array. */
21-
const { HEADER, CONTROLS, VOLUME } = ConfigArea;
23+
const { GENERAL, HEADER, CONTROLS, VOLUME } = ConfigArea;
2224

2325

2426
class PlayerSettingsEditor extends BaseEditor {
2527

26-
@state() private configArea = HEADER;
28+
@state() private configArea = GENERAL;
2729

2830
/**
2931
* Invoked on each update to perform rendering tasks.
@@ -41,7 +43,7 @@ class PlayerSettingsEditor extends BaseEditor {
4143
Settings that control the Player section look and feel
4244
</div>
4345
<ha-control-button-group>
44-
${[HEADER, CONTROLS, VOLUME].map(
46+
${[GENERAL, HEADER, CONTROLS, VOLUME].map(
4547
(configArea) => html`
4648
<ha-control-button
4749
selected=${this.configArea === configArea || nothing}
@@ -62,6 +64,10 @@ class PlayerSettingsEditor extends BaseEditor {
6264

6365
// show the desired section editor.
6466
return choose(this.configArea, [
67+
[
68+
GENERAL,
69+
() => html`<spc-player-general-editor .config=${this.config} .hass=${this.hass}></spc-player-general-editor>`,
70+
],
6571
[
6672
HEADER,
6773
() => html`<spc-player-header-editor .config=${this.config} .hass=${this.hass}></spc-player-header-editor>`,

src/editor/player-general-editor.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// lovelace card imports.
2+
import { css, html, TemplateResult } from 'lit';
3+
4+
// our imports.
5+
import { BaseEditor } from './base-editor';
6+
import { Section } from '../types/section';
7+
import { PLAYER_BACKGROUND_IMAGE_SIZE_DEFAULT } from '../constants';
8+
9+
10+
const CONFIG_SETTINGS_SCHEMA = [
11+
{
12+
name: 'playerBackgroundImageSize',
13+
label: 'Size of the player background image',
14+
help: 'default is "' + PLAYER_BACKGROUND_IMAGE_SIZE_DEFAULT + '"',
15+
required: false,
16+
type: 'string',
17+
},
18+
];
19+
20+
21+
class PlayerGeneralSettingsEditor extends BaseEditor {
22+
23+
/**
24+
* Invoked on each update to perform rendering tasks.
25+
*
26+
* This method may return any value renderable by lit-html's `ChildPart` (typically a `TemplateResult`).
27+
* Setting properties inside this method will *not* trigger the element to update.
28+
*/
29+
protected render(): TemplateResult {
30+
31+
// ensure store is created.
32+
super.createStore();
33+
34+
// render html.
35+
return html`
36+
<div class="schema-title">
37+
Player General area settings
38+
</div>
39+
<spc-editor-form
40+
.schema=${CONFIG_SETTINGS_SCHEMA}
41+
.section=${Section.PLAYER}
42+
.store=${this.store}
43+
.config=${this.config}
44+
.hass=${this.hass}
45+
></spc-editor-form>
46+
`;
47+
}
48+
49+
50+
/**
51+
* Style definitions used by this TemplateResult.
52+
*/
53+
static get styles() {
54+
return css`
55+
.schema-title {
56+
margin: 0.4rem 0;
57+
text-align: left;
58+
font-size: 1rem;
59+
color: var(--secondary-text-color);
60+
}
61+
`;
62+
}
63+
64+
}
65+
66+
customElements.define('spc-player-general-editor', PlayerGeneralSettingsEditor);

src/sections/player.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// lovelace card imports.
22
import { css, html, LitElement, PropertyValues, TemplateResult } from 'lit';
33
import { customElement, property, state } from "lit/decorators.js";
4-
import { styleMap } from 'lit-html/directives/style-map.js';
4+
import { styleMap, StyleInfo } from 'lit-html/directives/style-map.js';
55

66
// ** IMPORTANT - Vibrant notes:
77
// ensure that you have "compilerOptions"."lib": [ ... , "WebWorker" ] specified
@@ -125,6 +125,7 @@ export class Player extends LitElement implements playerAlerts {
125125
* style definitions used by this component.
126126
* */
127127
static get styles() {
128+
128129
return css`
129130
130131
.hoverable:focus,
@@ -148,7 +149,7 @@ export class Player extends LitElement implements playerAlerts {
148149
/*background-color: #000000;*/
149150
background-position: center;
150151
background-repeat: no-repeat;
151-
background-size: var(--spc-player-background-size);
152+
background-size: var(--spc-player-background-size, 100% 100%); /* PLAYER_BACKGROUND_IMAGE_SIZE_DEFAULT */
152153
text-align: -webkit-center;
153154
height: 100%;
154155
width: 100%;
@@ -215,12 +216,16 @@ export class Player extends LitElement implements playerAlerts {
215216
*/
216217
private styleBackgroundImage() {
217218

218-
// stretch the background cover art to fit the entire player.
219-
//const backgroundSize = 'cover';
220-
//const backgroundSize = 'contain';
221-
let backgroundSize = '100% 100%';
222-
if (this.config.width == 'fill') {
223-
// if in fill mode, then do not stretch the image.
219+
// get default player background size.
220+
let backgroundSize: string | undefined;
221+
222+
// allow user configuration to override background size.
223+
if (this.config.playerBackgroundImageSize) {
224+
backgroundSize = this.config.playerBackgroundImageSize;
225+
}
226+
227+
// if not configured AND in fill mode, then do not stretch the background image.
228+
if ((!backgroundSize) && (this.config.width == 'fill')) {
224229
backgroundSize = 'contain';
225230
}
226231

@@ -262,22 +267,25 @@ export class Player extends LitElement implements playerAlerts {
262267
// set player controls and volume controls icon size.
263268
const playerControlsIconSize = this.config.playerControlsIconSize || PLAYER_CONTROLS_ICON_SIZE_DEFAULT;
264269

265-
return styleMap({
266-
'background-image': `url(${imageUrl})`,
267-
'--spc-player-background-size': `${backgroundSize}`,
268-
'--spc-player-header-bg-color': `${headerBackgroundColor}`,
269-
'--spc-player-header-color': `#ffffff`,
270-
'--spc-player-controls-bg-color': `${controlsBackgroundColor}`,
271-
'--spc-player-controls-color': `#ffffff`,
272-
'--spc-player-controls-icon-size': `${playerControlsIconSize}`,
273-
'--spc-player-controls-icon-button-size': `var(--spc-player-controls-icon-size, ${PLAYER_CONTROLS_ICON_SIZE_DEFAULT}) + 0.75rem`,
274-
'--spc-player-palette-vibrant': `${this._colorPaletteVibrant}`,
275-
'--spc-player-palette-muted': `${this._colorPaletteMuted}`,
276-
'--spc-player-palette-darkvibrant': `${this._colorPaletteDarkVibrant}`,
277-
'--spc-player-palette-darkmuted': `${this._colorPaletteDarkMuted}`,
278-
'--spc-player-palette-lightvibrant': `${this._colorPaletteLightVibrant}`,
279-
'--spc-player-palette-lightmuted': `${this._colorPaletteLightMuted}`,
280-
});
270+
// build style info object.
271+
const styleInfo: StyleInfo = <StyleInfo>{};
272+
styleInfo['background-image'] = `url(${imageUrl})`;
273+
if (backgroundSize)
274+
styleInfo['--spc-player-background-size'] = `${backgroundSize}`;
275+
styleInfo['--spc-player-header-bg-color'] = `${headerBackgroundColor}`;
276+
styleInfo['--spc-player-header-color'] = `#ffffff`;
277+
styleInfo['--spc-player-controls-bg-color'] = `${controlsBackgroundColor} `;
278+
styleInfo['--spc-player-controls-color'] = `#ffffff`;
279+
styleInfo['--spc-player-controls-icon-size'] = `${playerControlsIconSize}`;
280+
styleInfo['--spc-player-controls-icon-button-size'] = `var(--spc-player-controls-icon-size, ${PLAYER_CONTROLS_ICON_SIZE_DEFAULT}) + 0.75rem`;
281+
styleInfo['--spc-player-palette-vibrant'] = `${this._colorPaletteVibrant}`;
282+
styleInfo['--spc-player-palette-muted'] = `${this._colorPaletteMuted}`;
283+
styleInfo['--spc-player-palette-darkvibrant'] = `${this._colorPaletteDarkVibrant}`;
284+
styleInfo['--spc-player-palette-darkmuted'] = `${this._colorPaletteDarkMuted}`;
285+
styleInfo['--spc-player-palette-lightvibrant'] = `${this._colorPaletteLightVibrant}`;
286+
styleInfo['--spc-player-palette-lightmuted'] = `${this._colorPaletteLightMuted}`;
287+
return styleMap(styleInfo);
288+
281289
}
282290

283291

src/types/card-config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ export interface CardConfig extends LovelaceCardConfig {
309309
*/
310310
episodeFavBrowserItemsSortTitle?: boolean;
311311

312+
/**
313+
* Size of the player background image.
314+
* Suggested values:
315+
* - "100% 100%" image size is 100%, stretching to fill available space.
316+
* - "contain" image is contained in the boundaries without stretching.
317+
* - "cover" image covers the entire background, stretching to fill available space.
318+
* Default is "100% 100%".
319+
*/
320+
playerBackgroundImageSize?: string;
321+
312322
/**
313323
* Title displayed in the header area of the Player section form.
314324
* Omit this parameter to hide the title display area.

0 commit comments

Comments
 (0)