Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
002af40756 | ||
|
|
285fb1fb85 | ||
|
|
1e07deedae | ||
|
|
a86d31b0ac | ||
|
|
0a0b393fb7 | ||
|
|
af83fa8a72 | ||
|
|
ab4aef4e2a | ||
|
|
e3f5da0294 | ||
|
|
aaa7bc33bc | ||
|
|
74d57cdc7d | ||
|
|
d48d590462 | ||
|
|
b3f461db45 | ||
|
|
ee0eab6a76 | ||
|
|
2dc1148a2a | ||
|
|
d12bdd2bd4 | ||
|
|
92b6e5ef33 | ||
|
|
d97d8efdd4 | ||
|
|
9f6f7d9404 | ||
|
|
528506f276 | ||
|
|
ce7c3c5883 | ||
|
|
3d3ad0f076 |
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Anton Palgunov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -7,6 +7,8 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */; };
|
||||
36C2ECD9207B74B4003CDA33 /* AppleScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.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 */; };
|
||||
@@ -17,6 +19,7 @@
|
||||
B082B266205C7D8000BC04DC /* MTMRTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B265205C7D8000BC04DC /* MTMRTests.swift */; };
|
||||
B082B271205C7D8000BC04DC /* MTMRUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B270205C7D8000BC04DC /* MTMRUITests.swift */; };
|
||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
||||
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0A8BF9D207B84160086F74D /* weather.scpt */; };
|
||||
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C1CFC9205C97D30021C862 /* WindowController.swift */; };
|
||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0F8771C207AD35400D6E430 /* battery.scpt */; };
|
||||
@@ -40,6 +43,9 @@
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* 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>"; };
|
||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScriptTouchBarItem.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>"; };
|
||||
@@ -59,6 +65,7 @@
|
||||
B082B270205C7D8000BC04DC /* MTMRUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTMRUITests.swift; sourceTree = "<group>"; };
|
||||
B082B272205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
||||
B0A8BF9D207B84160086F74D /* weather.scpt */ = {isa = PBXFileReference; lastKnownFileType = text; path = weather.scpt; sourceTree = "<group>"; };
|
||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = "<group>"; };
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||
@@ -102,6 +109,7 @@
|
||||
B082B246205C7D8000BC04DC = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
36C2ECD2207B3B1D003CDA33 /* README.md */,
|
||||
B082B251205C7D8000BC04DC /* MTMR */,
|
||||
B082B264205C7D8000BC04DC /* MTMRTests */,
|
||||
B082B26F205C7D8000BC04DC /* MTMRUITests */,
|
||||
@@ -130,6 +138,8 @@
|
||||
B082B256205C7D8000BC04DC /* Assets.xcassets */,
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||
B059D623205E04F3006E6B86 /* TouchBarItems.swift */,
|
||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */,
|
||||
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
||||
@@ -138,6 +148,7 @@
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
|
||||
B0F8771C207AD35400D6E430 /* battery.scpt */,
|
||||
B0A8BF9D207B84160086F74D /* weather.scpt */,
|
||||
);
|
||||
path = MTMR;
|
||||
sourceTree = "<group>";
|
||||
@@ -272,6 +283,7 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B0A8BF9E207B84160086F74D /* weather.scpt in Resources */,
|
||||
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
||||
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
||||
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */,
|
||||
@@ -300,12 +312,14 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */,
|
||||
36C2ECD9207B74B4003CDA33 /* AppleScriptTouchBarItem.swift in Sources */,
|
||||
B082B255205C7D8000BC04DC /* ViewController.swift in Sources */,
|
||||
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */,
|
||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||
B059D624205E04F3006E6B86 /* TouchBarItems.swift in Sources */,
|
||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
||||
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -402,7 +416,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12.2;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
@@ -455,7 +469,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12.2;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
|
||||
@@ -11,8 +11,6 @@ import Cocoa
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
TouchBarController.shared.setupControlStripPresence()
|
||||
// Insert code here to initialize your application
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
|
||||
class AppleScriptTouchBarItem: NSCustomTouchBarItem {
|
||||
let script: NSAppleScript
|
||||
private var timer: Timer!
|
||||
private let button = NSButton(title: "", target: nil, action: nil)
|
||||
|
||||
init?(identifier: NSTouchBarItem.Identifier, appleScript: String, interval: TimeInterval) {
|
||||
guard let script = NSAppleScript(source: appleScript) else {
|
||||
return nil
|
||||
}
|
||||
self.script = script
|
||||
super.init(identifier: identifier)
|
||||
timer = Timer.scheduledTimer(timeInterval: interval, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||
self.view = button
|
||||
button.bezelColor = .clear
|
||||
refresh()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func refresh() {
|
||||
self.button.title = self.execute()
|
||||
}
|
||||
|
||||
func execute() -> String {
|
||||
var error: NSDictionary?
|
||||
let output = script.executeAndReturnError(&error)
|
||||
if let error = error {
|
||||
print(error)
|
||||
return "error"
|
||||
}
|
||||
return output.stringValue ?? "empty value"
|
||||
}
|
||||
}
|
||||
@@ -1,53 +1,63 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-16.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-32.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-32.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-64.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-128.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-256.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-256.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-512.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-512.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "logo-1024.png",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
|
||||
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
@@ -30,11 +30,11 @@ struct ESCKeyPress: KeyPress {
|
||||
}
|
||||
|
||||
struct BrightnessUpPress: KeyPress {
|
||||
let keyCode: CGKeyCode = 107
|
||||
let keyCode: CGKeyCode = 113
|
||||
}
|
||||
|
||||
struct BrightnessDownPress: KeyPress {
|
||||
let keyCode: CGKeyCode = 113
|
||||
let keyCode: CGKeyCode = 107
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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,18 +14,18 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
let touchBar = NSTouchBar()
|
||||
|
||||
var timer = Timer()
|
||||
var timeButton: NSButton = NSButton()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
touchBar.delegate = self
|
||||
touchBar.defaultItemIdentifiers = [
|
||||
.escButton,
|
||||
.dismissButton,
|
||||
|
||||
.brightDown,
|
||||
.brightUp,
|
||||
|
||||
.flexibleSpace,
|
||||
|
||||
.prev,
|
||||
.play,
|
||||
.next,
|
||||
@@ -47,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() {
|
||||
@@ -55,123 +54,79 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}
|
||||
|
||||
@objc private func presentTouchBar() {
|
||||
NSTouchBar.presentSystemModalFunctionBar(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||
NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||
}
|
||||
|
||||
private func dismissTouchBar() {
|
||||
@objc private func dismissTouchBar() {
|
||||
NSTouchBar.minimizeSystemModalFunctionBar(touchBar)
|
||||
}
|
||||
|
||||
@objc func goToSleep() {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/pmset"
|
||||
task.arguments = ["sleepnow"]
|
||||
task.launch()
|
||||
}
|
||||
|
||||
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
||||
switch identifier {
|
||||
case .escButton:
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "esc", key: ESCKeyPress())
|
||||
case .dismissButton:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "esc", target: self, action: #selector(handleEsc))
|
||||
item.view = NSButton(title: "exit", target: self, action: #selector(dismissTouchBar))
|
||||
return item
|
||||
|
||||
case .brightUp:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "🔆", target: self, action: #selector(handleBrightUp))
|
||||
return item
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "🔆", key: BrightnessUpPress())
|
||||
case .brightDown:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "🔅", target: self, action: #selector(handleBrightDown))
|
||||
return item
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "🔅", key: BrightnessDownPress())
|
||||
|
||||
case .volumeDown:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "🔉", target: self, action: #selector(handleVolumeDown))
|
||||
return item
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "🔉", HIDKeycode: NX_KEYTYPE_SOUND_DOWN)
|
||||
case .volumeUp:
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "🔊", HIDKeycode: NX_KEYTYPE_SOUND_UP)
|
||||
|
||||
case .weather:
|
||||
let url = Bundle.main.url(forResource: "weather", withExtension: "scpt")!
|
||||
let script = try! String.init(contentsOf: url)
|
||||
return AppleScriptTouchBarItem(identifier: identifier, appleScript: script, interval: 600)
|
||||
|
||||
case .sleep:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "🔊", target: self, action: #selector(handleVolumeUp))
|
||||
item.view = NSButton(title: "☕️", target: self, action: #selector(goToSleep))
|
||||
return item
|
||||
|
||||
// case .prev:
|
||||
// let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
// item.view = NSButton(title: "⏪", target: self, action: #selector(handlePrev))
|
||||
// return item
|
||||
case .prev:
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "⏪", HIDKeycode: NX_KEYTYPE_PREVIOUS)
|
||||
case .play:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "⏯", target: self, action: #selector(handlePlay))
|
||||
return item
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "⏯", HIDKeycode: NX_KEYTYPE_PLAY)
|
||||
case .next:
|
||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||
item.view = NSButton(title: "⏩", target: self, action: #selector(handleNext))
|
||||
return item
|
||||
return CustomButtonTouchBarItem(identifier: identifier, title: "⏩", HIDKeycode: NX_KEYTYPE_NEXT)
|
||||
|
||||
case .battery:
|
||||
let url = Bundle.main.url(forResource: "battery", withExtension: "scpt")!
|
||||
let script = try! String.init(contentsOf: url)
|
||||
return AppleScriptTouchBarItem(identifier: identifier, appleScript: script, interval: 60)
|
||||
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()
|
||||
}
|
||||
|
||||
@objc func handleEsc() {
|
||||
let sender = ESCKeyPress()
|
||||
sender.send()
|
||||
}
|
||||
|
||||
@objc func handleVolumeUp() {
|
||||
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_UP))
|
||||
}
|
||||
|
||||
@objc func handleVolumeDown() {
|
||||
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_DOWN))
|
||||
}
|
||||
|
||||
@objc func handleBrightDown() {
|
||||
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_DOWN))
|
||||
|
||||
let sender = BrightnessUpPress()
|
||||
sender.send()
|
||||
}
|
||||
|
||||
@objc func handleBrightUp() {
|
||||
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_UP))
|
||||
|
||||
let sender = BrightnessDownPress()
|
||||
sender.send()
|
||||
}
|
||||
|
||||
@objc func handlePrev() {
|
||||
HIDPostAuxKey(Int(NX_KEYTYPE_PREVIOUS))
|
||||
}
|
||||
|
||||
@objc func handlePlay() {
|
||||
HIDPostAuxKey(Int(NX_KEYTYPE_PLAY))
|
||||
}
|
||||
|
||||
@objc func handleNext() {
|
||||
HIDPostAuxKey(Int(NX_KEYTYPE_NEXT))
|
||||
}
|
||||
|
||||
// func getBattery() {
|
||||
// var error: NSDictionary?
|
||||
// if let scriptObject = NSAppleScript(source: <#T##String#>) {
|
||||
// if let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(
|
||||
// &error) {
|
||||
// print(output.stringValue)
|
||||
// } else if (error != nil) {
|
||||
// print("error: \(error)")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
extension CustomButtonTouchBarItem {
|
||||
convenience init(identifier: NSTouchBarItem.Identifier, title: String, HIDKeycode: Int) {
|
||||
self.init(identifier: identifier, title: title) { _ in
|
||||
HIDPostAuxKey(HIDKeycode)
|
||||
}
|
||||
}
|
||||
convenience init(identifier: NSTouchBarItem.Identifier, title: String, key: KeyPress) {
|
||||
self.init(identifier: identifier, title: title) { _ in
|
||||
key.send()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import Cocoa
|
||||
|
||||
extension NSTouchBarItem.Identifier {
|
||||
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
|
||||
static let dismissButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.dismissButton")
|
||||
|
||||
// Volume
|
||||
static let volumeUp = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeUp")
|
||||
@@ -33,3 +34,22 @@ extension NSTouchBarItem.Identifier {
|
||||
|
||||
static let controlStripItem = NSTouchBarItem.Identifier("com.toxblh.mtmr.controlStrip")
|
||||
}
|
||||
|
||||
class CustomButtonTouchBarItem: NSCustomTouchBarItem {
|
||||
let tapClosure: (NSCustomTouchBarItem) -> ()
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, title: String, onTap callback: @escaping (NSCustomTouchBarItem) -> ()) {
|
||||
self.tapClosure = callback
|
||||
super.init(identifier: identifier)
|
||||
self.view = NSButton(title: title, target: self, action: #selector(didTapped))
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func didTapped() {
|
||||
self.tapClosure(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# This script requires two libs. Download them:
|
||||
# https://itunes.apple.com/ru/app/json-helper-for-applescript/id453114608?l=en&mt=12
|
||||
# https://itunes.apple.com/ru/app/location-helper-for-applescript/id488536386?mt=12
|
||||
tell application "Location Helper"
|
||||
set clocation_coords to get location coordinates
|
||||
tell application "JSON Helper"
|
||||
set weather to fetch JSON from "http://api.openweathermap.org/data/2.5/weather?lat=" & item 1 of clocation_coords & "&lon=" & item 2 of clocation_coords & "&units=metric&appid=32c4256d09a4c52b38aecddba7a078f6"
|
||||
set temp to temp of main of weather as string
|
||||
set cond_icon to icon of item 1 of weather of weather as string
|
||||
if cond_icon is in ["01d", "01n"] then
|
||||
set cond to "☀️"
|
||||
else if cond_icon is in ["02d", "02n"] then
|
||||
set cond to "⛅️"
|
||||
else if cond_icon is in ["03d", "03n", "04d", "04n"] then
|
||||
set cond to "☁️"
|
||||
else if cond_icon is in ["09d", "09n"] then
|
||||
set cond to "🌧"
|
||||
else if cond_icon is in ["10d", "10n"] then
|
||||
set cond to "🌦"
|
||||
else if cond_icon is in ["11d", "11n"] then
|
||||
set cond to "🌩"
|
||||
else if cond_icon is in ["13d", "13n"] then
|
||||
set cond to "❄️"
|
||||
else if cond_icon is in ["50d", "50n"] then
|
||||
set cond to "🌫"
|
||||
else
|
||||
set cond to ""
|
||||
end if
|
||||
set temp_round to round (temp * 1.0)
|
||||
return cond & " " & temp_round & "°C"
|
||||
end tell
|
||||
end tell
|
||||
@@ -5,18 +5,32 @@
|
||||
# My TouchBar. My rules
|
||||
|
||||
<p align="center">
|
||||
<img src="Resources/TouchBarV0.1.png">
|
||||
<img src="Resources/TouchBar-v0.3.png">
|
||||
</p>
|
||||
|
||||
My the idea is to create the program like a platform for plugins for customization TouchBar. I very like BTT and a full custom TouchBar. And I want to create it. And it's my the first Swift project for MacOS :)
|
||||
My the idea is to create the program like a platform for plugins for customization TouchBar. I very like BTT and a full custom TouchBar (my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)). And I want to create it. And it's my the first Swift project for MacOS :)
|
||||
|
||||
### Roadmap
|
||||
- [x] Create the first prototype with TouchBar in Storyboard
|
||||
- [x] Put in stripe menu on startup the application
|
||||
- [x] Find how to simulate real buttons like brightness, volume, night shift and etc.
|
||||
- [x] Time in touchbar!
|
||||
- [ ] First the weather plugin
|
||||
- [ ] Create the same panel like in my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)
|
||||
- [ ] Find how to open full-screen TouchBar without the cross and stripe menu
|
||||
- [x] First the weather plugin
|
||||
- [x] Find how to open full-screen TouchBar without the cross and stripe menu
|
||||
- [ ] Find how to add haptic feedback
|
||||
- [ ] JSON or another approch for save preset and plugins maybe in `~/mtmr`
|
||||
- [ ] Layout: [always left, NSSliderView for center, always right]
|
||||
- [ ] Custom buttons size, actions by click in settings
|
||||
- [ ] Add icon and menu in StatusBar
|
||||
- [ ] Hide from Dock
|
||||
- [ ] Status menu: "preferences", "quit"
|
||||
|
||||
Settings:
|
||||
- [ ] Intarface for plugins and export like presets
|
||||
- [ ] Startup at login
|
||||
- [ ] Show on/off in Dock
|
||||
- [ ] Show on/off in StatusBar
|
||||
- [ ] On/off Haptic Feedback
|
||||
|
||||
Maybe:
|
||||
- [ ] Refactoring the application on packages (AppleScript, JavaScript? and Swift?)
|
||||
|
||||
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 29 KiB |