Media and utilities Swift 6#808
Open
stevenzeck wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR advances Swift 6 / strict concurrency compliance across the media/toolkit utilities and navigator layers by tightening actor isolation (@MainActor) and updating utility primitives and callbacks to be Sendable-safe.
Changes:
- Isolates key navigator/media APIs and related view models to
@MainActor. - Reworks control-flow and cancellation utilities to require
@Sendablecallbacks and usesMutexfor thread-safe state. - Introduces a polling utility (
execute(when:...)via a newPoller) and adds observer-token wrappers for AVPlayer/NotificationCenter observer lifetime management.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| TestApp/Sources/Reader/Common/TTS/TTSViewModel.swift | Marks the view model as @MainActor to satisfy strict concurrency. |
| TestApp/Sources/Reader/Common/Preferences/UserPreferences.swift | Marks preferences view model @MainActor and adjusts Combine callbacks for actor isolation. |
| Sources/Shared/Toolkit/Poller.swift | Adds a dedicated polling implementation and updates execute(when:...) to require @Sendable @MainActor callbacks. |
| Sources/Shared/Toolkit/Media/NowPlayingInfo.swift | Isolates Now Playing manager to @MainActor and adapts throttled updates. |
| Sources/Shared/Toolkit/Media/AudioSession.swift | Moves audio session user protocol + session management onto @MainActor and adjusts APIs for Swift 6. |
| Sources/Shared/Toolkit/ControlFlow.swift | Updates throttle to be @Sendable-friendly and thread-safe via Mutex. |
| Sources/Shared/Toolkit/Cancellable.swift | Makes cancellation primitives Sendable and guards state/callbacks with Mutex. |
| Sources/Shared/Toolkit/Atomic.swift | Removes the legacy Atomic wrapper from ReadiumShared. |
| Sources/Navigator/VisualNavigator.swift | Marks VisualNavigator default implementations as @MainActor. |
| Sources/Navigator/TTS/PublicationSpeechSynthesizer.swift | Isolates synthesizer to @MainActor and updates delegate interactions and teardown. |
| Sources/Navigator/Preferences/Configurable.swift | Marks Configurable as @MainActor to align UI-facing configuration flows with isolation. |
| Sources/Navigator/Navigator.swift | Marks Navigator (and convenience extension) as @MainActor. |
| Sources/Navigator/Audiobook/AudioNavigator.swift | Isolates AudioNavigator to @MainActor, introduces observer token wrappers, and updates callback/sendability to satisfy Swift 6. |
Comments suppressed due to low confidence (1)
Sources/Navigator/Audiobook/AudioNavigator.swift:375
completionis declared@MainActor, but it’s called from aDispatchQueue.main.asyncclosure which is not guaranteed to be on the MainActor executor. This will typically trigger a Swift 6 actor-isolation error unless you explicitly assert/hop onto the MainActor before callingcompletion.
DispatchQueue.main.async {
completion(info)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+45
to
+48
| Task { | ||
| await block() | ||
| isPolling = false | ||
| } |
Comment on lines
+569
to
+576
| deinit { | ||
| // Technically, AVFoundation requires `removeTimeObserver` to be called | ||
| // from the same queue that added the observer (which was `.main`). | ||
| // However, since we cannot easily dispatch to the main actor during deinit | ||
| // without risking an async lifetime leak, we call it here. | ||
| // In practice, `AVPlayer.removeTimeObserver` handles this gracefully off-thread. | ||
| player.removeTimeObserver(observer) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Atomic.swiftand the@Atomicproperty wrapper.Navigator,Configurable,AudioSessionUser,PublicationSpeechSynthesizer, andNowPlayingInfoto@MainActor.@unchecked Sendablewrappers (TimeObserverTokenandNotificationObserverToken) for AVPlayer KVO andNotificationCenter.Cancellableprotocol,CancellableObject, andMediatorCancellableto conform toSendable, usingMutexto secure callbacks.Pollerclass for condition-polling, requiring@Sendableand@MainActorisolation for all callbacks.UserPreferencesViewModelandTTSViewModelto@MainActorand utilizedMainActor.assumeIsolatedwithin Combine callbacks to resolve compilation errors in the TestApp.Public API Breaking Changes
Navigator,Configurable,AudioSessionUser,PublicationSpeechSynthesizer, andNowPlayingInfoare now@MainActorisolated.Atomicclass and@Atomicproperty wrapper removed fromReadiumShared.Cancellable,CancellableObject, andMediatorCancellablenow conform toSendable.AudioSession.end(for:)parameter type changed fromAudioSessionUsertoObjectIdentifier.execute(when:pollingInterval:on::)parameters and return type updated to require@Sendable @MainActor.CancellableObject.init(onCancel:)closure now requires@Sendable.throttle(duration:on::)closure and return type now require@Sendable.Relates to #758.