1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Move some things into extensions

This commit is contained in:
Daniel Barber 2019-02-19 19:34:08 -05:00
parent 8749be7544
commit 7d390f45c6
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
6 changed files with 51 additions and 24 deletions

View File

@ -22,6 +22,8 @@
E41B22C021FB6BBA00D544F6 /* libmpdclient.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; settings = {ATTRIBUTES = (Required, ); }; };
E41B22C121FB6C3300D544F6 /* libmpdclient.2.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = E41B22BF21FB6BBA00D544F6 /* libmpdclient.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
E41B22C621FB932700D544F6 /* MPDClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E41B22C521FB932700D544F6 /* MPDClient.swift */; };
E435E3E2221CD4E200184CFC /* NSFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = E435E3E1221CD4E200184CFC /* NSFont.swift */; };
E435E3E4221CD75D00184CFC /* NSImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E435E3E3221CD75D00184CFC /* NSImage.swift */; };
E465049A21E94DF500A70F4C /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E465049921E94DF500A70F4C /* WindowController.swift */; };
E4928E0B2218D62A001D4BEA /* CGColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4928E0A2218D62A001D4BEA /* CGColor.swift */; };
E4A642DA22090CBE00067D21 /* Status.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4A642D922090CBE00067D21 /* Status.swift */; };
@ -122,6 +124,8 @@
E41B22E921FB966C00D544F6 /* capabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = capabilities.h; sourceTree = "<group>"; };
E41B22EA21FB966C00D544F6 /* queue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = queue.h; sourceTree = "<group>"; };
E41B22EB21FB966C00D544F6 /* playlist.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = playlist.h; sourceTree = "<group>"; };
E435E3E1221CD4E200184CFC /* NSFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSFont.swift; sourceTree = "<group>"; };
E435E3E3221CD75D00184CFC /* NSImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImage.swift; sourceTree = "<group>"; };
E465049921E94DF500A70F4C /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
E4928E0A2218D62A001D4BEA /* CGColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGColor.swift; sourceTree = "<group>"; };
E4A642D922090CBE00067D21 /* Status.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Status.swift; sourceTree = "<group>"; };
@ -222,6 +226,8 @@
E4928E0A2218D62A001D4BEA /* CGColor.swift */,
E408D3B5220DD8970006D9BE /* Notification.swift */,
E408D3B8220DE98F0006D9BE /* NSUserInterfaceItemIdentifier.swift */,
E435E3E1221CD4E200184CFC /* NSFont.swift */,
E435E3E3221CD75D00184CFC /* NSImage.swift */,
);
path = Extensions;
sourceTree = "<group>";
@ -516,6 +522,8 @@
E408D3BE220E03EE0006D9BE /* RawRepresentable.swift in Sources */,
E4E8CC922204F4B80024217A /* QueueViewController.swift in Sources */,
E4EB237B220F7CF1008C70C0 /* Album.swift in Sources */,
E435E3E4221CD75D00184CFC /* NSImage.swift in Sources */,
E435E3E2221CD4E200184CFC /* NSFont.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -14,12 +14,6 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
var queueIcon: NSImage? = nil
let systemFontRegular = NSFont.systemFont(ofSize: 13, weight: .regular)
let systemFontBold = NSFont.systemFont(ofSize: 13, weight: .bold)
let playIcon = NSImage(named: "playButton")
let pauseIcon = NSImage(named: "pauseButton")
struct SongItem {
var song: MPDClient.Song
var queuePos: Int
@ -98,9 +92,9 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
func setQueueIcon(_ state: MPDClient.Status.State) {
switch state {
case .playing:
self.queueIcon = playIcon
self.queueIcon = .playIcon
case .paused:
self.queueIcon = pauseIcon
self.queueIcon = .pauseIcon
default:
self.queueIcon = nil
}
@ -112,7 +106,7 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
let oldSongTitleCell = oldSongRow.view(atColumn: 0) as? NSTableCellView
else { return }
setRowFont(rowView: oldSongRow, font: systemFontRegular)
setRowFont(rowView: oldSongRow, font: .systemFontRegular)
oldSongTitleCell.imageView?.image = nil
}
@ -120,7 +114,7 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
let newSongTitleCell = songRow.view(atColumn: 0) as? NSTableCellView
else { return }
setRowFont(rowView: songRow, font: systemFontBold)
setRowFont(rowView: songRow, font: .systemFontBold)
newSongTitleCell.imageView?.image = self.queueIcon
}

View File

@ -9,8 +9,6 @@
import Cocoa
class WindowController: NSWindowController {
let timerFont = NSFont.monospacedDigitSystemFont(ofSize: 13, weight: .regular)
enum TransportAction: Int {
case prevTrack, playPause, stop, nextTrack
}
@ -20,9 +18,6 @@ class WindowController: NSWindowController {
var elapsedTimeMs: UInt?
var trackTimer: Timer?
let playIcon = NSImage(named: "playButton")
let pauseIcon = NSImage(named: "pauseButton")
override func windowDidLoad() {
super.windowDidLoad()
window?.titleVisibility = .hidden
@ -41,8 +36,8 @@ class WindowController: NSWindowController {
object: AppDelegate.mpdClient
)
trackProgress.font = timerFont
trackRemaining.font = timerFont
trackProgress.font = .timerFont
trackRemaining.font = .timerFont
}
@objc func stateChanged(_ notification: Notification) {
@ -63,9 +58,9 @@ class WindowController: NSWindowController {
transportControls.setEnabled(state.isOneOf([.playing, .paused]), forSegment: 3)
if state.isOneOf([.paused, .stopped, .unknown]) {
transportControls.setImage(playIcon, forSegment: 1)
transportControls.setImage(.playIcon, forSegment: 1)
} else {
transportControls.setImage(pauseIcon, forSegment: 1)
transportControls.setImage(.pauseIcon, forSegment: 1)
}
}

View File

@ -0,0 +1,16 @@
//
// NSFont.swift
// Persephone
//
// Created by Daniel Barber on 2019/2/19.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Cocoa
extension NSFont {
static let systemFontRegular = systemFont(ofSize: 13, weight: .regular)
static let systemFontBold = systemFont(ofSize: 13, weight: .bold)
static let timerFont = monospacedDigitSystemFont(ofSize: 13, weight: .regular)
}

View File

@ -0,0 +1,14 @@
//
// NSImage.swift
// Persephone
//
// Created by Daniel Barber on 2019/2/19.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Cocoa
extension NSImage {
static let playIcon = NSImage(named: "playButton")
static let pauseIcon = NSImage(named: "pauseButton")
}

View File

@ -9,11 +9,11 @@
import Foundation
extension Notification {
static let stateChanged = Notification.Name("MPDClientStateChanged")
static let timeChanged = Notification.Name("MPDClientTimeChanged")
static let queueChanged = Notification.Name("MPDClientQueueChanged")
static let queuePosChanged = Notification.Name("MPDClientQueuePosChanged")
static let loadedAlbums = Notification.Name("MPDClientLoadedAlbums")
static let stateChanged = Name("MPDClientStateChanged")
static let timeChanged = Name("MPDClientTimeChanged")
static let queueChanged = Name("MPDClientQueueChanged")
static let queuePosChanged = Name("MPDClientQueuePosChanged")
static let loadedAlbums = Name("MPDClientLoadedAlbums")
static let stateKey = "state"
static let queueKey = "queue"