Compare commits

...
11 Commits
Author SHA1 Message Date
toxblh c496156cf2 0.19.5 2019-02-12 21:35:47 +00:00
Anton Palgunov 154ea09e98 Merge pull request #139 from ReDetection/apple-script-robustness
Stable AppleScript
2019-02-04 05:55:38 +00:00
Serg 3b493fd5be create applescript on the queue it will run on 2019-01-28 10:36:04 +07:00
toxblh b718b1c9dd Style format 2019-01-24 00:04:30 +03:00
toxblh acc248a579 Close #135 2019-01-24 00:04:14 +03:00
toxblh 59581ffdc8 Merge branch 'master' of https://github.com/Toxblh/MTMR 2019-01-23 12:43:54 +03:00
toxblh 238b15b6a4 fix drop MTMR without timeZone 2019-01-23 12:43:25 +03:00
toxblh 732fd5c5b5 add helpers for fast update homebrew 2019-01-22 19:20:40 +03:00
toxblh f4b8e1f39a switch from localized to custom templates 2019-01-22 12:46:17 +03:00
Anton Palgunov e988951ff9 Update README.md 2019-01-22 12:26:42 +03:00
toxblh 807290ff0c improve build.sh 2019-01-22 12:21:38 +03:00
13 changed files with 135 additions and 121 deletions
+5 -1
View File
@@ -50,7 +50,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return frontmostId
}
isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil
if frontmostApplicationIdentifier != nil {
isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil
} else {
isBlockedApp = false
}
createMenu()
}
+12 -6
View File
@@ -9,13 +9,19 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
self.interval = interval
super.init(identifier: identifier, title: "⏳")
forceHideConstraint = view.widthAnchor.constraint(equalToConstant: 0)
guard let script = source.appleScript else {
title = "no script"
return
}
self.script = script
isBordered = false
title = "scheduled"
DispatchQueue.appleScriptQueue.async {
guard let script = source.appleScript else {
DispatchQueue.main.async {
self.title = "no script"
}
return
}
self.script = script
DispatchQueue.main.async {
self.isBordered = false
}
var error: NSDictionary?
guard script.compileAndReturnError(&error) else {
#if DEBUG
+2 -2
View File
@@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.19.2</string>
<string>0.19.5</string>
<key>CFBundleVersion</key>
<string>129</string>
<string>140</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
+3 -3
View File
@@ -303,7 +303,7 @@ class SupportedTypesHolder {
action: try ActionType(from: decoder),
longAction: try LongActionType(from: decoder),
parameters: [:]
)}
) }
}
func register(typename: String, decoder: @escaping ParametersDecoder) {
@@ -325,7 +325,7 @@ class SupportedTypesHolder {
enum ItemType: Decodable {
case staticButton(title: String)
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
case timeButton(formatTemplate: String, timeZone: String)
case timeButton(formatTemplate: String, timeZone: String?)
case battery()
case dock()
case volume()
@@ -394,7 +394,7 @@ enum ItemType: Decodable {
case .timeButton:
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
self = .timeButton(formatTemplate: template, timeZone: timeZone!)
self = .timeButton(formatTemplate: template, timeZone: timeZone)
case .battery:
self = .battery()
+22 -25
View File
@@ -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
}
}
+59 -66
View File
@@ -17,7 +17,6 @@ let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSuppor
let standardConfigPath = appSupportDirectory.appending("/items.json")
extension ItemType {
var identifierBase: String {
switch self {
case .staticButton(title: _):
@@ -52,7 +51,6 @@ extension ItemType {
return PomodoroBarItem.identifier
}
}
}
extension NSTouchBarItem.Identifier {
@@ -60,7 +58,6 @@ extension NSTouchBarItem.Identifier {
}
class TouchBarController: NSObject, NSTouchBarDelegate {
static let shared = TouchBarController()
var touchBar: NSTouchBar!
@@ -87,25 +84,23 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
var blacklistAppIdentifiers: [String] = []
var frontmostApplicationIdentifier: String? {
get {
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
return frontmostId
}
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
return frontmostId
}
private override init() {
super.init()
SupportedTypesHolder.sharedInstance.register(typename: "exitTouchbar", item: .staticButton(title: "exit"), action: .custom(closure: { [weak self] in self?.dismissTouchBar()}), longAction: .none)
SupportedTypesHolder.sharedInstance.register(typename: "exitTouchbar", item: .staticButton(title: "exit"), action: .custom(closure: { [weak self] in self?.dismissTouchBar() }), longAction: .none)
SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in
return (item: .staticButton(title: ""), action: .custom(closure: { [weak self] in
(item: .staticButton(title: ""), action: .custom(closure: { [weak self] in
guard let `self` = self else { return }
self.reloadPreset(path: self.lastPresetPath)
}), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
}
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
self.blacklistAppIdentifiers = blackListed
blacklistAppIdentifiers = blackListed
}
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
@@ -119,37 +114,37 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
if let oldBar = self.touchBar {
minimizeSystemModal(oldBar)
}
self.touchBar = NSTouchBar()
self.jsonItems = newJsonItems
self.itemDefinitions = [:]
self.items = [:]
self.leftIdentifiers = []
self.centerItems = []
self.rightIdentifiers = []
touchBar = NSTouchBar()
jsonItems = newJsonItems
itemDefinitions = [:]
items = [:]
leftIdentifiers = []
centerItems = []
rightIdentifiers = []
loadItemDefinitions(jsonItems: self.jsonItems)
loadItemDefinitions(jsonItems: jsonItems)
createItems()
centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
return items[identifier]
items[identifier]
})
self.centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
self.scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
touchBar.delegate = self
touchBar.defaultItemIdentifiers = []
touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers
touchBar.defaultItemIdentifiers = leftIdentifiers + [centerScrollArea] + rightIdentifiers
self.updateActiveApp()
updateActiveApp()
}
@objc func activeApplicationChanged(_ n: Notification) {
@objc func activeApplicationChanged(_: Notification) {
updateActiveApp()
}
func updateActiveApp() {
if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil {
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil {
dismissTouchBar()
} else {
presentTouchBar()
@@ -194,8 +189,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
}
func createItems() {
for (identifier, definition) in self.itemDefinitions {
self.items[identifier] = self.createItem(forIdentifier: identifier, definition: definition)
for (identifier, definition) in itemDefinitions {
items[identifier] = createItem(forIdentifier: identifier, definition: definition)
}
}
@@ -212,7 +207,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
}
@objc private func presentTouchBar() {
if self.showControlStripState {
if showControlStripState {
updateControlStripPresence()
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
} else {
@@ -230,9 +225,9 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
presentTouchBar()
}
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
func touchBar(_: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
if identifier == centerScrollArea {
return self.scrollArea
return scrollArea
}
guard let item = self.items[identifier],
@@ -244,46 +239,45 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
}
func createItem(forIdentifier identifier: NSTouchBarItem.Identifier, definition item: BarItemDefinition) -> NSTouchBarItem? {
var barItem: NSTouchBarItem!
switch item.type {
case .staticButton(title: let title):
case let .staticButton(title: title):
barItem = CustomButtonTouchBarItem(identifier: identifier, title: title)
case .appleScriptTitledButton(source: let source, refreshInterval: let interval):
case let .appleScriptTitledButton(source: source, refreshInterval: interval):
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
case .timeButton(formatTemplate: let template, timeZone: let timeZone):
case let .timeButton(formatTemplate: template, timeZone: timeZone):
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
case .battery():
barItem = BatteryBarItem(identifier: identifier)
case .dock:
barItem = AppScrubberTouchBarItem(identifier: identifier)
case .volume:
if case .image(let source)? = item.additionalParameters[.image] {
if case let .image(source)? = item.additionalParameters[.image] {
barItem = VolumeViewController(identifier: identifier, image: source.image)
} else {
barItem = VolumeViewController(identifier: identifier)
}
case .brightness(refreshInterval: let interval):
if case .image(let source)? = item.additionalParameters[.image] {
case let .brightness(refreshInterval: interval):
if case let .image(source)? = item.additionalParameters[.image] {
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval, image: source.image)
} else {
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval)
}
case .weather(interval: let interval, units: let units, api_key: let api_key, icon_type: let icon_type):
case let .weather(interval: interval, units: units, api_key: api_key, icon_type: icon_type):
barItem = WeatherBarItem(identifier: identifier, interval: interval, units: units, api_key: api_key, icon_type: icon_type)
case .currency(interval: let interval, from: let from, to: let to, full: let full):
case let .currency(interval: interval, from: from, to: to, full: full):
barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, full: full)
case .inputsource():
barItem = InputSourceBarItem(identifier: identifier)
case .music(interval: let interval):
case let .music(interval: interval):
barItem = MusicBarItem(identifier: identifier, interval: interval)
case .groupBar(items: let items):
case let .groupBar(items: items):
barItem = GroupBarItem(identifier: identifier, items: items)
case .nightShift():
barItem = NightShiftBarItem(identifier: identifier)
case .dnd():
barItem = DnDBarItem(identifier: identifier)
case .pomodoro(workTime: let workTime, restTime: let restTime):
case let .pomodoro(workTime: workTime, restTime: restTime):
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
}
@@ -293,19 +287,19 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
if let longAction = self.longAction(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
item.longTapClosure = longAction
}
if case .bordered(let bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
if case let .bordered(bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
item.isBordered = bordered
}
if case .background(let color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
if case let .background(color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
item.backgroundColor = color
}
if case .width(let value)? = item.additionalParameters[.width], let widthBarItem = barItem as? CanSetWidth {
if case let .width(value)? = item.additionalParameters[.width], let widthBarItem = barItem as? CanSetWidth {
widthBarItem.setWidth(value: value)
}
if case .image(let source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
if case let .image(source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
item.image = source.image
}
if case .title(let value)? = item.additionalParameters[.title] {
if case let .title(value)? = item.additionalParameters[.title] {
if let item = barItem as? GroupBarItem {
item.collapsedRepresentationLabel = value
} else if let item = barItem as? CustomButtonTouchBarItem {
@@ -315,13 +309,13 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
return barItem
}
func action(forItem item: BarItemDefinition) -> (()->())? {
func action(forItem item: BarItemDefinition) -> (() -> Void)? {
switch item.action {
case .hidKey(keycode: let keycode):
case let .hidKey(keycode: keycode):
return { HIDPostAuxKey(keycode) }
case .keyPress(keycode: let keycode):
case let .keyPress(keycode: keycode):
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
case .appleScript(source: let source):
case let .appleScript(source: source):
guard let appleScript = source.appleScript else {
print("cannot create apple script for item \(item)")
return {}
@@ -335,38 +329,37 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
}
}
}
case .shellScript(executable: let executable, parameters: let parameters):
case let .shellScript(executable: executable, parameters: parameters):
return {
let task = Process()
task.launchPath = executable
task.arguments = parameters
task.launch()
}
case .openUrl(url: let url):
case let .openUrl(url: url):
return {
if let url = URL(string: url), NSWorkspace.shared.open(url) {
#if DEBUG
print("URL was successfully opened")
print("URL was successfully opened")
#endif
} else {
print("error", url)
}
}
case .custom(closure: let closure):
case let .custom(closure: closure):
return closure
case .none:
return nil
}
}
func longAction(forItem item: BarItemDefinition) -> (()->())? {
func longAction(forItem item: BarItemDefinition) -> (() -> Void)? {
switch item.longAction {
case .hidKey(keycode: let keycode):
case let .hidKey(keycode: keycode):
return { HIDPostAuxKey(keycode) }
case .keyPress(keycode: let keycode):
case let .keyPress(keycode: keycode):
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
case .appleScript(source: let source):
case let .appleScript(source: source):
guard let appleScript = source.appleScript else {
print("cannot create apple script for item \(item)")
return {}
@@ -378,24 +371,24 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
print("error \(error) when handling \(item) ")
}
}
case .shellScript(executable: let executable, parameters: let parameters):
case let .shellScript(executable: executable, parameters: parameters):
return {
let task = Process()
task.launchPath = executable
task.arguments = parameters
task.launch()
}
case .openUrl(url: let url):
case let .openUrl(url: url):
return {
if let url = URL(string: url), NSWorkspace.shared.open(url) {
#if DEBUG
print("URL was successfully opened")
print("URL was successfully opened")
#endif
} else {
print("error", url)
}
}
case .custom(closure: let closure):
case let .custom(closure: closure):
return closure
case .none:
return nil
@@ -409,13 +402,13 @@ protocol CanSetWidth {
extension NSCustomTouchBarItem: CanSetWidth {
func setWidth(value: CGFloat) {
self.view.widthAnchor.constraint(equalToConstant: value).isActive = true
view.widthAnchor.constraint(equalToConstant: value).isActive = true
}
}
extension BarItemDefinition {
var align: Align {
if case .align(let result)? = self.additionalParameters[.align] {
if case let .align(result)? = additionalParameters[.align] {
return result
}
return .center
+5 -4
View File
@@ -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()
}
+1 -1
View File
@@ -5,7 +5,7 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
private var timer: Timer!
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil) {
dateFormatter.setLocalizedDateFormatFromTemplate(formatTemplate)
dateFormatter.dateFormat = formatTemplate
if let abbr = timeZone {
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
}
+2 -4
View File
@@ -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
}
}
}
+3 -5
View File
@@ -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)
}
}
+2 -4
View File
@@ -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
}
}
}
+10
View File
@@ -119,6 +119,16 @@ To close a group, use the button:
```
## Native plugins
#### `timeButton`
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
```js
{
"type": "timeButton",
"formatTemplate": "dd HH:mm",
"timeZone": "UTC"
}
```
#### `weather`
> Provider: https://openweathermap.org Need allowance location service
```js
+9
View File
@@ -26,6 +26,7 @@ VERSION=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ${NAME}.a
MINIMUM=`/usr/libexec/PlistBuddy -c "Print LSMinimumSystemVersion" ${NAME}.app/Contents/Info.plist`
SIZE=`stat -f%z MTMR\ ${VERSION}.dmg`
SIGN=`~/Sparkle/bin/sign_update MTMR\ ${VERSION}.dmg ~/Sparkle/bin/dsa_priv.pem | awk '{printf "%s",$0} END {print ""}'`
SHA256=`shasum -a 256 MTMR\ ${VERSION}.dmg | awk '{print $1}'`
# ditto -c -k --sequesterRsrc --keepParent "${NAME}.app" "${NAME}v${VERSION}.zip"
@@ -57,5 +58,13 @@ echo "<?xml version=\"1.0\" standalone=\"yes\"?>
</channel>
</rss>" > appcast.xml
echo ""
echo "Homebrew https://github.com/Homebrew/homebrew-cask/edit/master/Casks/mtmr.rb"
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