// // RootTouchBarController.swift // Underbar // // Created by Shadowfacts on 7/13/19. // Copyright © 2019 Shadowfacts. All rights reserved. // import Cocoa class RootTouchBarController: TouchBarController { let nowPlaying = NowPlayingItem(identifier: .nowPlaying) override init() { super.init() touchBar.defaultItemIdentifiers = [ .closeUnderbar, .flexibleSpace, .nowPlaying, ] } override func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { switch identifier { case .closeUnderbar: return createCloseItem() case .nowPlaying: return nowPlaying default: return super.touchBar(touchBar, makeItemForIdentifier: identifier) } } func createCloseItem() -> NSTouchBarItem { let item = NSCustomTouchBarItem(identifier: .closeUnderbar) let button = NSButton(image: NSImage(named: "underbar")!, target: self, action: #selector(toggle)) button.widthAnchor.constraint(equalToConstant: 40).isActive = true item.view = button return item } }