Skip to content

Commit

Permalink
Fix style issues and increase max line length to 120 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
arttuperala committed Mar 28, 2018
1 parent 5eb4456 commit 6f19b29
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .swiftlint.yml
Expand Up @@ -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
15 changes: 5 additions & 10 deletions kmbmpdc/AppDelegate.swift
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand All @@ -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"
}
Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions kmbmpdc/Constants.swift
Expand Up @@ -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")
Expand Down
28 changes: 15 additions & 13 deletions kmbmpdc/Controller.swift
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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] {
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 7 additions & 12 deletions kmbmpdc/MPDClient.swift
Expand Up @@ -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
Expand Down Expand Up @@ -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!)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions kmbmpdc/Search.swift
Expand Up @@ -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
}
Expand Down

0 comments on commit 6f19b29

Please sign in to comment.