From 970fb99e33322fc73f92518df022a4cf86e1825f Mon Sep 17 00:00:00 2001 From: Serg Date: Tue, 10 Apr 2018 16:58:52 +0700 Subject: [PATCH] interval for apple script --- MTMR/ItemsParsing.swift | 12 ++++++++---- MTMR/TouchBarController.swift | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index eea90e8..3420d70 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -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 } diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 4decea7..c6c976f 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -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 {