Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping 15 sec progress #237

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions src/renderer/components/Lofi/Cover/Controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,58 @@ class Controls extends React.Component<any, any> {
this.props.parent.togglePlayPause();
}

async forward() {
async forward(e: React.MouseEvent) {
if (this.props.parent.state.spotifyError) {
return;
}

SpotifyApiInstance.fetch('/me/player/next', {
method: 'POST',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
if (e.ctrlKey) {
SpotifyApiInstance.fetch(`/me/player`, {
method: 'GET',
}).then((body) => {
const currentProgress = Number(body.progress_ms);
SpotifyApiInstance.fetch(`/me/player/seek?position_ms=${currentProgress + 15000}`, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'd rather have this 15000ms as a configurable setting, but for now it can stay that way. I'm in the process of refactoring the whole application, I'll include your change and expose the settings in the settings window...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also thought about doing that, but I wanted to start with smaller changes.

method: 'PUT',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
});
} else {
SpotifyApiInstance.fetch('/me/player/next', {
method: 'POST',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
}
this.props.parent.setPlaying(true);
}

async backward() {
async backward(e: React.MouseEvent) {
if (this.props.parent.state.spotifyError) {
return;
}

SpotifyApiInstance.fetch('/me/player/previous', {
method: 'POST',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
if (e.ctrlKey) {
SpotifyApiInstance.fetch(`/me/player`, {
method: 'GET',
}).then((body) => {
const currentProgress = Number(body.progress_ms);
SpotifyApiInstance.fetch(`/me/player/seek?position_ms=${currentProgress - 15000}`, {
method: 'PUT',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
});
} else {
SpotifyApiInstance.fetch('/me/player/previous', {
method: 'POST',
}).then(() => {
// Spotify API doesn't update fast enough sometimes, so give it some leeway
setTimeout(this.props.parent.listeningTo.bind(this), 2000);
});
}
this.props.parent.setPlaying(true);
}

Expand Down