chore: add import Foundation and clarifying comments to context menu code

feat/music-streaming
Laurent 1 month ago
parent bd97d060a0
commit c04533d0a8
  1. 2
      Music/ContentView.swift
  2. 7
      Music/Models/TrackContextMenuConfig.swift

@ -366,6 +366,8 @@ struct ContentView: View {
onAddToLastPlaylist: { track in
try? playlist.addTrackToLastUsedPlaylist(track)
},
// Outer nil hides the "Remove from Playlist" menu item when not in a playlist view.
// Inner re-check defends against the playlist being deselected between menu display and action.
onRemoveFromPlaylist: playlist.selectedPlaylist != nil ? { track in
if let selected = playlist.selectedPlaylist {
try? playlist.removeTrack(track, from: selected)

@ -1,8 +1,13 @@
import Foundation
// `nonisolated` opts this struct out of the project-wide `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`
// setting (same reason as Track, Playlist, etc.). `Sendable` is omitted because the closure
// properties are not Sendable the config is created and consumed exclusively on @MainActor.
nonisolated struct TrackContextMenuConfig {
let playlists: [Playlist]
let lastUsedPlaylistName: String?
let selectedPlaylist: Playlist?
let onAddToPlaylist: (Track, Playlist) -> Void
let onAddToLastPlaylist: ((Track) -> Void)?
let onAddToLastPlaylist: ((Track) -> Void)? // nil hides the "Add to [last]" button; always non-nil in practice
let onRemoveFromPlaylist: ((Track) -> Void)?
}

Loading…
Cancel
Save