mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
time in separate file, divide bar in two parts
This commit is contained in:
parent
ee0eab6a76
commit
b3f461db45
@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */; };
|
||||
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D621205E03F5006E6B86 /* TouchBarController.swift */; };
|
||||
B059D624205E04F3006E6B86 /* TouchBarItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D623205E04F3006E6B86 /* TouchBarItems.swift */; };
|
||||
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B059D62C205F11E8006E6B86 /* DFRFoundation.framework */; };
|
||||
@ -41,6 +42,7 @@
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
36C2ECD2207B3B1D003CDA33 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeTouchBarItem.swift; sourceTree = "<group>"; };
|
||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarController.swift; sourceTree = "<group>"; };
|
||||
B059D623205E04F3006E6B86 /* TouchBarItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarItems.swift; sourceTree = "<group>"; };
|
||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarPrivateApi.h; sourceTree = "<group>"; };
|
||||
@ -132,6 +134,7 @@
|
||||
B082B256205C7D8000BC04DC /* Assets.xcassets */,
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||
B059D623205E04F3006E6B86 /* TouchBarItems.swift */,
|
||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */,
|
||||
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
||||
|
||||
25
MTMR/TimeTouchBarItem.swift
Normal file
25
MTMR/TimeTouchBarItem.swift
Normal file
@ -0,0 +1,25 @@
|
||||
import Cocoa
|
||||
|
||||
class TimeTouchBarItem: NSCustomTouchBarItem {
|
||||
private let dateFormatter = DateFormatter()
|
||||
private var timer: Timer!
|
||||
private let button = NSButton(title: "", target: nil, action: nil)
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String) {
|
||||
dateFormatter.setLocalizedDateFormatFromTemplate(formatTemplate)
|
||||
super.init(identifier: identifier)
|
||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
|
||||
self.view = button
|
||||
button.bezelColor = .clear
|
||||
updateTime()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func updateTime() {
|
||||
button.title = self.dateFormatter.string(from: Date())
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,9 +14,6 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
let touchBar = NSTouchBar()
|
||||
|
||||
var timer = Timer()
|
||||
var timeButton: NSButton = NSButton()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
touchBar.delegate = self
|
||||
@ -27,6 +24,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
.brightDown,
|
||||
.brightUp,
|
||||
|
||||
.flexibleSpace,
|
||||
|
||||
.prev,
|
||||
.play,
|
||||
.next,
|
||||
@ -48,7 +47,6 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
item.view = NSButton(image: #imageLiteral(resourceName: "Strip"), target: self, action: #selector(presentTouchBar))
|
||||
NSTouchBarItem.addSystemTrayItem(item)
|
||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
func updateControlStripPresence() {
|
||||
@ -90,28 +88,13 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "⏩", HIDKeycode: NX_KEYTYPE_NEXT)
|
||||
|
||||
case .time:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
timeButton = NSButton(title: self.getCurrentTime(), target: self, action: nil)
|
||||
item.view = timeButton
|
||||
return item
|
||||
return TimeTouchBarItem(identifier: identifier, formatTemplate: "HH:mm")
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func getCurrentTime() -> String {
|
||||
let date = Date()
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.setLocalizedDateFormatFromTemplate("HH:mm")
|
||||
let timestamp = dateFormatter.string(from: date)
|
||||
return timestamp
|
||||
}
|
||||
|
||||
@objc func updateTime() {
|
||||
timeButton.title = getCurrentTime()
|
||||
}
|
||||
|
||||
// func getBattery() {
|
||||
// var error: NSDictionary?
|
||||
// if let scriptObject = NSAppleScript(source: <#T##String#>) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user