From 6f19b29af37f4fb36633c4357552a3b212bb92c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Per=C3=A4l=C3=A4?= Date: Wed, 28 Mar 2018 20:11:44 +0300 Subject: [PATCH] Fix style issues and increase max line length to 120 characters --- .swiftlint.yml | 3 ++- kmbmpdc/AppDelegate.swift | 15 +++++---------- kmbmpdc/Constants.swift | 4 ++-- kmbmpdc/Controller.swift | 28 +++++++++++++++------------- kmbmpdc/MPDClient.swift | 19 +++++++------------ kmbmpdc/Search.swift | 3 +-- 6 files changed, 32 insertions(+), 40 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 577a845..a72de69 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,7 +4,8 @@ disabled_rules: opt_in_rules: - overridden_super_call - conditional_returns_on_newline + - operator_usage_whitespace included: - kmbmpdc -line_length: 110 +line_length: 120 diff --git a/kmbmpdc/AppDelegate.swift b/kmbmpdc/AppDelegate.swift index d9c9324..7abc726 100644 --- a/kmbmpdc/AppDelegate.swift +++ b/kmbmpdc/AppDelegate.swift @@ -2,8 +2,7 @@ import Cocoa import MediaKeyTap @NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate, - NSUserNotificationCenterDelegate, MediaKeyTapDelegate { +class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDelegate, MediaKeyTapDelegate { let controller = Controller(nibName: NSNib.Name("Controller"), bundle: Bundle.main) let popover = NSPopover() let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength) @@ -59,8 +58,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, } } - /// Open the controller popover and monitor when user clicks outside kmbmpdc UI to dismiss the - /// popover. + /// Open the controller popover and monitor when user clicks outside kmbmpdc UI to dismiss the popover. func openPopover(_ button: NSStatusBarButton) { mediaKeyTap?.activate() popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY) @@ -74,8 +72,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, self.closePopover() } let eventMask = NSEvent.EventTypeMask.leftMouseDown.union(NSEvent.EventTypeMask.rightMouseDown) - popoverDismissMonitor = NSEvent.addGlobalMonitorForEvents(matching: eventMask, - handler: eventHandler) + popoverDismissMonitor = NSEvent.addGlobalMonitorForEvents(matching: eventMask, handler: eventHandler) } } @@ -85,8 +82,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, let viewController = Preferences() viewController.owner = self preferenceWindow = NSWindow(contentViewController: viewController) - let nonResizableMask: UInt = preferenceWindow!.styleMask.rawValue & - ~NSWindow.StyleMask.resizable.rawValue + let nonResizableMask: UInt = preferenceWindow!.styleMask.rawValue & ~NSWindow.StyleMask.resizable.rawValue preferenceWindow!.styleMask = NSWindow.StyleMask(rawValue: nonResizableMask) preferenceWindow!.title = "kmbmpdc Preferences" } @@ -110,8 +106,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, return true } - func userNotificationCenter(_ center: NSUserNotificationCenter, - didActivate notification: NSUserNotification) { + func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) { if !popover.isShown { togglePopover() } diff --git a/kmbmpdc/Constants.swift b/kmbmpdc/Constants.swift index 96ee539..7748440 100644 --- a/kmbmpdc/Constants.swift +++ b/kmbmpdc/Constants.swift @@ -10,11 +10,11 @@ struct Constants { static let statusPaused = NSImage.Name("StatusPaused") static let statusPlaying = NSImage.Name("StatusPlaying") } - + struct Nibs { static let search = NSNib.Name("Search") } - + struct Notifications { static let changedTrack = Notification.Name("KMBMPDCChangedTrack") static let connected = Notification.Name("KMBMPDCConnected") diff --git a/kmbmpdc/Controller.swift b/kmbmpdc/Controller.swift index 36b0f80..dd62c2a 100644 --- a/kmbmpdc/Controller.swift +++ b/kmbmpdc/Controller.swift @@ -160,10 +160,11 @@ class Controller: NSViewController { DispatchQueue.main.async { let center = NSUserNotificationCenter.default - for deliveredNotification in center.deliveredNotifications { - if deliveredNotification.identifier == Constants.UserNotifications.trackChange { - center.removeDeliveredNotification(deliveredNotification) - } + let trackNotifications = center.deliveredNotifications.filter { + $0.identifier == Constants.UserNotifications.trackChange + } + for trackNotification in trackNotifications { + center.removeDeliveredNotification(trackNotification) } center.deliver(notification) } @@ -264,12 +265,11 @@ class Controller: NSViewController { source = cover! } - // Produce a scaled version of the given cover art to fit the target `NSImageView`. - // `NSImage` is produced by creating two different sized bitmap representations, one 300 - // pixels wide and other 600 pixels wide, in order to display good quality cover art on - // regular PPI displays and Apple's Retina displays. - // `NSImageInterpolation.high` is used to produce better quality scaling, especially when - // downscaling bigger cover art scans. + // Produce a scaled version of the given cover art to fit the target `NSImageView`. `NSImage` is produced by + // creating two different sized bitmap representations, one 300 pixels wide and other 600 pixels wide, in order + // to display good quality cover art on regular PPI displays and Apple's Retina displays. + // `NSImageInterpolation.high` is used to produce better quality scaling, especially when downscaling bigger + // cover art scans. let height = floor(source.size.height / source.size.width * 300.0) let image = NSImage(size: NSSize(width: 300.0, height: height)) for i: CGFloat in [1, 2] { @@ -331,13 +331,15 @@ class Controller: NSViewController { // If display is toggled on, `sender.state` equals 1 and if not, 0. When the queue view is // toggled on, it's 201 points high and the separator horizontal line is displayed. trackQueueSeparator.isHidden = false - NSAnimationContext.runAnimationGroup({ _ in - trackQueueTableHeight.animator().constant = sender.state == .on ? 201 : 0 - }) { + let animation: (NSAnimationContext) -> Void = { _ in + self.trackQueueTableHeight.animator().constant = sender.state == .on ? 201 : 0 + } + let callback = { if sender.state == .off { self.trackQueueSeparator.isHidden = true } } + NSAnimationContext.runAnimationGroup(animation, completionHandler: callback) } @IBAction func toggleRandomMode(_ sender: NSButton) { diff --git a/kmbmpdc/MPDClient.swift b/kmbmpdc/MPDClient.swift index 38415da..dc2b4aa 100644 --- a/kmbmpdc/MPDClient.swift +++ b/kmbmpdc/MPDClient.swift @@ -35,8 +35,7 @@ class MPDClient: NSObject { return host } - /// Returns the saved connection password string. If no string is saved in preferences, nil is - /// returned. + /// Returns the saved connection password string. If no string is saved in preferences, nil is returned. var connectionPassword: String? { guard let pass = UserDefaults.standard.string(forKey: Constants.Preferences.mpdPass) else { return nil @@ -239,9 +238,8 @@ class MPDClient: NSObject { idleEnter() } - /// Toggles between play and pause modes. If there isn't a song currently playing or paused, - /// starts playing the first track on the playlist to make sure there is a change to playback - /// when requested. + /// Toggles between play and pause modes. If there isn't a song currently playing or paused, starts playing the + /// first track on the playlist to make sure there is a change to playback when requested. func playPause() { idleExit() let status = mpd_run_status(mpdConnection!) @@ -268,9 +266,8 @@ class MPDClient: NSObject { idleEnter() } - /// Continuously sends idle commands to MPD until quitIdle is set to true. When the loop exits, - /// idling property is set to false so that operations that wait for idling to be finished can - /// continue execution. + /// Continuously sends idle commands to MPD until quitIdle is set to true. When the loop exits, idling property is + /// set to false so that operations that wait for idling to be finished can continue execution. func receiveIdleEvents() { DispatchQueue.global(qos: .background).async { idleLoop: while !self.quitIdle { @@ -384,8 +381,7 @@ class MPDClient: NSObject { NotificationCenter.default.post(notification) } - /// Fetches the queue not including the currently playing track and saves it to the global - /// `TrackQueue` object. + /// Fetches the queue not including the currently playing track and saves it to the global `TrackQueue` object. func reloadQueue() { while self.queueBusy { usleep(100 * 1000) @@ -460,8 +456,7 @@ class MPDClient: NSObject { idleEnter() } - /// Toggles a MPD option with idle mode cancel and resume, and refreshes the instance variables - /// from MPD afterwards. + /// Toggles a MPD option with idle mode cancel and resume, and refreshes the instance variables from MPD afterwards. /// - Parameter mode: MPDClient instance variable that stores the option value. /// - Parameter modeToggleFunction: libmpdclient function that toggles the option. func toggleMode(_ mode: Bool, modeToggleFunction: MPDSettingToggle) { diff --git a/kmbmpdc/Search.swift b/kmbmpdc/Search.swift index 7ed1eab..4eebbd0 100644 --- a/kmbmpdc/Search.swift +++ b/kmbmpdc/Search.swift @@ -91,8 +91,7 @@ class Search: NSViewController, NSTableViewDelegate, NSTableViewDataSource { } } - func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, - row: Int) -> Any? { + func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { guard let identifier = tableColumn?.identifier else { return nil }