diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index caa0476..572af40 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -340,7 +340,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1000; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Anton Palgunov"; TargetAttributes = { B082B24E205C7D8000BC04DC = { @@ -626,7 +626,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_IDENTITY = "Developer ID Application"; + CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = D6D8BR2QNB; diff --git a/MTMR.xcodeproj/xcshareddata/xcschemes/MTMR.xcscheme b/MTMR.xcodeproj/xcshareddata/xcschemes/MTMR.xcscheme index 5fc2e33..7faee5b 100644 --- a/MTMR.xcodeproj/xcshareddata/xcschemes/MTMR.xcscheme +++ b/MTMR.xcodeproj/xcshareddata/xcschemes/MTMR.xcscheme @@ -1,6 +1,6 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.19 + 0.19.1 CFBundleVersion - 112 + 125 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index c9c5038..bb6aff8 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -181,15 +181,16 @@ class SupportedTypesHolder { }, "currency": { decoder in - enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to } + enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to; case full } let container = try decoder.container(keyedBy: CodingKeys.self) let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) let from = try container.decodeIfPresent(String.self, forKey: .from) let to = try container.decodeIfPresent(String.self, forKey: .to) + let full = try container.decodeIfPresent(Bool.self, forKey: .full) let action = try ActionType(from: decoder) let longAction = try LongActionType(from: decoder) return ( - item: .currency(interval: interval ?? 600.00, from: from ?? "RUB", to: to ?? "USD"), + item: .currency(interval: interval ?? 600.00, from: from ?? "RUB", to: to ?? "USD", full: full ?? false), action, longAction, parameters: [:] @@ -330,7 +331,7 @@ enum ItemType: Decodable { case volume() case brightness(refreshInterval: Double) case weather(interval: Double, units: String, api_key: String, icon_type: String) - case currency(interval: Double, from: String, to: String) + case currency(interval: Double, from: String, to: String, full: Bool) case inputsource() case music(interval: Double) case groupBar(items: [BarItemDefinition]) @@ -345,6 +346,7 @@ enum ItemType: Decodable { case refreshInterval case from case to + case full case units case api_key case icon_type @@ -416,7 +418,8 @@ enum ItemType: Decodable { let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 600.0 let from = try container.decodeIfPresent(String.self, forKey: .from) ?? "RUB" let to = try container.decodeIfPresent(String.self, forKey: .to) ?? "USD" - self = .currency(interval: interval, from: from, to: to) + let full = try container.decodeIfPresent(Bool.self, forKey: .full) ?? false + self = .currency(interval: interval, from: from, to: to, full: full) case .inputsource: self = .inputsource() diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index ed54402..de86288 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -36,7 +36,7 @@ extension ItemType { return "com.toxblh.mtmr.brightness" case .weather(interval: _, units: _, api_key: _, icon_type: _): return "com.toxblh.mtmr.weather" - case .currency(interval: _, from: _, to: _): + case .currency(interval: _, from: _, to: _, full: _): return "com.toxblh.mtmr.currency" case .inputsource(): return "com.toxblh.mtmr.inputsource." @@ -84,7 +84,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip") } } - + var blacklistAppIdentifiers: [String] = [] var frontmostApplicationIdentifier: String? { get { @@ -92,11 +92,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate { 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: "close") { _ in return (item: .staticButton(title: ""), action: .custom(closure: { [weak self] in guard let `self` = self else { return } @@ -107,14 +107,14 @@ class TouchBarController: NSObject, NSTouchBarDelegate { if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { self.blacklistAppIdentifiers = blackListed } - + NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil) NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil) NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil) - + reloadStandardConfig() } - + func createAndUpdatePreset(newJsonItems: [BarItemDefinition]) { if let oldBar = self.touchBar { minimizeSystemModal(oldBar) @@ -126,28 +126,28 @@ class TouchBarController: NSObject, NSTouchBarDelegate { self.leftIdentifiers = [] self.centerItems = [] self.rightIdentifiers = [] - + loadItemDefinitions(jsonItems: self.jsonItems) createItems() - + centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in return items[identifier] }) - + self.centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString)) self.scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems) - + touchBar.delegate = self touchBar.defaultItemIdentifiers = [] touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers - + self.updateActiveApp() } - + @objc func activeApplicationChanged(_ n: Notification) { updateActiveApp() } - + func updateActiveApp() { if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil { dismissTouchBar() @@ -155,7 +155,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { presentTouchBar() } } - + func reloadStandardConfig() { let presetPath = standardConfigPath if !FileManager.default.fileExists(atPath: presetPath), @@ -163,16 +163,16 @@ class TouchBarController: NSObject, NSTouchBarDelegate { try? FileManager.default.createDirectory(atPath: appSupportDirectory, withIntermediateDirectories: true, attributes: nil) try? FileManager.default.copyItem(atPath: defaultPreset, toPath: presetPath) } - + reloadPreset(path: presetPath) } - + func reloadPreset(path: String) { lastPresetPath = path let items = path.fileData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])] createAndUpdatePreset(newJsonItems: items) } - + func loadItemDefinitions(jsonItems: [BarItemDefinition]) { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH-mm-ss" @@ -192,13 +192,13 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } } } - + func createItems() { for (identifier, definition) in self.itemDefinitions { self.items[identifier] = self.createItem(forIdentifier: identifier, definition: definition) } } - + @objc func setupControlStripPresence() { DFRSystemModalShowsCloseBoxWhenFrontMost(false) let item = NSCustomTouchBarItem(identifier: .controlStripItem) @@ -224,7 +224,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { minimizeSystemModal(touchBar) updateControlStripPresence() } - + @objc func resetControlStrip() { dismissTouchBar() presentTouchBar() @@ -242,7 +242,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } return item } - + func createItem(forIdentifier identifier: NSTouchBarItem.Identifier, definition item: BarItemDefinition) -> NSTouchBarItem? { var barItem: NSTouchBarItem! @@ -271,8 +271,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } case .weather(interval: let interval, units: let units, api_key: let api_key, icon_type: let 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): - barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to) + case .currency(interval: let interval, from: let from, to: let to, full: let full): + barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, full: full) case .inputsource(): barItem = InputSourceBarItem(identifier: identifier) case .music(interval: let interval): @@ -286,7 +286,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { case .pomodoro(workTime: let workTime, restTime: let restTime): barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime) } - + if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem { item.tapClosure = action } @@ -359,7 +359,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } } - + func longAction(forItem item: BarItemDefinition) -> (()->())? { switch item.longAction { case .hidKey(keycode: let keycode): diff --git a/MTMR/Widgets/CurrencyBarItem.swift b/MTMR/Widgets/CurrencyBarItem.swift index 1733a0a..cd89e6c 100644 --- a/MTMR/Widgets/CurrencyBarItem.swift +++ b/MTMR/Widgets/CurrencyBarItem.swift @@ -12,9 +12,11 @@ import CoreLocation class CurrencyBarItem: CustomButtonTouchBarItem { private let activity: NSBackgroundActivityScheduler private var prefix: String + private var postfix: String private var from: String private var to: String private var oldValue: Float32! + private var full: Bool = false private let currencies = [ "USD": "$", @@ -36,11 +38,12 @@ class CurrencyBarItem: CustomButtonTouchBarItem { "ETH": "Ξ", ] - init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) { + init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, full: Bool) { activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck") activity.interval = interval self.from = from self.to = to + self.full = full if let prefix = currencies[from] { self.prefix = prefix @@ -48,6 +51,12 @@ class CurrencyBarItem: CustomButtonTouchBarItem { prefix = from } + if let postfix = currencies[to] { + self.postfix = postfix + } else { + postfix = to + } + super.init(identifier: identifier, title: "⏳") activity.repeats = true @@ -103,9 +112,15 @@ class CurrencyBarItem: CustomButtonTouchBarItem { color = NSColor.red } } + oldValue = value - let title = String(format: "%@%.2f", prefix, value) + var title = "" + if full { + title = String(format: "%@‣%.2f%@", prefix, value, postfix) + } else { + title = String(format: "%@%.2f", prefix, value) + } let regularFont = attributedTitle.attribute(.font, at: 0, effectiveRange: nil) as? NSFont ?? NSFont.systemFont(ofSize: 15) let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont]) diff --git a/README.md b/README.md index 1e7429e..0fe1fbc 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ To close a group, use the button: "align": "right", "from": "BTC", "to": "USD", + "full": true // £‣1.29$ ``` #### `music`