mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
added key full for currency widget.
This commit is contained in:
parent
560d8ed508
commit
1d1d666986
@ -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;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1000"
|
||||
LastUpgradeVersion = "1010"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1000"
|
||||
LastUpgradeVersion = "1010"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user