mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
Style format
This commit is contained in:
parent
acc248a579
commit
b718b1c9dd
@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.19.3</string>
|
||||
<string>0.19.4</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>130</string>
|
||||
<string>140</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@ -303,7 +303,7 @@ class SupportedTypesHolder {
|
||||
action: try ActionType(from: decoder),
|
||||
longAction: try LongActionType(from: decoder),
|
||||
parameters: [:]
|
||||
)}
|
||||
) }
|
||||
}
|
||||
|
||||
func register(typename: String, decoder: @escaping ParametersDecoder) {
|
||||
|
||||
@ -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)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
case rest
|
||||
case none
|
||||
}
|
||||
|
||||
private let defaultTitle = "🍅"
|
||||
private let workTime: TimeInterval
|
||||
private let restTime: TimeInterval
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import XCTest
|
||||
|
||||
class AppleScriptDefinitionTests: XCTestCase {
|
||||
|
||||
func testInline() {
|
||||
let buttonNoActionFixture = """
|
||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ]
|
||||
@ -37,5 +36,4 @@ class AppleScriptDefinitionTests: XCTestCase {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
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
|
||||
}
|
||||
@ -19,11 +18,10 @@ class BackgroundColorTests: XCTestCase {
|
||||
[ { "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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import XCTest
|
||||
|
||||
class ParseConfig: XCTestCase {
|
||||
|
||||
func testButtonNoAction() {
|
||||
let buttonNoActionFixture = """
|
||||
[ { "type": "staticButton", "title": "Pew" } ]
|
||||
@ -65,5 +64,4 @@ class ParseConfig: XCTestCase {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user