Skip to content

Commit

Permalink
Merge pull request #26 from jeroentvb/dev
Browse files Browse the repository at this point in the history
feat: setting to add item to queue instead of playing it
  • Loading branch information
jeroentvb authored May 3, 2022
2 parents 41be10e + 8d68f2b commit 8826cea
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ Settings for the power bar can be found on spotify's settings page. There are se
* Control
* Alt
* Cmd/Windows
* **Amount of suggestions per category**. How many suggestions to show per per category. Default is 3. Technically this can be set to 50, but in the power bar it's limited to 10 per category due to it being a better user experience.
* **Amount of suggestions per category**. How many suggestions to show per per category. Default is 3. Technically this can be set to 50, but in the power bar it's limited to 10 per category due to it being a better user experience.
* **Add to queue**. Add the selected suggestion to the queue instead of playing it. When enabled hold `ctrl` (windows/linux) or `cmd` (macOs) when selecting the suggestion to add it to the playback queue.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "power-bar",
"version": "1.4.0",
"version": "1.5.0",
"author": {
"name": "jeroentvb",
"url": "https://github.com/jeroentvb"
Expand Down
19 changes: 17 additions & 2 deletions src/components/PowerBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Suggestions from './Suggestions';

import type { ICategorizedSuggestion, ISuggestion } from '../types/suggestions.model';
import type { SuggestionClickEmitEvent } from '../types/custom-events.model';
import { IS_INPUT_REGEX, KEY_COMBO, MODIFIER_KEYS, RESULTS_PER_CATEGORY } from '../constants';
import { ADD_TO_QUEUE, IS_INPUT_REGEX, KEY_COMBO, MODIFIER_KEYS, RESULTS_PER_CATEGORY } from '../constants';

interface LocalState {
active: boolean;
Expand Down Expand Up @@ -79,6 +79,11 @@ export default class PowerBar extends React.Component<Record<string, unknown>, L
}
}
},
[ADD_TO_QUEUE]: {
type: 'toggle',
description: 'Add suggestion to queue instead of playing it when holding ctrl (windows/linux) or cmd (mac)',
defaultValue: false,
}
});
this.settings.pushSettings();

Expand Down Expand Up @@ -107,8 +112,18 @@ export default class PowerBar extends React.Component<Record<string, unknown>, L
this.onSelectSuggestion(uri, e);
};

onSelectSuggestion(uri: string, { metaKey, ctrlKey }: KeyboardEvent | MouseEvent) {
async onSelectSuggestion(uri: string, { metaKey, ctrlKey }: KeyboardEvent | MouseEvent) {
// Play item/add to queue if modifier key is held
if (this.isMac && metaKey || !this.isMac && ctrlKey) {
const addToQueue = this.settings.getFieldValue(ADD_TO_QUEUE);
if (addToQueue) {
await Spicetify.CosmosAsync.post(`https://api.spotify.com/v1/me/player/queue?uri=${uri}`);

this.togglePowerBar();
Spicetify.showNotification('Added to queue');
return;
}

Spicetify.Player.playUri(uri);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/constants/change-notes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const CHANGE_NOTES = `
* Remove 'play immediately' setting
* Remove 'play immediately' setting in favour of 'add to queue'
- Default behaviour is navigating to the selected suggestion
- To just play and not navigate, hold \`ctrl\` (windows/linux) or \`cmd\` (mac) when selecting it
- To add to queue instad of playing the item, enable 'add to queue' and hold hold \`ctrl\` (windows/linux) or \`cmd\` (mac)
`;

export default CHANGE_NOTES;
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ export const RESULTS_PER_CATEGORY = 'results-per-category';

export const KEY_COMBO = 'key-combo';

export const ADD_TO_QUEUE = 'add-to-queue';

export const MODIFIER_KEYS: ['Shift', 'Control', 'Alt', 'Meta'] = ['Shift', 'Control', 'Alt', 'Meta'];

0 comments on commit 8826cea

Please sign in to comment.