Skip to content

fix: shuffle shortcut bug#50

Merged
sozercan merged 2 commits intomainfrom
shuffle-bug
Jan 7, 2026
Merged

fix: shuffle shortcut bug#50
sozercan merged 2 commits intomainfrom
shuffle-bug

Conversation

@sozercan
Copy link
Owner

@sozercan sozercan commented Jan 7, 2026

Description

fixes #43

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🎨 UI/UX improvement
  • ♻️ Refactoring (no functional changes)
  • 🧪 Test update
  • 🔧 Build/CI configuration

Related Issues

Changes Made

Testing

  • Unit tests pass (xcodebuild test -only-testing:KasetTests)
  • Manual testing performed
  • UI tested on macOS 26+

Checklist

  • My code follows the project's style guidelines
  • I have run swiftlint --strict && swiftformat .
  • I have added tests that prove my fix/feature works
  • New and existing unit tests pass locally
  • I have updated documentation if needed
  • I have checked for any performance implications
  • My changes generate no new warnings

Screenshots

Additional Notes

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI review requested due to automatic review settings January 7, 2026 16:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where YouTube's media session intercepts keyboard shortcuts (particularly when shuffle is enabled) and plays YouTube's autoplay track instead of the intended track from Kaset's queue. The fix introduces a flag to track Kaset-initiated playback and corrects any YouTube autoplay interference by re-playing the intended track.

  • Adds isKasetInitiatedPlayback flag to track when Kaset initiates playback
  • Updates updateTrackMetadata to detect and correct YouTube autoplay interference
  • Routes dock menu actions through PlayerService for proper shuffle handling

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
Core/Services/Player/PlayerService.swift Adds isKasetInitiatedPlayback flag and logic to detect/correct YouTube autoplay interference when Kaset initiates track changes
App/AppDelegate.swift Updates dock menu actions to use PlayerService instead of direct WebView calls, ensuring shuffle mode is respected
App/KasetApp.swift Wires up PlayerService reference to AppDelegate for dock menu functionality
Tests/KasetTests/PlayerServiceTests.swift Adds tests for shuffle behavior and YouTube autoplay correction

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/// Flag to track when a song is nearing its end.
private var songNearingEnd: Bool = false

/// Flag to track when we initiated a track change (to ignore YouTube's autoplay).
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

Similarly, the comment says "to ignore YouTube's autoplay" but the flag is used to detect and correct it, not ignore it. Consider rephrasing to "to detect when we initiated a track change (to correct YouTube's autoplay interference)" for consistency with the actual behavior.

Suggested change
/// Flag to track when we initiated a track change (to ignore YouTube's autoplay).
/// Flag to track when we initiated a track change (to correct YouTube's autoplay interference).

Copilot uses AI. Check for mistakes.
Comment on lines +340 to +341
// Get the song we intended to play
if let intendedSong = queue[safe: currentIndex], intendedSong.title != title {
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The comparison uses song titles to detect if YouTube loaded a different track, but song titles may not be unique in a queue. Consider comparing intendedSong.videoId against the actual videoId loaded by YouTube instead. The videoId is available from self.currentTrack?.videoId and should be more reliable for detecting if YouTube loaded a different track.

Suggested change
// Get the song we intended to play
if let intendedSong = queue[safe: currentIndex], intendedSong.title != title {
// Get the song we intended to play and compare using videoId to detect mismatched tracks
if let intendedSong = queue[safe: currentIndex],
let currentVideoId = self.currentTrack?.videoId,
intendedSong.videoId != currentVideoId {

Copilot uses AI. Check for mistakes.
}

@Test("UpdateTrackMetadata corrects YouTube autoplay with Kaset-initiated playback")
func updateTrackMetadataCorrectYouTubeAutoplay() async {
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The test name "updateTrackMetadataCorrectYouTubeAutoplay" is missing a verb. Consider renaming it to "updateTrackMetadataCorrectsYouTubeAutoplay" to follow standard Swift naming conventions where function names start with a verb.

Suggested change
func updateTrackMetadataCorrectYouTubeAutoplay() async {
func updateTrackMetadataCorrectsYouTubeAutoplay() async {

Copilot uses AI. Check for mistakes.
self.state = .loading
self.currentTrack = song

// Mark that we initiated this playback (to ignore YouTube's autoplay override)
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The comment says "to ignore YouTube's autoplay override" but the actual behavior is to detect and correct it, not ignore it. Consider rephrasing to "to detect and correct YouTube's autoplay override" for clarity.

Suggested change
// Mark that we initiated this playback (to ignore YouTube's autoplay override)
// Mark that we initiated this playback (to detect and correct YouTube's autoplay override)

Copilot uses AI. Check for mistakes.
@sozercan sozercan merged commit 5557adc into main Jan 7, 2026
6 checks passed
@sozercan sozercan deleted the shuffle-bug branch January 7, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Shuffle behaves differently when triggered via keyboard

2 participants