mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
hacky solution to autohide if title is empty
This commit is contained in:
parent
ed14f34a2d
commit
d0cfa45b5d
@ -4,11 +4,13 @@ class AppleScriptTouchBarItem: NSCustomTouchBarItem {
|
||||
private var script: NSAppleScript!
|
||||
private let button = NSButton(title: "", target: nil, action: nil)
|
||||
private let interval: TimeInterval
|
||||
private var forceHideConstraint: NSLayoutConstraint!
|
||||
|
||||
init?(identifier: NSTouchBarItem.Identifier, source: Source, interval: TimeInterval) {
|
||||
self.interval = interval
|
||||
super.init(identifier: identifier)
|
||||
self.view = button
|
||||
self.forceHideConstraint = self.view.widthAnchor.constraint(equalToConstant: 0)
|
||||
guard let source = source.string else {
|
||||
button.title = "no script"
|
||||
return
|
||||
@ -42,12 +44,15 @@ class AppleScriptTouchBarItem: NSCustomTouchBarItem {
|
||||
let scriptResult = self.execute()
|
||||
DispatchQueue.main.async {
|
||||
self.button.title = scriptResult
|
||||
self.forceHideConstraint.isActive = scriptResult == ""
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + self.interval) { [weak self] in
|
||||
self?.refreshAndSchedule()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func execute() -> String {
|
||||
var error: NSDictionary?
|
||||
let output = script.executeAndReturnError(&error)
|
||||
@ -55,6 +60,7 @@ class AppleScriptTouchBarItem: NSCustomTouchBarItem {
|
||||
print(error)
|
||||
return "error"
|
||||
}
|
||||
return output.stringValue ?? "empty value"
|
||||
return output.stringValue ?? ""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user