Skip to content

Commit ae6a252

Browse files
committed
feat: add option doNotRememberSelectedPlayer
1 parent 3727c45 commit ae6a252

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ showChannelInPlayer: true # default is false. Will show the channel (if availabl
210210
hidePlaylistInPlayer: true # default is false. Will hide the playlist name in the player section.
211211
stopInsteadOfPause: true # default is false. Will show the stop button instead of the pause button when media is playing.
212212
storePlayerInSessionStorage: true # default is false. If set to true, the active player will be stored in the session storage instead of URL hash.
213+
doNotRememberSelectedPlayer: true # default is false. If set to true, the selected player will not be remembered in URL hash or session storage.
213214

214215
# media browser specific
215216
favoritesItemsPerRow: 1 # default is 4. Use this to show items as list.
@@ -344,6 +345,8 @@ You can change this behavior to use the browser's session storage by setting `st
344345

345346
If `entityId` is configured for the card, both the URL hash and session storage will be ignored on initial load. See more in the Usage section above.
346347

348+
If you never want to remember the selected player, you can set `doNotRememberSelectedPlayer: true` to an empty string.
349+
347350
## Sort order of entities
348351

349352
If you want to have a custom sorting for your entities in the groups section you can use the `entities` configuration.

src/card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class Card extends LitElement {
124124
}
125125
window.addEventListener(CALL_MEDIA_STARTED, this.callMediaStartedListener);
126126
window.addEventListener(CALL_MEDIA_DONE, this.callMediaDoneListener);
127-
if (!this.config.storePlayerInSessionStorage) {
127+
if (!this.config.storePlayerInSessionStorage && !this.config.doNotRememberSelectedPlayer) {
128128
window.addEventListener('hashchange', this.hashChangeListener);
129129
}
130130
}

src/components/group.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ class Group extends LitElement {
7373
private handleGroupClicked() {
7474
if (!this.selected) {
7575
this.selected = true;
76-
if (this.store.config.storePlayerInSessionStorage) {
77-
window.sessionStorage.setItem(SESSION_STORAGE_PLAYER_ID, this.player.id);
78-
} else {
79-
const newUrl = window.location.href.replace(/#.*/g, '');
80-
window.location.replace(`${newUrl}#${this.player.id}`);
76+
if (!this.store.config.doNotRememberSelectedPlayer) {
77+
if (this.store.config.storePlayerInSessionStorage) {
78+
window.sessionStorage.setItem(SESSION_STORAGE_PLAYER_ID, this.player.id);
79+
} else {
80+
const newUrl = window.location.href.replace(/#.*/g, '');
81+
window.location.replace(`${newUrl}#${this.player.id}`);
82+
}
8183
}
8284
this.dispatchEntityIdEvent();
8385
}

src/editor/advanced-editor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ export const ADVANCED_SCHEMA = [
169169
name: 'storePlayerInSessionStorage',
170170
selector: { boolean: {} },
171171
},
172+
{
173+
name: 'doNotRememberSelectedPlayer',
174+
selector: { boolean: {} },
175+
},
172176
];
173177

174178
class AdvancedEditor extends BaseEditor {

src/model/store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ export default class Store {
182182
}
183183

184184
private getActivePlayer() {
185+
if (this.config.doNotRememberSelectedPlayer) {
186+
return '';
187+
}
185188
if (this.config.storePlayerInSessionStorage) {
186189
return this.getActivePlayerFromStorage();
187190
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface CardConfig extends LovelaceCardConfig {
103103
inverseGroupMuteState?: boolean;
104104
storePlayerInSessionStorage?: boolean;
105105
sortFavoritesByType?: boolean;
106+
doNotRememberSelectedPlayer?: boolean;
106107
}
107108

108109
export interface MediaArtworkOverride {

0 commit comments

Comments
 (0)