1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 09:28:38 +00:00

interval for apple script

This commit is contained in:
Serg 2018-04-10 16:58:52 +07:00
parent 46f35f4737
commit 970fb99e33
2 changed files with 10 additions and 6 deletions

View File

@ -56,12 +56,13 @@ class SupportedTypesHolder {
enum ItemType: Decodable { enum ItemType: Decodable {
case staticButton(title: String) case staticButton(title: String)
case appleScriptTitledButton(source: String) case appleScriptTitledButton(source: String, refreshInterval: Double)
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case type case type
case title case title
case titleAppleScript case titleAppleScript
case refreshInterval
} }
private enum ItemTypeRaw: String, Decodable { private enum ItemTypeRaw: String, Decodable {
@ -75,7 +76,8 @@ enum ItemType: Decodable {
switch type { switch type {
case .appleScriptTitledButton: case .appleScriptTitledButton:
let source = try container.decode(String.self, forKey: .titleAppleScript) let source = try container.decode(String.self, forKey: .titleAppleScript)
self = .appleScriptTitledButton(source: source) let interval = try container.decode(Double.self, forKey: .refreshInterval)
self = .appleScriptTitledButton(source: source, refreshInterval: interval)
case .staticButton: case .staticButton:
let title = try container.decode(String.self, forKey: .title) let title = try container.decode(String.self, forKey: .title)
self = .staticButton(title: title) self = .staticButton(title: title)
@ -123,9 +125,11 @@ enum ActionType: Decodable {
extension ItemType: Equatable {} extension ItemType: Equatable {}
func ==(lhs: ItemType, rhs: ItemType) -> Bool { func ==(lhs: ItemType, rhs: ItemType) -> Bool {
switch (lhs, rhs) { switch (lhs, rhs) {
case let (.staticButton(a), .staticButton(b)), case let (.staticButton(a), .staticButton(b)):
let (.appleScriptTitledButton(a), .appleScriptTitledButton(b)):
return a == b return a == b
case let (.appleScriptTitledButton(a, b), .appleScriptTitledButton(c, d)):
return a == c && b == d
default: default:
return false return false
} }

View File

@ -98,8 +98,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
return CustomButtonTouchBarItem(identifier: identifier, title: title) { _ in return CustomButtonTouchBarItem(identifier: identifier, title: title) { _ in
} }
case .appleScriptTitledButton(source: let source): case .appleScriptTitledButton(source: let source, refreshInterval: let interval):
return AppleScriptTouchBarItem(identifier: identifier, appleScript: source, interval: 30) //fixme interval return AppleScriptTouchBarItem(identifier: identifier, appleScript: source, interval: interval)
} }
switch identifier { switch identifier {