Skip to content

Commit

Permalink
Swift 4 - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xzzz9097 committed Jul 2, 2019
1 parent aaaf9ed commit 9e2ae24
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 31 deletions.
8 changes: 6 additions & 2 deletions Muse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
0C0980571E2830E500FF9FE0 /* NSTouch+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C0980561E2830E500FF9FE0 /* NSTouch+Extensions.swift */; };
0C1B1F5F1F17C065009D4588 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C3382CD1F14F372000D74F9 /* DFRFoundation.framework */; };
0C1F20EC1F2B21E50055ACAC /* NSCustomizableButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C1F20EB1F2B21E50055ACAC /* NSCustomizableButton.swift */; };
0C1F20F41F2B9F3C0055ACAC /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C1F20F31F2B9F3C0055ACAC /* Preferences.swift */; };
0C21EBC01E12F9C700E9268C /* NSWindow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C21EBBF1E12F9C700E9268C /* NSWindow+Extensions.swift */; };
Expand Down Expand Up @@ -41,6 +40,7 @@
0C8B16791F82A31C0009BE7B /* NSBezierPath+CGPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8B16781F82A31C0009BE7B /* NSBezierPath+CGPath.swift */; };
0C8E3BC11E3CC43900C8EBD1 /* iTunesHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C8E3BC01E3CC43900C8EBD1 /* iTunesHelper.swift */; };
0C999A3722C29FEC00E9637A /* iTunesLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C999A3522C29BB400E9637A /* iTunesLibrary.framework */; };
0C999A3922CA513700E9637A /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C999A3822CA513700E9637A /* DFRFoundation.framework */; };
0C9A60BE1DE6071F0051CDC6 /* Song.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C9A60BD1DE6071F0051CDC6 /* Song.swift */; };
0C9A60C71DE75DCC0051CDC6 /* Imageable+Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C9A60C61DE75DCC0051CDC6 /* Imageable+Download.swift */; };
0C9A60D91DE79B6D0051CDC6 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0C9A60D81DE79B6D0051CDC6 /* Carbon.framework */; };
Expand Down Expand Up @@ -178,6 +178,7 @@
0C8B16781F82A31C0009BE7B /* NSBezierPath+CGPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBezierPath+CGPath.swift"; sourceTree = "<group>"; };
0C8E3BC01E3CC43900C8EBD1 /* iTunesHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = iTunesHelper.swift; sourceTree = "<group>"; };
0C999A3522C29BB400E9637A /* iTunesLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = iTunesLibrary.framework; path = System/Library/Frameworks/iTunesLibrary.framework; sourceTree = SDKROOT; };
0C999A3822CA513700E9637A /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
0C9A60BD1DE6071F0051CDC6 /* Song.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Song.swift; sourceTree = "<group>"; };
0C9A60C61DE75DCC0051CDC6 /* Imageable+Download.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Imageable+Download.swift"; sourceTree = "<group>"; };
0C9A60C81DE76EBB0051CDC6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -231,8 +232,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0C999A3922CA513700E9637A /* DFRFoundation.framework in Frameworks */,
0C999A3722C29FEC00E9637A /* iTunesLibrary.framework in Frameworks */,
0C1B1F5F1F17C065009D4588 /* DFRFoundation.framework in Frameworks */,
0CFA0FDD1DF37059007DA6AE /* MediaPlayer.framework in Frameworks */,
0C9A60D91DE79B6D0051CDC6 /* Carbon.framework in Frameworks */,
FD9F763CA855EFBC8846FCDC /* Pods_Muse.framework in Frameworks */,
Expand Down Expand Up @@ -482,6 +483,7 @@
7E9AA20CAC9772D1BED5DCE5 /* Frameworks */ = {
isa = PBXGroup;
children = (
0C999A3822CA513700E9637A /* DFRFoundation.framework */,
0CAB4ED121064F8600CC118A /* iTunesLibrary.framework */,
0CFAE22021597E3F0010215E /* iTunesLibrary.framework */,
0C999A3522C29BB400E9637A /* iTunesLibrary.framework */,
Expand Down Expand Up @@ -957,6 +959,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Muse/Resources/Muse-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SYSTEM_FRAMEWORK_SEARCH_PATHS = "$(inherited) $(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
};
name = Debug;
};
Expand All @@ -978,6 +981,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Muse/Resources/Muse-Bridging-Header.h";
SWIFT_VERSION = 4.0;
SYSTEM_FRAMEWORK_SEARCH_PATHS = "$(inherited) $(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
};
name = Release;
};
Expand Down
8 changes: 4 additions & 4 deletions Muse/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -365,7 +365,7 @@
<constraint firstAttribute="width" constant="10" id="Y39-cG-Bhb"/>
<constraint firstAttribute="height" constant="10" id="e4p-JJ-MmC"/>
</constraints>
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" alignment="center" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" id="AJS-0n-bS0">
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" alignment="center" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" id="AJS-0n-bS0" customClass="ButtonCell" customModule="Muse" customModuleProvider="target">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system" size="10"/>
</buttonCell>
Expand All @@ -376,7 +376,7 @@
<constraint firstAttribute="width" constant="10" id="kDy-jc-GW6"/>
<constraint firstAttribute="height" constant="10" id="wII-KS-CqT"/>
</constraints>
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" alignment="center" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" id="eMb-Na-FtX">
<buttonCell key="cell" type="smallSquare" bezelStyle="smallSquare" alignment="center" lineBreakMode="truncatingTail" state="on" imageScaling="proportionallyDown" inset="2" id="eMb-Na-FtX" customClass="ButtonCell" customModule="Muse" customModuleProvider="target">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system" size="10"/>
</buttonCell>
Expand Down
2 changes: 1 addition & 1 deletion Muse/Sources/Extensions/Imageable+Tint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension NSImage {

// Then apply the tint
color.set()
NSRectFillUsingOperation(imageRect, .sourceAtop)
imageRect.fill(using: .sourceAtop)

tinted.unlockFocus()

Expand Down
2 changes: 1 addition & 1 deletion Muse/Sources/Extensions/NSWindow+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension NSWindow {
context.allowsImplicitAnimation = true

self.setFrame(frame, display: true)
}, completionHandler: { _ in animationCompletionHandler() })
}, completionHandler: { animationCompletionHandler() })
}

}
7 changes: 3 additions & 4 deletions Muse/Sources/Interface/NSCustomizableButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ class NSCustomizableButton: NSButton, NSMouseHoverableView {
target: target,
action: action)

// Use custom button cell
self.cell = ButtonCell()

self.hasRoundedLeadingImage = hasRoundedLeadingImage
}

override class func cellClass() -> AnyClass? {
return ButtonCell.self
}

}
9 changes: 5 additions & 4 deletions Muse/Sources/Interface/SliderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,15 @@ class SliderCell: NSSliderCell {
/**
Font attributes for the info text
*/
func infoFontAttributes(for rect: NSRect) -> [String: Any] {
func infoFontAttributes(for rect: NSRect) -> [NSAttributedStringKey: Any] {
let isLeftOfKnob = shouldInfoBeLeft(of: rect)

paraghraphStyle.alignment = isLeftOfKnob ? .left : .right

return [NSAttributedStringKey.font.rawValue: NSFont.systemFont(ofSize: infoFontSize),
NSAttributedStringKey.foregroundColor.rawValue: isLeftOfKnob ? infoFontLeftColor : infoFontRightColor,
NSAttributedStringKey.paragraphStyle.rawValue: paraghraphStyle]

return [.font: NSFont.systemFont(ofSize: infoFontSize),
.foregroundColor: isLeftOfKnob ? infoFontLeftColor : infoFontRightColor,
.paragraphStyle: paraghraphStyle]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import MASPreferences

class AccountsPreferencesViewController: NSViewController, MASPreferencesViewController {

override var nibName: String? {
return "AccountsPreferencesView"
override var nibName: NSNib.Name? {
return NSNib.Name(rawValue: "AccountsPreferencesView")
}

// MARK: Outlets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import MASPreferences

class GeneralPreferencesViewController: NSViewController, MASPreferencesViewController {

override var nibName: String? {
return "GeneralPreferencesView"
override var nibName: NSNib.Name? {
return NSNib.Name(rawValue: "GeneralPreferencesView")
}

// MARK: MASPreferencesViewController
Expand Down
22 changes: 11 additions & 11 deletions Muse/Sources/Views/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
updateSoundPopoverButton(for: helper.volume)
}

func songArtworkTitleButtonClicked(_ sender: NSButton) {
@objc func songArtworkTitleButtonClicked(_ sender: NSButton) {
// Jump to player when the artwork on the TouchBar is tapped
showPlayer()
}

func likeButtonClicked(_ sender: NSButton) {
@objc func likeButtonClicked(_ sender: NSButton) {
// Reverse like on current track if supported
if var helper = helper as? LikablePlayerHelper {
helper.toggleLiked()
Expand Down Expand Up @@ -342,7 +342,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
object: nil)
}

func hotkeyAction() {
@objc func hotkeyAction() {
if let window = self.window {
if didPresentAsSystemModal {
// Dismiss system modal bar before opening the window
Expand Down Expand Up @@ -537,7 +537,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
return recognizer
}

func controlStripButtonPressureGestureHandler(_ sender: NSGestureRecognizer?) {
@objc func controlStripButtonPressureGestureHandler(_ sender: NSGestureRecognizer?) {
guard let recognizer = sender else { return }

switch recognizer.state {
Expand All @@ -553,7 +553,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
}
}

func controlStripButtonPanGestureHandler(_ sender: NSGestureRecognizer?) {
@objc func controlStripButtonPanGestureHandler(_ sender: NSGestureRecognizer?) {
guard let recognizer = sender as? NSPanGestureRecognizer else { return }

switch recognizer.state {
Expand Down Expand Up @@ -768,7 +768,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
Recognizes pan (aka touch drag) gestures on the song artwork+title button.
We use this to toggle song information on the button
*/
var songArtworkTitleButtonPanGestureRecognizer: NSGestureRecognizer {
@objc var songArtworkTitleButtonPanGestureRecognizer: NSGestureRecognizer {
let recognizer = NSPanGestureRecognizer()

recognizer.target = self
Expand All @@ -779,7 +779,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
return recognizer
}

func songArtworkTitleButtonPanGestureHandler(_ recognizer: NSPanGestureRecognizer) {
@objc func songArtworkTitleButtonPanGestureHandler(_ recognizer: NSPanGestureRecognizer) {
if case .began = recognizer.state {
songArtworkTitleButton?.title =
recognizer.translation(in: songArtworkTitleButton).x > 0 ?
Expand Down Expand Up @@ -843,7 +843,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
/**
Catches URLs with specific prefix (@objc "muse://")
*/
func handleURLEvent(event: NSAppleEventDescriptor,
@objc func handleURLEvent(event: NSAppleEventDescriptor,
replyEvent: NSAppleEventDescriptor) {
if let urlDescriptor = event.paramDescriptor(forKeyword: keyDirectObject),
let urlString = urlDescriptor.stringValue,
Expand Down Expand Up @@ -871,7 +871,7 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {

func initWakeNotificationWatcher() {
// Attach the NotificationObserver for system wake notification
NSWorkspace.shared().notificationCenter.addObserver(forName: .NSWorkspaceDidWake,
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification,
object: nil,
queue: nil,
using: hookWakeNotification)
Expand Down Expand Up @@ -1078,10 +1078,10 @@ class WindowController: NSWindowController, NSWindowDelegate, SliderDelegate {
// And the View's slider
onViewController { controller in
controller.updateSongProgressSlider(with: position / self.song.duration)
@objc }
}
}

func syncSongProgressSlider() {
@objc func syncSongProgressSlider() {
guard helper.playerState != .stopped else {
// Reset song data if player is stopped
resetSong()
Expand Down

0 comments on commit 9e2ae24

Please sign in to comment.