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>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.23</string>
|
<string>0.23.1</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>275</string>
|
<string>278</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@ -344,7 +344,7 @@ enum ItemType: Decodable {
|
|||||||
case staticButton(title: String)
|
case staticButton(title: String)
|
||||||
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||||
case shellScriptTitledButton(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 battery()
|
||||||
case dock(autoResize: Bool)
|
case dock(autoResize: Bool)
|
||||||
case volume()
|
case volume()
|
||||||
@ -374,6 +374,7 @@ enum ItemType: Decodable {
|
|||||||
case api_key
|
case api_key
|
||||||
case icon_type
|
case icon_type
|
||||||
case formatTemplate
|
case formatTemplate
|
||||||
|
case locale
|
||||||
case image
|
case image
|
||||||
case url
|
case url
|
||||||
case longUrl
|
case longUrl
|
||||||
@ -428,7 +429,8 @@ enum ItemType: Decodable {
|
|||||||
case .timeButton:
|
case .timeButton:
|
||||||
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
||||||
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
|
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:
|
case .battery:
|
||||||
self = .battery()
|
self = .battery()
|
||||||
|
|||||||
@ -25,7 +25,7 @@ extension ItemType {
|
|||||||
return "com.toxblh.mtmr.appleScriptButton."
|
return "com.toxblh.mtmr.appleScriptButton."
|
||||||
case .shellScriptTitledButton(source: _):
|
case .shellScriptTitledButton(source: _):
|
||||||
return "com.toxblh.mtmr.shellScriptButton."
|
return "com.toxblh.mtmr.shellScriptButton."
|
||||||
case .timeButton(formatTemplate: _, timeZone: _):
|
case .timeButton(formatTemplate: _, timeZone: _, locale: _):
|
||||||
return "com.toxblh.mtmr.timeButton."
|
return "com.toxblh.mtmr.timeButton."
|
||||||
case .battery():
|
case .battery():
|
||||||
return "com.toxblh.mtmr.battery."
|
return "com.toxblh.mtmr.battery."
|
||||||
@ -255,8 +255,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||||
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
|
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
|
||||||
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||||
case let .timeButton(formatTemplate: template, timeZone: timeZone):
|
case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale):
|
||||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
|
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||||
case .battery():
|
case .battery():
|
||||||
barItem = BatteryBarItem(identifier: identifier)
|
barItem = BatteryBarItem(identifier: identifier)
|
||||||
case let .dock(autoResize: autoResize):
|
case let .dock(autoResize: autoResize):
|
||||||
|
|||||||
@ -4,8 +4,11 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
private let dateFormatter = DateFormatter()
|
private let dateFormatter = DateFormatter()
|
||||||
private var timer: Timer!
|
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
|
dateFormatter.dateFormat = formatTemplate
|
||||||
|
if let locale = locale {
|
||||||
|
dateFormatter.locale = Locale(identifier: locale)
|
||||||
|
}
|
||||||
if let abbr = timeZone {
|
if let abbr = timeZone {
|
||||||
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
|
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,11 +196,14 @@ To close a group, use the button:
|
|||||||
#### `timeButton`
|
#### `timeButton`
|
||||||
|
|
||||||
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
> 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
|
```js
|
||||||
{
|
{
|
||||||
"type": "timeButton",
|
"type": "timeButton",
|
||||||
"formatTemplate": "dd HH:mm",
|
"formatTemplate": "dd HH:mm",
|
||||||
|
"locale": "en_GB",
|
||||||
"timeZone": "UTC"
|
"timeZone": "UTC"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user