Bug Fix: Playlist Loader now correctly sorts items

Playlist Loader was sorting only the non-container tracks, and not the
final track list. Move the sort operation to the end of the processing.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-02-27 00:56:58 -08:00
parent bf5e6d85a3
commit d5ca037943

View file

@ -418,21 +418,13 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
DLog(@"Expanded urls: %@", expandedURLs); DLog(@"Expanded urls: %@", expandedURLs);
NSArray *sortedURLs;
if(sort == YES) {
sortedURLs = [expandedURLs sortedArrayUsingSelector:@selector(finderCompare:)];
// sortedURLs = [expandedURLs sortedArrayUsingSelector:@selector(compareTrackNumbers:)];
} else {
sortedURLs = expandedURLs;
}
[self beginProgressJob:NSLocalizedString(@"ProgressSubActionLoaderFilteringContainerFiles", @"") percentOfTotal:20.0]; [self beginProgressJob:NSLocalizedString(@"ProgressSubActionLoaderFilteringContainerFiles", @"") percentOfTotal:20.0];
progressstep = [sortedURLs count] ? 100.0 / (double)([sortedURLs count]) : 0; progressstep = [expandedURLs count] ? 100.0 / (double)([expandedURLs count]) : 0;
id<SentrySpan> containerTask = [mainTask startChildWithOperation:@"Process paths for containers"]; id<SentrySpan> containerTask = [mainTask startChildWithOperation:@"Process paths for containers"];
for(url in sortedURLs) { for(url in expandedURLs) {
// Container vs non-container url // Container vs non-container url
id<SentrySpan> pathTask = nil; id<SentrySpan> pathTask = nil;
@try { @try {
@ -637,15 +629,22 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
return @[]; return @[];
} }
NSArray *sortedURLs;
if(sort == YES) {
sortedURLs = [validURLs sortedArrayUsingSelector:@selector(finderCompare:)];
} else {
sortedURLs = validURLs;
}
[self beginProgressJob:NSLocalizedString(@"ProgressSubActionLoaderAddingEntries", @"") percentOfTotal:20.0]; [self beginProgressJob:NSLocalizedString(@"ProgressSubActionLoaderAddingEntries", @"") percentOfTotal:20.0];
progressstep = 100.0 / (double)(count); progressstep = 100.0 / (double)(count);
__block id<SentrySpan> addTask = [mainTask startChildWithOperation:@"Add entries to playlist" description:[NSString stringWithFormat:@"Adding %lu entries to the playlist", [validURLs count]]]; __block id<SentrySpan> addTask = [mainTask startChildWithOperation:@"Add entries to playlist" description:[NSString stringWithFormat:@"Adding %lu entries to the playlist", [sortedURLs count]]];
NSInteger i = 0; NSInteger i = 0;
__block NSMutableArray *entries = [NSMutableArray arrayWithCapacity:count]; __block NSMutableArray *entries = [NSMutableArray arrayWithCapacity:count];
for(NSURL *url in validURLs) { for(NSURL *url in sortedURLs) {
__block PlaylistEntry *pe; __block PlaylistEntry *pe;
dispatch_sync_reentrant(dispatch_get_main_queue(), ^{ dispatch_sync_reentrant(dispatch_get_main_queue(), ^{