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

added key full for currency widget.

This commit is contained in:
Toxblh 2019-01-21 19:59:10 +03:00
parent 560d8ed508
commit 1d1d666986
8 changed files with 57 additions and 38 deletions

View File

@ -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;

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1010"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.19</string>
<string>0.19.1</string>
<key>CFBundleVersion</key>
<string>112</string>
<string>125</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>

View File

@ -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()

View File

@ -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."
@ -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):

View File

@ -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])

View File

@ -137,6 +137,7 @@ To close a group, use the button:
"align": "right",
"from": "BTC",
"to": "USD",
"full": true // £‣1.29$
```
#### `music`