refactor: migrate to @Observable and fix VolumeController initialization#26
Merged
refactor: migrate to @Observable and fix VolumeController initialization#26
Conversation
MPVolumeView needs to be in the view hierarchy and laid out before its internal slider subview is accessible. Previously, volume adjustments could fail silently if called before the view was ready. - Add explicit initialize() method called from ShuffledApp.init() - Force layout after adding to hierarchy so subviews are populated - Consolidate increase/decrease into shared adjustVolume(by:) helper - Keep assertionFailure for catching issues during development Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## @observable Migration - Migrate 6 classes from ObservableObject to @observable macro: - ShufflePlayer, AppViewModel, LibraryBrowserViewModel - SongUndoManager, ArtworkLoader, AlbumArtColorExtractor - Replace @StateObject/@ObservedObject with @State/var in views - Use @bindable for bindings from @observable objects - Use @ObservationIgnored for non-observed internal state ## Environment-Based Settings - Create AppSettings (@observable) to centralize app settings - Add Environment keys for appSettings and shufflePlayer - Replace NotificationCenter-based communication with direct observation - Settings views now modify appSettings directly ## VolumeController Fix - Move initialization from App.init() to MainView.onAppear - Remove assertionFailure that caused crash when no window available - Add lazy initialization fallback in adjustVolume() ## Performance Fix - Make ShufflePlayer's playback observation Task @mainactor - Simplify AppViewModel's scrobble observation to avoid actor-hopping - Fixes multi-second lag on play/pause UI updates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
ObservableObjectto@ObservablemacroAppSettingsfor environment-based settings managementChanges
@observable Migration
reshuffleWithNewAlgorithm(_:)withObservationTrackingreplacement for scrobble forwardingEnvironment-Based Settings
AppSettingsclass centralizes shuffle algorithm and sort optionappSettingsdirectly (no NotificationCenter)MainViewusesonChangeto forward settings changes to playerView Updates
@StateObject→@Statefor owned@Observableclasses@ObservedObject→ plainvarfor injected classes@Bindablefor bindings,@Environmentfor injected stateBug Fixes
onAppear, remove crash-causingassertionFailure@MainActorto avoid actor-hopping delaysTest plan
🤖 Generated with Claude Code