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

Upd default. Readme. Fixed reload for central scroller.

This commit is contained in:
Toxblh 2018-04-21 01:43:37 +01:00
parent 9b86ed1dee
commit 4b39b000e0
6 changed files with 38 additions and 25 deletions

View File

@ -98,9 +98,9 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
if let oldValue = self.oldValue { if let oldValue = self.oldValue {
if oldValue < value { if oldValue < value {
color = NSColor(red: 95.0/255.0, green: 185.0/255.0, blue: 50.0/255.0, alpha: 1.0) color = NSColor.green
} else if oldValue > value { } else if oldValue > value {
color = NSColor(red: 185.0/255.0, green: 95.0/255.0, blue: 50.0/255.0, alpha: 1.0) color = NSColor.red
} }
} }
self.oldValue = value self.oldValue = value

View File

@ -208,7 +208,7 @@ enum ItemType: Decodable {
let icon_type = try container.decodeIfPresent(String.self, forKey: .icon_type) ?? "text" let icon_type = try container.decodeIfPresent(String.self, forKey: .icon_type) ?? "text"
self = .weather(interval: interval, units: units, api_key: api_key, icon_type: icon_type) self = .weather(interval: interval, units: units, api_key: api_key, icon_type: icon_type)
case .currency: case .currency:
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0 let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 600.0
let from = try container.decodeIfPresent(String.self, forKey: .from) ?? "RUB" let from = try container.decodeIfPresent(String.self, forKey: .from) ?? "RUB"
let to = try container.decodeIfPresent(String.self, forKey: .to) ?? "USD" let to = try container.decodeIfPresent(String.self, forKey: .to) ?? "USD"
self = .currency(interval: interval, from: from, to: to) self = .currency(interval: interval, from: from, to: to)

View File

@ -42,7 +42,6 @@ extension ItemType {
extension NSTouchBarItem.Identifier { extension NSTouchBarItem.Identifier {
static let controlStripItem = NSTouchBarItem.Identifier("com.toxblh.mtmr.controlStrip") static let controlStripItem = NSTouchBarItem.Identifier("com.toxblh.mtmr.controlStrip")
static let centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea")
} }
class TouchBarController: NSObject, NSTouchBarDelegate { class TouchBarController: NSObject, NSTouchBarDelegate {
@ -56,6 +55,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
var leftIdentifiers: [NSTouchBarItem.Identifier] = [] var leftIdentifiers: [NSTouchBarItem.Identifier] = []
var centerItems: [NSTouchBarItem] = [] var centerItems: [NSTouchBarItem] = []
var rightIdentifiers: [NSTouchBarItem.Identifier] = [] var rightIdentifiers: [NSTouchBarItem.Identifier] = []
var scrollArea: NSCustomTouchBarItem?
var centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
private override init() { private override init() {
super.init() super.init()
@ -83,8 +84,12 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
return definition.align == .center ? items[identifier] : nil return definition.align == .center ? items[identifier] : nil
} }
self.centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
self.scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
touchBar.delegate = self touchBar.delegate = self
touchBar.defaultItemIdentifiers = self.leftIdentifiers + [.centerScrollArea] + self.rightIdentifiers touchBar.defaultItemIdentifiers = []
touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers
self.presentTouchBar() self.presentTouchBar()
} }
@ -143,8 +148,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
} }
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
if identifier == .centerScrollArea { if identifier == centerScrollArea {
return ScrollViewItem(identifier: identifier, items: centerItems) return self.scrollArea
} }
guard let item = self.items[identifier], guard let item = self.items[identifier],

View File

@ -33,6 +33,10 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
units_str = "°C" units_str = "°C"
} }
if self.units == "imperial" {
units_str = "°F"
}
if icon_type == "images" { if icon_type == "images" {
iconsSource = iconsImages iconsSource = iconsImages
} else { } else {

View File

@ -66,8 +66,10 @@
{ "type": "previous", "width": 44 }, { "type": "previous", "width": 44 },
{ "type": "play", "width": 44 }, { "type": "play", "width": 44 },
{ "type": "next", "width": 44 }, { "type": "next", "width": 44 },
{ "type": "weather", "refreshInterval": 1800 }, { "type": "weather", "icon_type": "images", "units": "metric" },
{ "type": "currency", "from": "BTC", "to": "USD" },
{ "type": "sleep", "width": 44 }, { "type": "sleep", "width": 44 },
{ "type": "mute", "width": 40, "align": "right" },
{ "type": "volumeDown", "width": 34, "align": "right" }, { "type": "volumeDown", "width": 34, "align": "right" },
{ "type": "volume", "width": 60, "align": "right" }, { "type": "volume", "width": 60, "align": "right" },
{ "type": "volumeUp", "width": 34, "align": "right" }, { "type": "volumeUp", "width": 34, "align": "right" },

View File

@ -116,6 +116,8 @@ File for customize your preset for MTMR: `open ~/Library/Application\ Support/MT
"type": "weather", "type": "weather",
"refreshInterval": 600, "refreshInterval": 600,
"units": "metric", // or imperial "units": "metric", // or imperial
"icon_type": "text" // or images
"api_key": "" // you can get the key on openweather
``` ```
- `currency` - `currency`