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

View File

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