Skip to content

Commit

Permalink
#58 - Using the new autoplay option in PlaylistDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-venugopal committed May 31, 2023
1 parent c502ee7 commit db47880
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/ObjectGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ObjectGraph {
// })
// }()

lazy var playlistDelegate: PlaylistDelegateProtocol = PlaylistDelegate(persistentState: persistentState.playlist, playlist,
lazy var playlistDelegate: PlaylistDelegateProtocol = PlaylistDelegate(persistentState: persistentState.playlist, playlist, playbackInfoDelegate,
trackReader, preferences)

var playlistAccessorDelegate: PlaylistAccessorDelegateProtocol {playlistDelegate}
Expand Down
24 changes: 19 additions & 5 deletions Source/Playlist/Delegates/PlaylistDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class PlaylistDelegate: PlaylistDelegateProtocol {
// private var playlist: PlaylistProtocol {playlistsManager.currentPlaylist}
private let playlist: PlaylistProtocol

private let player: PlaybackInfoDelegateProtocol

// private let playlistsManager: PlaylistsManager

private let trackReader: TrackReader
Expand Down Expand Up @@ -59,10 +61,11 @@ class PlaylistDelegate: PlaylistDelegateProtocol {
private lazy var messenger = Messenger(for: self)

init(persistentState: PlaylistPersistentState?, _ playlist: PlaylistProtocol,
_ trackReader: TrackReader, _ preferences: Preferences) {
_ player: PlaybackInfoDelegateProtocol, _ trackReader: TrackReader, _ preferences: Preferences) {

self.playlist = playlist
// self.playlistsManager = playlistsManager
self.player = player
self.trackReader = trackReader

self.persistentState = persistentState
Expand Down Expand Up @@ -466,12 +469,19 @@ class PlaylistDelegate: PlaylistDelegateProtocol {
// Check if any launch parameters were specified
if filesToOpen.isNonEmpty {

// Launch parameters specified, override playlist saved state and add file paths in params to playlist
if playlistPreferences.openWithAddMode == .replace {

NSLog("PREF SET TO REPLACE, CLEARING ...")
clear()
addFiles_async(filesToOpen, AutoplayOptions(autoplay: playbackPreferences.autoplayAfterOpeningTracks), userAction: false)

} else if let tracks = self.persistentState?.tracks?.map({URL(fileURLWithPath: $0)}) {

NSLog("PREF SET TO APPEND, not CLEARING.")
// Need to append files, load playlist saved state
addFiles_async(tracks + filesToOpen, AutoplayOptions(autoplay: playbackPreferences.autoplayAfterOpeningTracks), userAction: false, reorderGroupingPlaylists: true)
}

// Launch parameters specified, override playlist saved state and add file paths in params to playlist
addFiles_async(filesToOpen, AutoplayOptions(autoplay: true), userAction: false)

} else if playlistPreferences.playlistOnStartup == .rememberFromLastAppLaunch,
let tracks = self.persistentState?.tracks?.map({URL(fileURLWithPath: $0)}) {
Expand All @@ -497,8 +507,12 @@ class PlaylistDelegate: PlaylistDelegateProtocol {
clear()
}

let autoplayEnabled = (!notification.isDuplicateNotification) && playbackPreferences.autoplayAfterOpeningTracks
let interruptPlayback = playbackPreferences.autoplayAfterOpeningOption == .always

// When a duplicate notification is sent, don't autoplay ! Otherwise, always autoplay.
addFiles_async(notification.filesToOpen, AutoplayOptions(autoplay: !notification.isDuplicateNotification, autoplayType: .playSpecificTrack))
addFiles_async(notification.filesToOpen, AutoplayOptions(autoplay: autoplayEnabled, autoplayType: .playSpecificTrack,
interruptPlayback: interruptPlayback))
}
}

Expand Down
9 changes: 6 additions & 3 deletions Source/UI/Preferences/Playback/PlaybackPreferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<outlet property="btnAutoplayAfterAddingTracks" destination="qSu-Gq-GD0" id="WFj-tj-Ui4"/>
<outlet property="btnAutoplayAfterAdding_Always" destination="WrV-9w-TDC" id="ISm-HO-4OZ"/>
<outlet property="btnAutoplayAfterAdding_IfNotPlaying" destination="Oaz-io-4ja" id="Ugf-fh-bTf"/>
<outlet property="btnAutoplayAfterOpeningTracks" destination="t4d-Qx-hGu" id="Fa6-IQ-OJN"/>
<outlet property="btnAutoplayAfterOpening_Always" destination="15u-Vf-yRK" id="CGW-xR-PlO"/>
<outlet property="btnAutoplayAfterOpening_IfNotPlaying" destination="GK8-Xg-g0d" id="2ac-Lx-Had"/>
<outlet property="btnAutoplayOnStartup" destination="znf-vd-0EN" id="v3P-VH-2gM"/>
<outlet property="btnInfo_primarySeekLength" destination="L8I-p6-5ZK" id="7hv-qa-tZC"/>
<outlet property="btnInfo_secondarySeekLength" destination="pLg-Zx-z1o" id="O0L-tk-5qQ"/>
Expand Down Expand Up @@ -196,7 +199,7 @@
<font key="font" size="11" name="Play-Regular"/>
</buttonCell>
<connections>
<action selector="autoplayAfterAddingAction:" target="-2" id="Vns-3l-63k"/>
<action selector="autoplayAfterOpeningAction:" target="-2" id="Wnw-EI-yMs"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="15u-Vf-yRK" customClass="DialogCheckRadioButton" customModule="Aural" customModuleProvider="target">
Expand All @@ -207,7 +210,7 @@
<font key="font" size="11" name="Play-Regular"/>
</buttonCell>
<connections>
<action selector="autoplayAfterAddingRadioButtonAction:" target="-2" id="gvd-di-mvL"/>
<action selector="autoplayAfterOpeningRadioButtonAction:" target="-2" id="eC1-57-8Rh"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="GK8-Xg-g0d" customClass="DialogCheckRadioButton" customModule="Aural" customModuleProvider="target">
Expand All @@ -218,7 +221,7 @@
<font key="font" size="11" name="Play-Regular"/>
</buttonCell>
<connections>
<action selector="autoplayAfterAddingRadioButtonAction:" target="-2" id="ckb-5x-XcJ"/>
<action selector="autoplayAfterOpeningRadioButtonAction:" target="-2" id="9Nd-cu-88R"/>
</connections>
</button>
<stepper focusRingType="none" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CC1-0k-NBg" userLabel="Secondary Seek Stepper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class PlaybackPreferencesViewController: NSViewController, PreferencesViewProtoc
@IBAction func autoplayAfterAddingAction(_ sender: Any) {
}

// When the check box for "autoplay after opening tracks" is checked/unchecked, update the enabled state of the 2 option radio buttons
@IBAction func autoplayAfterOpeningAction(_ sender: Any) {
}

@IBAction func autoplayAfterAddingRadioButtonAction(_ sender: Any) {
// Needed for radio button group
}
Expand Down

0 comments on commit db47880

Please sign in to comment.