Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ class AppDelegate: NSObject,
@IBOutlet weak var playSelectedSongMenuItem: NSMenuItem!
@IBOutlet weak var playSelectedSongNextMenuItem: NSMenuItem!
@IBOutlet weak var addSelectedSongToQueueMenuItem: NSMenuItem!

@IBOutlet weak var savePlaylistMenuItem: NSMenuItem!

func applicationDidFinishLaunching(_ aNotification: Notification) {
mediaKeyTap = MediaKeyTap(delegate: self)
mediaKeyTap?.start()

App.store.subscribe(self) {
$0.select {
($0.serverState, $0.playerState, $0.uiState)
($0.serverState, $0.playerState, $0.uiState, $0.playlistState)
}
}


NotificationCenter.default.addObserver(self, selector: #selector(didConnect), name: .didConnect, object: nil)

_ = App.userNotificationsController
_ = App.mediaInfoController
_ = App.playerStateInfoController
Expand Down Expand Up @@ -137,6 +141,27 @@ class AppDelegate: NSObject,
connectMenuItem.isEnabled = !connected
disconnectMenuItem.isEnabled = connected
}

func setPlaylists(state: PlaylistState) {
guard let playlistsMenuItem = NSApplication.shared.mainMenu?.item(withTitle: "Playlists")
else { return }

playlistsMenuItem.submenu?.items.forEach { item in
if item.tag == 1 {
playlistsMenuItem.submenu?.removeItem(item)
}
}

state.playlists.forEach { playlist in
let playlistMenuItem = NSMenuItem(
title: playlist.path,
action: #selector(loadPlaylist),
keyEquivalent: ""
)
playlistMenuItem.tag = 1
playlistsMenuItem.submenu?.addItem(playlistMenuItem)
}
}

func handle(mediaKey: MediaKey, event: KeyEvent) {
switch mediaKey {
Expand All @@ -148,6 +173,17 @@ class AppDelegate: NSObject,
App.mpdClient.prevTrack()
}
}

@objc func didConnect() {
App.mpdClient.fetchPlaylists()
}

@objc func loadPlaylist(_ sender: NSMenuItem) {
let name = sender.title

App.mpdClient.clearQueue()
App.mpdClient.loadQueueFromPlaylist(name: name)
}

@IBAction func connectMenuAction(_ sender: NSMenuItem) {
App.mpdServerController.connect()
Expand Down Expand Up @@ -222,7 +258,10 @@ class AppDelegate: NSObject,

extension AppDelegate: StoreSubscriber {
typealias StoreSubscriberStateType = (
serverState: ServerState, playerState: PlayerState, uiState: UIState
serverState: ServerState,
playerState: PlayerState,
uiState: UIState,
playlistState: PlaylistState
)

func newState(state: StoreSubscriberStateType) {
Expand All @@ -231,5 +270,6 @@ extension AppDelegate: StoreSubscriber {
setSongMenuItemsState(selectedSong: state.uiState.selectedSong)
setControlsMenuItemsState(state: state.playerState)
setConnectMenuItemsState(connected: state.serverState.connected)
setPlaylists(state: state.playlistState)
}
}
15 changes: 7 additions & 8 deletions Mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<capability name="System colors introduced in macOS 10.14" minToolsVersion="10.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -620,7 +621,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
Expand Down Expand Up @@ -772,14 +773,13 @@
<subviews>
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" selectionHighlightStyle="sourceList" multipleSelection="NO" autosaveColumns="NO" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="16" outlineTableColumn="0Co-uF-CCB" id="jEJ-jg-fll">
<rect key="frame" x="0.0" y="0.0" width="450" height="300"/>
<autoresizingMask key="autoresizingMask"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="songTitleColumn" width="222" minWidth="128" maxWidth="1000" id="0Co-uF-CCB">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" title="Title">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
Expand Down Expand Up @@ -809,14 +809,14 @@
<rect key="frame" x="1" y="20" width="222" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="o8i-cz-hIP">
<imageView ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="o8i-cz-hIP">
<rect key="frame" x="3" y="0.0" width="17" height="17"/>
<constraints>
<constraint firstAttribute="width" constant="17" id="UFf-Fg-9Qg"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" imageScaling="proportionallyDown" image="playButton" id="ckK-gW-Vhx"/>
</imageView>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="i0h-bn-auJ">
<textField verticalHuggingPriority="750" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="i0h-bn-auJ">
<rect key="frame" x="25" y="0.0" width="197" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="ei8-1e-ErK">
<font key="font" metaFont="system"/>
Expand All @@ -842,7 +842,6 @@
</tableColumn>
<tableColumn identifier="songArtistColumn" width="222" minWidth="128" maxWidth="1000" id="SPM-QP-DX8">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Artist">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableHeaderCell>
Expand Down
26 changes: 26 additions & 0 deletions Mac/Components/Playlists/SavePlaylistViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// SavePlaylistViewController.swift
// Persephone
//
// Created by Dan Barber on 2020-4-11.
// Copyright © 2020 Dan Barber. All rights reserved.
//

import AppKit

class SavePlaylistViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func saveButtonAction(_ sender: Any) {
App.mpdClient.saveQueueToPlaylist(name: playlistName.stringValue)
self.dismiss(sender)
}

@IBAction func cancelButtonAction(_ sender: Any) {
self.dismiss(sender)
}

@IBOutlet var playlistName: NSTextFieldCell!
}
Loading