From 54d1ae9e27819d73c4d4b8e2151660361a06238c Mon Sep 17 00:00:00 2001 From: Valeriy Van Date: Sun, 18 Nov 2018 20:33:20 +0100 Subject: [PATCH] Refactors dimStartFromChange and dimFadeToChange --- .../PreferencesWindowController.swift | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Aerial/Source/Controllers/PreferencesWindowController.swift b/Aerial/Source/Controllers/PreferencesWindowController.swift index b0fe720e..4b953ca7 100644 --- a/Aerial/Source/Controllers/PreferencesWindowController.swift +++ b/Aerial/Source/Controllers/PreferencesWindowController.swift @@ -1222,19 +1222,17 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo } @IBAction func dimStartFromChange(_ sender: NSSliderCell) { - let timeManagement = TimeManagement.sharedInstance - guard let event = NSApplication.shared.currentEvent else { - return - } + guard let event = NSApplication.shared.currentEvent else { return } - if event.type != .leftMouseUp && event.type != .leftMouseDown && event.type != .leftMouseDragged { + guard [.leftMouseUp, .leftMouseDown, .leftMouseDragged].contains(event.type) else { //warnLog("Unexepected event type \(event.type)") return } + let timeManagement = TimeManagement.sharedInstance if event.type == .leftMouseUp { - if savedBrightness != nil { - timeManagement.setBrightness(level: savedBrightness!) + if let brightness = savedBrightness { + timeManagement.setBrightness(level: brightness) savedBrightness = nil } preferences.startDim = sender.doubleValue @@ -1248,18 +1246,16 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo } @IBAction func dimFadeToChange(_ sender: NSSliderCell) { - let timeManagement = TimeManagement.sharedInstance - guard let event = NSApplication.shared.currentEvent else { - return - } + guard let event = NSApplication.shared.currentEvent else { return } - if event.type != .leftMouseUp && event.type != .leftMouseDown && event.type != .leftMouseDragged { + if ![.leftMouseUp, .leftMouseDown, .leftMouseDragged].contains(event.type) { //warnLog("Unexepected event type \(event.type)") } + let timeManagement = TimeManagement.sharedInstance if event.type == .leftMouseUp { - if savedBrightness != nil { - timeManagement.setBrightness(level: savedBrightness!) + if let brightness = savedBrightness { + timeManagement.setBrightness(level: brightness) savedBrightness = nil } preferences.endDim = sender.doubleValue