mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
add locale to timeButton
This commit is contained in:
parent
29da70c477
commit
aa73fd1dc3
@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.23</string>
|
||||
<string>0.23.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>275</string>
|
||||
<string>278</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@ -344,7 +344,7 @@ enum ItemType: Decodable {
|
||||
case staticButton(title: String)
|
||||
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||
case timeButton(formatTemplate: String, timeZone: String?)
|
||||
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
|
||||
case battery()
|
||||
case dock(autoResize: Bool)
|
||||
case volume()
|
||||
@ -374,6 +374,7 @@ enum ItemType: Decodable {
|
||||
case api_key
|
||||
case icon_type
|
||||
case formatTemplate
|
||||
case locale
|
||||
case image
|
||||
case url
|
||||
case longUrl
|
||||
@ -428,7 +429,8 @@ enum ItemType: Decodable {
|
||||
case .timeButton:
|
||||
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
||||
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
|
||||
self = .timeButton(formatTemplate: template, timeZone: timeZone)
|
||||
let locale = try container.decodeIfPresent(String.self, forKey: .locale) ?? nil
|
||||
self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||
|
||||
case .battery:
|
||||
self = .battery()
|
||||
|
||||
@ -25,7 +25,7 @@ extension ItemType {
|
||||
return "com.toxblh.mtmr.appleScriptButton."
|
||||
case .shellScriptTitledButton(source: _):
|
||||
return "com.toxblh.mtmr.shellScriptButton."
|
||||
case .timeButton(formatTemplate: _, timeZone: _):
|
||||
case .timeButton(formatTemplate: _, timeZone: _, locale: _):
|
||||
return "com.toxblh.mtmr.timeButton."
|
||||
case .battery():
|
||||
return "com.toxblh.mtmr.battery."
|
||||
@ -255,8 +255,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
|
||||
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||
case let .timeButton(formatTemplate: template, timeZone: timeZone):
|
||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
|
||||
case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale):
|
||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||
case .battery():
|
||||
barItem = BatteryBarItem(identifier: identifier)
|
||||
case let .dock(autoResize: autoResize):
|
||||
|
||||
@ -4,8 +4,11 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
|
||||
private let dateFormatter = DateFormatter()
|
||||
private var timer: Timer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil) {
|
||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil, locale: String? = nil) {
|
||||
dateFormatter.dateFormat = formatTemplate
|
||||
if let locale = locale {
|
||||
dateFormatter.locale = Locale(identifier: locale)
|
||||
}
|
||||
if let abbr = timeZone {
|
||||
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
|
||||
}
|
||||
|
||||
@ -196,11 +196,14 @@ To close a group, use the button:
|
||||
#### `timeButton`
|
||||
|
||||
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
||||
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
|
||||
> locale examples: https://gist.github.com/jacobbubu/1836273
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "timeButton",
|
||||
"formatTemplate": "dd HH:mm",
|
||||
"locale": "en_GB",
|
||||
"timeZone": "UTC"
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user