From 9e2ae248d477e4124432a04d43d74ad72220105f Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 1 Jul 2019 16:34:24 +0200 Subject: [PATCH] Swift 4 - part 2 --- Muse.xcodeproj/project.pbxproj | 8 +++++-- Muse/Resources/Base.lproj/Main.storyboard | 8 +++---- Muse/Sources/Extensions/Imageable+Tint.swift | 2 +- .../Extensions/NSWindow+Extensions.swift | 2 +- .../Interface/NSCustomizableButton.swift | 7 +++--- Muse/Sources/Interface/SliderCell.swift | 9 ++++---- .../AccountsPreferencesViewController.swift | 4 ++-- .../GeneralPreferencesViewController.swift | 4 ++-- Muse/Sources/Views/WindowController.swift | 22 +++++++++---------- 9 files changed, 35 insertions(+), 31 deletions(-) diff --git a/Muse.xcodeproj/project.pbxproj b/Muse.xcodeproj/project.pbxproj index 0b8d9f4..e59f94b 100644 --- a/Muse.xcodeproj/project.pbxproj +++ b/Muse.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -178,6 +178,7 @@ 0C8B16781F82A31C0009BE7B /* NSBezierPath+CGPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBezierPath+CGPath.swift"; sourceTree = ""; }; 0C8E3BC01E3CC43900C8EBD1 /* iTunesHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = iTunesHelper.swift; sourceTree = ""; }; 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 = ""; }; 0C9A60BD1DE6071F0051CDC6 /* Song.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Song.swift; sourceTree = ""; }; 0C9A60C61DE75DCC0051CDC6 /* Imageable+Download.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Imageable+Download.swift"; sourceTree = ""; }; 0C9A60C81DE76EBB0051CDC6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -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 */, @@ -482,6 +483,7 @@ 7E9AA20CAC9772D1BED5DCE5 /* Frameworks */ = { isa = PBXGroup; children = ( + 0C999A3822CA513700E9637A /* DFRFoundation.framework */, 0CAB4ED121064F8600CC118A /* iTunesLibrary.framework */, 0CFAE22021597E3F0010215E /* iTunesLibrary.framework */, 0C999A3522C29BB400E9637A /* iTunesLibrary.framework */, @@ -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; }; @@ -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; }; diff --git a/Muse/Resources/Base.lproj/Main.storyboard b/Muse/Resources/Base.lproj/Main.storyboard index a730f74..c7114b3 100644 --- a/Muse/Resources/Base.lproj/Main.storyboard +++ b/Muse/Resources/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -365,7 +365,7 @@ - + @@ -376,7 +376,7 @@ - + diff --git a/Muse/Sources/Extensions/Imageable+Tint.swift b/Muse/Sources/Extensions/Imageable+Tint.swift index 03a2a46..980e89f 100644 --- a/Muse/Sources/Extensions/Imageable+Tint.swift +++ b/Muse/Sources/Extensions/Imageable+Tint.swift @@ -45,7 +45,7 @@ extension NSImage { // Then apply the tint color.set() - NSRectFillUsingOperation(imageRect, .sourceAtop) + imageRect.fill(using: .sourceAtop) tinted.unlockFocus() diff --git a/Muse/Sources/Extensions/NSWindow+Extensions.swift b/Muse/Sources/Extensions/NSWindow+Extensions.swift index cbefde8..b2a94a0 100644 --- a/Muse/Sources/Extensions/NSWindow+Extensions.swift +++ b/Muse/Sources/Extensions/NSWindow+Extensions.swift @@ -111,7 +111,7 @@ extension NSWindow { context.allowsImplicitAnimation = true self.setFrame(frame, display: true) - }, completionHandler: { _ in animationCompletionHandler() }) + }, completionHandler: { animationCompletionHandler() }) } } diff --git a/Muse/Sources/Interface/NSCustomizableButton.swift b/Muse/Sources/Interface/NSCustomizableButton.swift index 793739a..8fb624b 100644 --- a/Muse/Sources/Interface/NSCustomizableButton.swift +++ b/Muse/Sources/Interface/NSCustomizableButton.swift @@ -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 - } - } diff --git a/Muse/Sources/Interface/SliderCell.swift b/Muse/Sources/Interface/SliderCell.swift index c8eab6d..34db097 100644 --- a/Muse/Sources/Interface/SliderCell.swift +++ b/Muse/Sources/Interface/SliderCell.swift @@ -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] } } diff --git a/Muse/Sources/Preferences/AccountsPreferencesViewController.swift b/Muse/Sources/Preferences/AccountsPreferencesViewController.swift index 11d85ef..4212885 100644 --- a/Muse/Sources/Preferences/AccountsPreferencesViewController.swift +++ b/Muse/Sources/Preferences/AccountsPreferencesViewController.swift @@ -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 diff --git a/Muse/Sources/Preferences/GeneralPreferencesViewController.swift b/Muse/Sources/Preferences/GeneralPreferencesViewController.swift index a0a284d..b582ede 100644 --- a/Muse/Sources/Preferences/GeneralPreferencesViewController.swift +++ b/Muse/Sources/Preferences/GeneralPreferencesViewController.swift @@ -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 diff --git a/Muse/Sources/Views/WindowController.swift b/Muse/Sources/Views/WindowController.swift index 8966b40..b3b42e8 100644 --- a/Muse/Sources/Views/WindowController.swift +++ b/Muse/Sources/Views/WindowController.swift @@ -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() @@ -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 @@ -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 { @@ -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 { @@ -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 @@ -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 ? @@ -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, @@ -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) @@ -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()