diff --git a/packages/mobile/ios/Podfile b/packages/mobile/ios/Podfile index c5d685c23e7..fa8f6f35214 100644 --- a/packages/mobile/ios/Podfile +++ b/packages/mobile/ios/Podfile @@ -140,6 +140,24 @@ target 'AudiusReactNative' do end end + # SwiftAudioEx 1.x only shifts the current index for an insert in front + # of the current item when the queue already has more than one item. With + # a single item, inserting at 0 leaves the index one slot early, so the + # player replays the current track instead of advancing. Fixed upstream + # on main but not released. Fail if the line changes so an update can't + # silently drop the patch. + queue_manager = File.join(__dir__, 'Pods/SwiftAudioEx/Sources/SwiftAudioEx/QueueManager.swift') + buggy_line = 'if (self.items.count > 1 && currentIndex >= index) {' + fixed_line = 'if (self.items.count > 0 && currentIndex >= index) {' + text = File.read(queue_manager) + if text.include?(buggy_line) + File.chmod(0644, queue_manager) + File.write(queue_manager, text.sub(buggy_line, fixed_line)) + Pod::UI.puts "Patched SwiftAudioEx QueueManager.swift: shift current index when inserting into a one-item queue".green + elsif !text.include?(fixed_line) + raise "SwiftAudioEx QueueManager.swift no longer contains '#{buggy_line}'. Check whether the insert index fix is still needed and update the Podfile patch." + end + end end