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>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.19.3</string>
|
<string>0.19.4</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>130</string>
|
<string>140</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@ -303,7 +303,7 @@ class SupportedTypesHolder {
|
|||||||
action: try ActionType(from: decoder),
|
action: try ActionType(from: decoder),
|
||||||
longAction: try LongActionType(from: decoder),
|
longAction: try LongActionType(from: decoder),
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
)}
|
) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func register(typename: String, decoder: @escaping ParametersDecoder) {
|
func register(typename: String, decoder: @escaping ParametersDecoder) {
|
||||||
|
|||||||
@ -6,17 +6,17 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import Foundation
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
func trim() -> String {
|
func trim() -> String {
|
||||||
return self.trimmingCharacters(in: NSCharacterSet.whitespaces)
|
return trimmingCharacters(in: NSCharacterSet.whitespaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripComments() -> String {
|
func stripComments() -> String {
|
||||||
// ((\s|,)\/\*[\s\S]*?\*\/)|(( |, ")\/\/.*)
|
// ((\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? {
|
var hexColor: NSColor? {
|
||||||
@ -39,21 +39,20 @@ extension String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension NSImage {
|
extension NSImage {
|
||||||
func resize(maxSize:NSSize) -> NSImage {
|
func resize(maxSize: NSSize) -> NSImage {
|
||||||
var ratio:Float = 0.0
|
var ratio: Float = 0.0
|
||||||
let imageWidth = Float(self.size.width)
|
let imageWidth = Float(size.width)
|
||||||
let imageHeight = Float(self.size.height)
|
let imageHeight = Float(size.height)
|
||||||
let maxWidth = Float(maxSize.width)
|
let maxWidth = Float(maxSize.width)
|
||||||
let maxHeight = Float(maxSize.height)
|
let maxHeight = Float(maxSize.height)
|
||||||
|
|
||||||
// Get ratio (landscape or portrait)
|
// Get ratio (landscape or portrait)
|
||||||
if (imageWidth > imageHeight) {
|
if imageWidth > imageHeight {
|
||||||
// Landscape
|
// Landscape
|
||||||
ratio = maxWidth / imageWidth;
|
ratio = maxWidth / imageWidth
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Portrait
|
// Portrait
|
||||||
ratio = maxHeight / imageHeight;
|
ratio = maxHeight / imageHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate new size based on the ratio
|
// Calculate new size based on the ratio
|
||||||
@ -61,11 +60,11 @@ extension NSImage {
|
|||||||
let newHeight = imageHeight * ratio
|
let newHeight = imageHeight * ratio
|
||||||
|
|
||||||
// Create a new NSSize object with the newly calculated size
|
// 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
|
// Cast the NSImage to a CGImage
|
||||||
var imageRect:NSRect = NSMakeRect(0, 0, self.size.width, self.size.height)
|
var imageRect: NSRect = NSMakeRect(0, 0, size.width, size.height)
|
||||||
let imageRef = self.cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
|
let imageRef = cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
|
||||||
|
|
||||||
// Create NSImage from the CGImage using the new size
|
// Create NSImage from the CGImage using the new size
|
||||||
let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize)
|
let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize)
|
||||||
@ -74,34 +73,32 @@ extension NSImage {
|
|||||||
return imageWithNewSize
|
return imageWithNewSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func rotateByDegreess(degrees:CGFloat) -> NSImage {
|
func rotateByDegreess(degrees: CGFloat) -> NSImage {
|
||||||
|
var imageBounds = NSZeroRect; imageBounds.size = size
|
||||||
var imageBounds = NSZeroRect ; imageBounds.size = self.size
|
|
||||||
let pathBounds = NSBezierPath(rect: imageBounds)
|
let pathBounds = NSBezierPath(rect: imageBounds)
|
||||||
var transform = NSAffineTransform()
|
var transform = NSAffineTransform()
|
||||||
transform.rotate(byDegrees: degrees)
|
transform.rotate(byDegrees: degrees)
|
||||||
pathBounds.transform(using: transform as AffineTransform)
|
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)
|
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.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
|
// Start a new transform
|
||||||
transform = NSAffineTransform()
|
transform = NSAffineTransform()
|
||||||
// Move coordinate system to the center (since we want to rotate around the center)
|
// 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)
|
transform.rotate(byDegrees: degrees)
|
||||||
// Move the coordinate system bak to normal
|
// 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
|
// Draw the original image, rotated, into the new image
|
||||||
rotatedImage.lockFocus()
|
rotatedImage.lockFocus()
|
||||||
transform.concat()
|
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()
|
rotatedImage.unlockFocus()
|
||||||
|
|
||||||
return rotatedImage
|
return rotatedImage
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,11 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
case workTime
|
case workTime
|
||||||
case restTime
|
case restTime
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime)
|
let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime)
|
||||||
let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime)
|
let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300),
|
item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300),
|
||||||
action: .none,
|
action: .none,
|
||||||
@ -34,6 +34,7 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
case rest
|
case rest
|
||||||
case none
|
case none
|
||||||
}
|
}
|
||||||
|
|
||||||
private let defaultTitle = "🍅"
|
private let defaultTitle = "🍅"
|
||||||
private let workTime: TimeInterval
|
private let workTime: TimeInterval
|
||||||
private let restTime: TimeInterval
|
private let restTime: TimeInterval
|
||||||
@ -66,12 +67,12 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
typeTime = .work
|
typeTime = .work
|
||||||
startStopTimer()
|
startStopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func startStopRest() {
|
@objc func startStopRest() {
|
||||||
typeTime = .rest
|
typeTime = .rest
|
||||||
startStopTimer()
|
startStopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func startStopTimer() {
|
func startStopTimer() {
|
||||||
timer == nil ? start() : reset()
|
timer == nil ? start() : reset()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class AppleScriptDefinitionTests: XCTestCase {
|
class AppleScriptDefinitionTests: XCTestCase {
|
||||||
|
|
||||||
func testInline() {
|
func testInline() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ]
|
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ]
|
||||||
@ -13,7 +12,7 @@ class AppleScriptDefinitionTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
XCTAssertEqual(source.string, "tell everything fine")
|
XCTAssertEqual(source.string, "tell everything fine")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPath() {
|
func testPath() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/pew" } } ]
|
[ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/pew" } } ]
|
||||||
@ -26,7 +25,7 @@ class AppleScriptDefinitionTests: XCTestCase {
|
|||||||
let sourceStruct = source as? Source
|
let sourceStruct = source as? Source
|
||||||
XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew")
|
XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew")
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRefreshInterval() {
|
func testRefreshInterval() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]
|
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]
|
||||||
@ -37,5 +36,4 @@ class AppleScriptDefinitionTests: XCTestCase {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,29 +1,27 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class BackgroundColorTests: XCTestCase {
|
class BackgroundColorTests: XCTestCase {
|
||||||
|
|
||||||
func testOpaque() {
|
func testOpaque() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ]
|
[ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
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()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
XCTAssertEqual(color, .red)
|
XCTAssertEqual(color, .red)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAlpha() {
|
func testAlpha() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ]
|
[ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
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()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01)
|
XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class ParseConfig: XCTestCase {
|
class ParseConfig: XCTestCase {
|
||||||
|
|
||||||
func testButtonNoAction() {
|
func testButtonNoAction() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew" } ]
|
[ { "type": "staticButton", "title": "Pew" } ]
|
||||||
@ -31,7 +30,7 @@ class ParseConfig: XCTestCase {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPredefinedItem() {
|
func testPredefinedItem() {
|
||||||
let buttonKeycodeFixture = """
|
let buttonKeycodeFixture = """
|
||||||
[ { "type": "escape" } ]
|
[ { "type": "escape" } ]
|
||||||
@ -46,7 +45,7 @@ class ParseConfig: XCTestCase {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testExtendedWidthForPredefinedItem() {
|
func testExtendedWidthForPredefinedItem() {
|
||||||
let buttonKeycodeFixture = """
|
let buttonKeycodeFixture = """
|
||||||
[ { "type": "escape", "width": 110}, ]
|
[ { "type": "escape", "width": 110}, ]
|
||||||
@ -65,5 +64,4 @@ class ParseConfig: XCTestCase {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
build.sh
1
build.sh
@ -64,6 +64,7 @@ echo ""
|
|||||||
echo " version '${VERSION}'"
|
echo " version '${VERSION}'"
|
||||||
echo " sha256 '${SHA256}'"
|
echo " sha256 '${SHA256}'"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "Update MTMR v${VERSION}"
|
||||||
|
|
||||||
scp MTMR\ ${VERSION}.dmg do:/var/www/mtmr
|
scp MTMR\ ${VERSION}.dmg do:/var/www/mtmr
|
||||||
scp appcast.xml do:/var/www/mtmr
|
scp appcast.xml do:/var/www/mtmr
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user