From b718b1c9dd062e563a9c34c26f3d96406db91645 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Thu, 24 Jan 2019 00:04:30 +0300 Subject: [PATCH] Style format --- MTMR/Info.plist | 4 +- MTMR/ItemsParsing.swift | 2 +- MTMR/SupportHelpers.swift | 47 ++++++++++------------ MTMR/Widgets/PomodoroBarItem.swift | 9 +++-- MTMRTests/AppleScriptDefinitionTests.swift | 6 +-- MTMRTests/BackgroundColorTests.swift | 8 ++-- MTMRTests/ParseConfigTests.swift | 6 +-- build.sh | 1 + 8 files changed, 38 insertions(+), 45 deletions(-) diff --git a/MTMR/Info.plist b/MTMR/Info.plist index ad299c4..1996487 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.19.3 + 0.19.4 CFBundleVersion - 130 + 140 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index 4cf6726..c2003db 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -303,7 +303,7 @@ class SupportedTypesHolder { action: try ActionType(from: decoder), longAction: try LongActionType(from: decoder), parameters: [:] - )} + ) } } func register(typename: String, decoder: @escaping ParametersDecoder) { diff --git a/MTMR/SupportHelpers.swift b/MTMR/SupportHelpers.swift index 5ff7110..71373cc 100644 --- a/MTMR/SupportHelpers.swift +++ b/MTMR/SupportHelpers.swift @@ -6,17 +6,17 @@ // Copyright © 2018 Anton Palgunov. All rights reserved. // -import Foundation import AppKit +import Foundation extension String { func trim() -> String { - return self.trimmingCharacters(in: NSCharacterSet.whitespaces) + return trimmingCharacters(in: NSCharacterSet.whitespaces) } func stripComments() -> String { // ((\s|,)\/\*[\s\S]*?\*\/)|(( |, ")\/\/.*) - return self.replacingOccurrences(of: "((\\s|,)\\/\\*[\\s\\S]*?\\*\\/)|(( |, \\\")\\/\\/.*)", with: "", options: .regularExpression) + return replacingOccurrences(of: "((\\s|,)\\/\\*[\\s\\S]*?\\*\\/)|(( |, \\\")\\/\\/.*)", with: "", options: .regularExpression) } var hexColor: NSColor? { @@ -39,21 +39,20 @@ extension String { } extension NSImage { - func resize(maxSize:NSSize) -> NSImage { - var ratio:Float = 0.0 - let imageWidth = Float(self.size.width) - let imageHeight = Float(self.size.height) + func resize(maxSize: NSSize) -> NSImage { + var ratio: Float = 0.0 + let imageWidth = Float(size.width) + let imageHeight = Float(size.height) let maxWidth = Float(maxSize.width) let maxHeight = Float(maxSize.height) // Get ratio (landscape or portrait) - if (imageWidth > imageHeight) { + if imageWidth > imageHeight { // Landscape - ratio = maxWidth / imageWidth; - } - else { + ratio = maxWidth / imageWidth + } else { // Portrait - ratio = maxHeight / imageHeight; + ratio = maxHeight / imageHeight } // Calculate new size based on the ratio @@ -61,11 +60,11 @@ extension NSImage { let newHeight = imageHeight * ratio // Create a new NSSize object with the newly calculated size - let newSize:NSSize = NSSize(width: Int(newWidth), height: Int(newHeight)) + let newSize: NSSize = NSSize(width: Int(newWidth), height: Int(newHeight)) // Cast the NSImage to a CGImage - var imageRect:NSRect = NSMakeRect(0, 0, self.size.width, self.size.height) - let imageRef = self.cgImage(forProposedRect: &imageRect, context: nil, hints: nil) + var imageRect: NSRect = NSMakeRect(0, 0, size.width, size.height) + let imageRef = cgImage(forProposedRect: &imageRect, context: nil, hints: nil) // Create NSImage from the CGImage using the new size let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize) @@ -74,34 +73,32 @@ extension NSImage { return imageWithNewSize } - func rotateByDegreess(degrees:CGFloat) -> NSImage { - - var imageBounds = NSZeroRect ; imageBounds.size = self.size + func rotateByDegreess(degrees: CGFloat) -> NSImage { + var imageBounds = NSZeroRect; imageBounds.size = size let pathBounds = NSBezierPath(rect: imageBounds) var transform = NSAffineTransform() transform.rotate(byDegrees: degrees) pathBounds.transform(using: transform as AffineTransform) - let rotatedBounds:NSRect = NSMakeRect(NSZeroPoint.x, NSZeroPoint.y , self.size.width, self.size.height ) + let rotatedBounds: NSRect = NSMakeRect(NSZeroPoint.x, NSZeroPoint.y, size.width, size.height) let rotatedImage = NSImage(size: rotatedBounds.size) - //Center the image within the rotated bounds + // Center the image within the rotated bounds imageBounds.origin.x = NSMidX(rotatedBounds) - (NSWidth(imageBounds) / 2) - imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight(imageBounds) / 2) + imageBounds.origin.y = NSMidY(rotatedBounds) - (NSHeight(imageBounds) / 2) // Start a new transform transform = NSAffineTransform() // Move coordinate system to the center (since we want to rotate around the center) - transform.translateX(by: +(NSWidth(rotatedBounds) / 2 ), yBy: +(NSHeight(rotatedBounds) / 2)) + transform.translateX(by: +(NSWidth(rotatedBounds) / 2), yBy: +(NSHeight(rotatedBounds) / 2)) transform.rotate(byDegrees: degrees) // Move the coordinate system bak to normal - transform.translateX(by: -(NSWidth(rotatedBounds) / 2 ), yBy: -(NSHeight(rotatedBounds) / 2)) + transform.translateX(by: -(NSWidth(rotatedBounds) / 2), yBy: -(NSHeight(rotatedBounds) / 2)) // Draw the original image, rotated, into the new image rotatedImage.lockFocus() transform.concat() - self.draw(in: imageBounds, from: NSZeroRect, operation: NSCompositingOperation.copy, fraction: 1.0) + draw(in: imageBounds, from: NSZeroRect, operation: NSCompositingOperation.copy, fraction: 1.0) rotatedImage.unlockFocus() return rotatedImage } - } diff --git a/MTMR/Widgets/PomodoroBarItem.swift b/MTMR/Widgets/PomodoroBarItem.swift index c106938..7b824f7 100644 --- a/MTMR/Widgets/PomodoroBarItem.swift +++ b/MTMR/Widgets/PomodoroBarItem.swift @@ -16,11 +16,11 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { case workTime case restTime } - + let container = try decoder.container(keyedBy: CodingKeys.self) let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime) - + return ( item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300), action: .none, @@ -34,6 +34,7 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { case rest case none } + private let defaultTitle = "🍅" private let workTime: TimeInterval private let restTime: TimeInterval @@ -66,12 +67,12 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget { typeTime = .work startStopTimer() } - + @objc func startStopRest() { typeTime = .rest startStopTimer() } - + func startStopTimer() { timer == nil ? start() : reset() } diff --git a/MTMRTests/AppleScriptDefinitionTests.swift b/MTMRTests/AppleScriptDefinitionTests.swift index 0977bab..8b6c442 100644 --- a/MTMRTests/AppleScriptDefinitionTests.swift +++ b/MTMRTests/AppleScriptDefinitionTests.swift @@ -1,7 +1,6 @@ import XCTest class AppleScriptDefinitionTests: XCTestCase { - func testInline() { let buttonNoActionFixture = """ [ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ] @@ -13,7 +12,7 @@ class AppleScriptDefinitionTests: XCTestCase { } XCTAssertEqual(source.string, "tell everything fine") } - + func testPath() { let buttonNoActionFixture = """ [ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/pew" } } ] @@ -26,7 +25,7 @@ class AppleScriptDefinitionTests: XCTestCase { let sourceStruct = source as? Source XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew") } - + func testRefreshInterval() { let buttonNoActionFixture = """ [ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ] @@ -37,5 +36,4 @@ class AppleScriptDefinitionTests: XCTestCase { return } } - } diff --git a/MTMRTests/BackgroundColorTests.swift b/MTMRTests/BackgroundColorTests.swift index 915bbbc..4ed6066 100644 --- a/MTMRTests/BackgroundColorTests.swift +++ b/MTMRTests/BackgroundColorTests.swift @@ -1,29 +1,27 @@ import XCTest class BackgroundColorTests: XCTestCase { - func testOpaque() { let buttonNoActionFixture = """ [ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ] """.data(using: .utf8)! let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) - guard case .background(let color)? = result?.first?.additionalParameters[.background] else { + guard case let .background(color)? = result?.first?.additionalParameters[.background] else { XCTFail() return } XCTAssertEqual(color, .red) } - + func testAlpha() { let buttonNoActionFixture = """ [ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ] """.data(using: .utf8)! let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture) - guard case .background(let color)? = result?.first?.additionalParameters[.background] else { + guard case let .background(color)? = result?.first?.additionalParameters[.background] else { XCTFail() return } XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01) } - } diff --git a/MTMRTests/ParseConfigTests.swift b/MTMRTests/ParseConfigTests.swift index f5e4221..a3321cc 100644 --- a/MTMRTests/ParseConfigTests.swift +++ b/MTMRTests/ParseConfigTests.swift @@ -1,7 +1,6 @@ import XCTest class ParseConfig: XCTestCase { - func testButtonNoAction() { let buttonNoActionFixture = """ [ { "type": "staticButton", "title": "Pew" } ] @@ -31,7 +30,7 @@ class ParseConfig: XCTestCase { return } } - + func testPredefinedItem() { let buttonKeycodeFixture = """ [ { "type": "escape" } ] @@ -46,7 +45,7 @@ class ParseConfig: XCTestCase { return } } - + func testExtendedWidthForPredefinedItem() { let buttonKeycodeFixture = """ [ { "type": "escape", "width": 110}, ] @@ -65,5 +64,4 @@ class ParseConfig: XCTestCase { return } } - } diff --git a/build.sh b/build.sh index 27ba3ca..cc5f8ee 100755 --- a/build.sh +++ b/build.sh @@ -64,6 +64,7 @@ echo "" echo " version '${VERSION}'" echo " sha256 '${SHA256}'" echo "" +echo "Update MTMR v${VERSION}" scp MTMR\ ${VERSION}.dmg do:/var/www/mtmr scp appcast.xml do:/var/www/mtmr