Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd99e9d73d | ||
|
|
58beb5a213 | ||
|
|
7da9ca2c68 | ||
|
|
88a4ce82db | ||
|
|
d39b4c0c31 | ||
|
|
5e609c2446 | ||
|
|
14301c4dbd | ||
|
|
a879498e4c | ||
|
|
36bf749a46 | ||
|
|
ac0e44db4d | ||
|
|
26ad83be70 | ||
|
|
d199bbd852 | ||
|
|
352bf4887c | ||
|
|
211ca4be32 | ||
|
|
d270a7bbcd | ||
|
|
44732e8ad6 | ||
|
|
8c57342070 | ||
|
|
3add660d72 | ||
|
|
eb617ff31b | ||
| 3e82676008 | |||
| a2ad47c7ba | |||
| bbe901a572 | |||
| 54eaa3fd9f | |||
|
|
6660bb2d8f | ||
|
|
7a1800252c | ||
|
|
588e6ae09b | ||
|
|
87141e381b | ||
|
|
14282b86a9 | ||
|
|
810cdeed36 | ||
|
|
a65613acaf | ||
|
|
aa69d5f592 | ||
|
|
2f00c9ffb3 | ||
|
|
1def53878d | ||
| 3e5fa14494 | |||
|
|
2e2f556daf |
2
.github/FUNDING.yml
vendored
@ -3,4 +3,4 @@
|
|||||||
issuehunt: Toxblh
|
issuehunt: Toxblh
|
||||||
patreon: toxblh
|
patreon: toxblh
|
||||||
ko_fi: toxblh
|
ko_fi: toxblh
|
||||||
custom: https://www.paypal.me/toxblh
|
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WUAAG2HH58WE4
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FEF871235A1CFC00A0ABCE /* AppSettings.swift */; };
|
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FEF871235A1CFC00A0ABCE /* AppSettings.swift */; };
|
||||||
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */; };
|
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */; };
|
||||||
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */; };
|
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */; };
|
||||||
|
4CF222EB26CC00470025BDA7 /* CPUBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */; };
|
||||||
|
4CF222ED26CC43D50025BDA7 /* CPU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF222EC26CC43D40025BDA7 /* CPU.swift */; };
|
||||||
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */; };
|
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */; };
|
||||||
5DC6CA02241F92CB005CD5E8 /* Music.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */; };
|
5DC6CA02241F92CB005CD5E8 /* Music.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */; };
|
||||||
5DC6CA03241F92CB005CD5E8 /* Music.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */; };
|
5DC6CA03241F92CB005CD5E8 /* Music.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */; };
|
||||||
@ -71,6 +73,7 @@
|
|||||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||||
BAF5AB5724317B4300B04904 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5624317B4300B04904 /* BasicView.swift */; };
|
BAF5AB5724317B4300B04904 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5624317B4300B04904 /* BasicView.swift */; };
|
||||||
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5824317CAF00B04904 /* SwipeItem.swift */; };
|
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5824317CAF00B04904 /* SwipeItem.swift */; };
|
||||||
|
F29F6A2524BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
@ -103,6 +106,8 @@
|
|||||||
4CC9FEDA22FDEA65001512EB /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = "<group>"; };
|
4CC9FEDA22FDEA65001512EB /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = "<group>"; };
|
||||||
4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = "<group>"; };
|
4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = "<group>"; };
|
||||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellScriptTouchBarItem.swift; sourceTree = "<group>"; };
|
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellScriptTouchBarItem.swift; sourceTree = "<group>"; };
|
||||||
|
4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPUBarItem.swift; sourceTree = "<group>"; };
|
||||||
|
4CF222EC26CC43D40025BDA7 /* CPU.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPU.swift; sourceTree = "<group>"; };
|
||||||
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YandexWeatherBarItem.swift; sourceTree = "<group>"; };
|
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YandexWeatherBarItem.swift; sourceTree = "<group>"; };
|
||||||
5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.nowPlaying.scpt; sourceTree = "<group>"; };
|
5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||||
5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.next.scpt; sourceTree = "<group>"; };
|
5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.next.scpt; sourceTree = "<group>"; };
|
||||||
@ -163,6 +168,7 @@
|
|||||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||||
BAF5AB5624317B4300B04904 /* BasicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = "<group>"; };
|
BAF5AB5624317B4300B04904 /* BasicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = "<group>"; };
|
||||||
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeItem.swift; sourceTree = "<group>"; };
|
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeItem.swift; sourceTree = "<group>"; };
|
||||||
|
F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpNextScrubberTouchBarItem.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -237,6 +243,7 @@
|
|||||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||||
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */,
|
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */,
|
||||||
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
||||||
|
4CF222EC26CC43D40025BDA7 /* CPU.swift */,
|
||||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||||
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */,
|
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */,
|
||||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */,
|
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */,
|
||||||
@ -308,6 +315,7 @@
|
|||||||
6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */,
|
6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */,
|
||||||
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */,
|
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */,
|
||||||
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */,
|
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */,
|
||||||
|
4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */,
|
||||||
607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */,
|
607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */,
|
||||||
B081732B213739FE005D4908 /* DnDBarItem.swift */,
|
B081732B213739FE005D4908 /* DnDBarItem.swift */,
|
||||||
60669B4220AD8FA80074E817 /* GroupBarItem.swift */,
|
60669B4220AD8FA80074E817 /* GroupBarItem.swift */,
|
||||||
@ -322,6 +330,7 @@
|
|||||||
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */,
|
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */,
|
||||||
B08126F0217BE19000A98970 /* WidgetProtocol.swift */,
|
B08126F0217BE19000A98970 /* WidgetProtocol.swift */,
|
||||||
B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */,
|
B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */,
|
||||||
|
F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */,
|
||||||
);
|
);
|
||||||
path = Widgets;
|
path = Widgets;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -475,12 +484,14 @@
|
|||||||
B0846A752220C968000288A7 /* NetworkBarItem.swift in Sources */,
|
B0846A752220C968000288A7 /* NetworkBarItem.swift in Sources */,
|
||||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
||||||
B08126F1217BE19000A98970 /* WidgetProtocol.swift in Sources */,
|
B08126F1217BE19000A98970 /* WidgetProtocol.swift in Sources */,
|
||||||
|
4CF222EB26CC00470025BDA7 /* CPUBarItem.swift in Sources */,
|
||||||
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */,
|
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */,
|
||||||
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */,
|
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */,
|
||||||
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */,
|
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */,
|
||||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||||
B0F54A7A2295AC7D00B4C509 /* DarkModeBarItem.swift in Sources */,
|
B0F54A7A2295AC7D00B4C509 /* DarkModeBarItem.swift in Sources */,
|
||||||
B08126EF217BD0B900A98970 /* PomodoroBarItem.swift in Sources */,
|
B08126EF217BD0B900A98970 /* PomodoroBarItem.swift in Sources */,
|
||||||
|
4CF222ED26CC43D50025BDA7 /* CPU.swift in Sources */,
|
||||||
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */,
|
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */,
|
||||||
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
||||||
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
||||||
@ -488,6 +499,7 @@
|
|||||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
||||||
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */,
|
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */,
|
||||||
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
||||||
|
F29F6A2524BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift in Sources */,
|
||||||
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
|
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
|
||||||
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */,
|
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */,
|
||||||
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
||||||
|
|||||||
@ -25,7 +25,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
|
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
|
||||||
|
|
||||||
TouchBarController.shared.setupControlStripPresence()
|
TouchBarController.shared.setupControlStripPresence()
|
||||||
HapticFeedbackUpdate()
|
|
||||||
|
|
||||||
if let button = statusItem.button {
|
if let button = statusItem.button {
|
||||||
button.image = #imageLiteral(resourceName: "StatusImage")
|
button.image = #imageLiteral(resourceName: "StatusImage")
|
||||||
@ -41,10 +40,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
func applicationWillTerminate(_: Notification) {}
|
func applicationWillTerminate(_: Notification) {}
|
||||||
|
|
||||||
func HapticFeedbackUpdate() {
|
|
||||||
HapticFeedback.shared = AppSettings.hapticFeedbackState ? HapticFeedback() : nil
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func updateIsBlockedApp() {
|
@objc func updateIsBlockedApp() {
|
||||||
if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
|
if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||||
isBlockedApp = AppSettings.blacklistedAppIds.firstIndex(of: frontmostAppId) != nil
|
isBlockedApp = AppSettings.blacklistedAppIds.firstIndex(of: frontmostAppId) != nil
|
||||||
@ -86,7 +81,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
@objc func toggleHapticFeedback(_ item: NSMenuItem) {
|
@objc func toggleHapticFeedback(_ item: NSMenuItem) {
|
||||||
item.state = item.state == .on ? .off : .on
|
item.state = item.state == .on ? .off : .on
|
||||||
AppSettings.hapticFeedbackState = item.state == .on
|
AppSettings.hapticFeedbackState = item.state == .on
|
||||||
HapticFeedbackUpdate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func toggleMultitouch(_ item: NSMenuItem) {
|
@objc func toggleMultitouch(_ item: NSMenuItem) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 667 B |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 2.7 KiB |
21
MTMR/Assets.xcassets/cpu.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "cpu.png",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
MTMR/Assets.xcassets/cpu.imageset/cpu.png
vendored
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
@ -15,41 +15,41 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
|||||||
var fourfingers: NSPanGestureRecognizer!
|
var fourfingers: NSPanGestureRecognizer!
|
||||||
var swipeItems: [SwipeItem] = []
|
var swipeItems: [SwipeItem] = []
|
||||||
var prevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
var prevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
||||||
|
|
||||||
// legacy gesture positions
|
// legacy gesture positions
|
||||||
// by legacy I mean gestures to increse/decrease volume/brigtness which can be checked from app menu
|
// by legacy I mean gestures to increse/decrease volume/brigtness which can be checked from app menu
|
||||||
var legacyPrevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
var legacyPrevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
||||||
var legacyGesturesEnabled = false
|
var legacyGesturesEnabled = false
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem], swipeItems: [SwipeItem]) {
|
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem], swipeItems: [SwipeItem]) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
self.swipeItems = swipeItems
|
self.swipeItems = swipeItems
|
||||||
let views = items.compactMap { $0.view }
|
let views = items.compactMap { $0.view }
|
||||||
let stackView = NSStackView(views: views)
|
let stackView = NSStackView(views: views)
|
||||||
stackView.spacing = 1
|
stackView.spacing = 8
|
||||||
stackView.orientation = .horizontal
|
stackView.orientation = .horizontal
|
||||||
view = stackView
|
view = stackView
|
||||||
|
|
||||||
twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||||
twofingers.numberOfTouchesRequired = 2
|
twofingers.numberOfTouchesRequired = 2
|
||||||
twofingers.allowedTouchTypes = .direct
|
twofingers.allowedTouchTypes = .direct
|
||||||
view.addGestureRecognizer(twofingers)
|
view.addGestureRecognizer(twofingers)
|
||||||
|
|
||||||
threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||||
threefingers.numberOfTouchesRequired = 3
|
threefingers.numberOfTouchesRequired = 3
|
||||||
threefingers.allowedTouchTypes = .direct
|
threefingers.allowedTouchTypes = .direct
|
||||||
view.addGestureRecognizer(threefingers)
|
view.addGestureRecognizer(threefingers)
|
||||||
|
|
||||||
fourfingers = NSPanGestureRecognizer(target: self, action: #selector(fourfingersHandler(_:)))
|
fourfingers = NSPanGestureRecognizer(target: self, action: #selector(fourfingersHandler(_:)))
|
||||||
fourfingers.numberOfTouchesRequired = 4
|
fourfingers.numberOfTouchesRequired = 4
|
||||||
fourfingers.allowedTouchTypes = .direct
|
fourfingers.allowedTouchTypes = .direct
|
||||||
view.addGestureRecognizer(fourfingers)
|
view.addGestureRecognizer(fourfingers)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder _: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func gestureHandler(position: CGFloat, fingers: Int, state: NSGestureRecognizer.State) {
|
func gestureHandler(position: CGFloat, fingers: Int, state: NSGestureRecognizer.State) {
|
||||||
switch state {
|
switch state {
|
||||||
case .began:
|
case .began:
|
||||||
@ -72,9 +72,9 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
|||||||
let prevPos = legacyPrevPositions[fingers]!
|
let prevPos = legacyPrevPositions[fingers]!
|
||||||
if ((position - prevPos) > 15) || ((prevPos - position) > 15) {
|
if ((position - prevPos) > 15) || ((prevPos - position) > 15) {
|
||||||
if position > prevPos {
|
if position > prevPos {
|
||||||
GenericKeyPress(keyCode: CGKeyCode(144)).send()
|
HIDPostAuxKey(NX_KEYTYPE_BRIGHTNESS_UP)
|
||||||
} else if position < prevPos {
|
} else if position < prevPos {
|
||||||
GenericKeyPress(keyCode: CGKeyCode(145)).send()
|
HIDPostAuxKey(NX_KEYTYPE_BRIGHTNESS_DOWN)
|
||||||
}
|
}
|
||||||
legacyPrevPositions[fingers] = position
|
legacyPrevPositions[fingers] = position
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func twofingersHandler(_ sender: NSGestureRecognizer?) {
|
@objc func twofingersHandler(_ sender: NSGestureRecognizer?) {
|
||||||
let position = (sender?.location(in: sender?.view).x)!
|
let position = (sender?.location(in: sender?.view).x)!
|
||||||
self.gestureHandler(position: position, fingers: 2, state: sender!.state)
|
self.gestureHandler(position: position, fingers: 2, state: sender!.state)
|
||||||
|
|||||||
191
MTMR/CPU.swift
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
//
|
||||||
|
// CPU.swift
|
||||||
|
// Pods
|
||||||
|
//
|
||||||
|
// Created by zixun on 2016/12/5.
|
||||||
|
// https://github.com/zixun/SystemEye
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
private let HOST_CPU_LOAD_INFO_COUNT : mach_msg_type_number_t =
|
||||||
|
UInt32(MemoryLayout<host_cpu_load_info_data_t>.size / MemoryLayout<integer_t>.size)
|
||||||
|
|
||||||
|
/// CPU Class
|
||||||
|
public class CPU: NSObject {
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: OPEN PROPERTY
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// /// Number of physical cores on this machine.
|
||||||
|
// public static var physicalCores: Int {
|
||||||
|
// get {
|
||||||
|
// return Int(System.hostBasicInfo.physical_cpu)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /// Number of logical cores on this machine. Will be equal to physicalCores
|
||||||
|
// /// unless it has hyper-threading, in which case it will be double.
|
||||||
|
// public static var logicalCores: Int {
|
||||||
|
// get {
|
||||||
|
// return Int(System.hostBasicInfo.logical_cpu)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: OPEN FUNCTIONS
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Get CPU usage of hole system (system, user, idle, nice). Determined by the delta between
|
||||||
|
/// the current and last call.
|
||||||
|
public static func systemUsage() -> (system: Double,
|
||||||
|
user: Double,
|
||||||
|
idle: Double,
|
||||||
|
nice: Double) {
|
||||||
|
let load = self.hostCPULoadInfo
|
||||||
|
|
||||||
|
let userDiff = Double(load.cpu_ticks.0 - loadPrevious.cpu_ticks.0)
|
||||||
|
let sysDiff = Double(load.cpu_ticks.1 - loadPrevious.cpu_ticks.1)
|
||||||
|
let idleDiff = Double(load.cpu_ticks.2 - loadPrevious.cpu_ticks.2)
|
||||||
|
let niceDiff = Double(load.cpu_ticks.3 - loadPrevious.cpu_ticks.3)
|
||||||
|
|
||||||
|
let totalTicks = sysDiff + userDiff + niceDiff + idleDiff
|
||||||
|
|
||||||
|
let sys = sysDiff / totalTicks * 100.0
|
||||||
|
let user = userDiff / totalTicks * 100.0
|
||||||
|
let idle = idleDiff / totalTicks * 100.0
|
||||||
|
let nice = niceDiff / totalTicks * 100.0
|
||||||
|
|
||||||
|
loadPrevious = load
|
||||||
|
|
||||||
|
return (sys, user, idle, nice)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Get CPU usage of application,get from all thread
|
||||||
|
open class func applicationUsage() -> Double {
|
||||||
|
let threads = self.threadBasicInfos()
|
||||||
|
var result : Double = 0.0
|
||||||
|
threads.forEach { (thread:thread_basic_info) in
|
||||||
|
if self.flag(thread) {
|
||||||
|
result += Double.init(thread.cpu_usage) / Double.init(TH_USAGE_SCALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: PRIVATE PROPERTY
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// previous load of cpu
|
||||||
|
private static var loadPrevious = host_cpu_load_info()
|
||||||
|
|
||||||
|
static var hostCPULoadInfo: host_cpu_load_info {
|
||||||
|
get {
|
||||||
|
var size = HOST_CPU_LOAD_INFO_COUNT
|
||||||
|
var hostInfo = host_cpu_load_info()
|
||||||
|
let result = withUnsafeMutablePointer(to: &hostInfo) {
|
||||||
|
$0.withMemoryRebound(to: integer_t.self, capacity: Int(size)) {
|
||||||
|
host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, $0, &size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
if result != KERN_SUCCESS {
|
||||||
|
fatalError("ERROR - \(#file):\(#function) - kern_result_t = "
|
||||||
|
+ "\(result)")
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return hostInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: PRIVATE FUNCTION
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private class func flag(_ thread:thread_basic_info) -> Bool {
|
||||||
|
let foo = thread.flags & TH_FLAGS_IDLE
|
||||||
|
let number = NSNumber.init(value: foo)
|
||||||
|
return !Bool.init(truncating: number)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class func threadActPointers() -> [thread_act_t] {
|
||||||
|
var threads_act = [thread_act_t]()
|
||||||
|
|
||||||
|
var threads_array: thread_act_array_t? = nil
|
||||||
|
var count = mach_msg_type_number_t()
|
||||||
|
|
||||||
|
let result = task_threads(mach_task_self_, &(threads_array), &count)
|
||||||
|
|
||||||
|
guard result == KERN_SUCCESS else {
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let array = threads_array else {
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..<count {
|
||||||
|
threads_act.append(array[Int(i)])
|
||||||
|
}
|
||||||
|
|
||||||
|
let krsize = count * UInt32.init(MemoryLayout<thread_t>.size)
|
||||||
|
_ = vm_deallocate(mach_task_self_, vm_address_t(array.pointee), vm_size_t(krsize));
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
private class func threadBasicInfos() -> [thread_basic_info] {
|
||||||
|
var result = [thread_basic_info]()
|
||||||
|
|
||||||
|
let thinfo : thread_info_t = thread_info_t.allocate(capacity: Int(THREAD_INFO_MAX))
|
||||||
|
let thread_info_count = UnsafeMutablePointer<mach_msg_type_number_t>.allocate(capacity: 128)
|
||||||
|
var basic_info_th: thread_basic_info_t? = nil
|
||||||
|
|
||||||
|
for act_t in self.threadActPointers() {
|
||||||
|
thread_info_count.pointee = UInt32(THREAD_INFO_MAX);
|
||||||
|
let kr = thread_info(act_t ,thread_flavor_t(THREAD_BASIC_INFO),thinfo, thread_info_count);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
return [thread_basic_info]();
|
||||||
|
}
|
||||||
|
basic_info_th = withUnsafePointer(to: &thinfo.pointee, { (ptr) -> thread_basic_info_t in
|
||||||
|
let int8Ptr = unsafeBitCast(ptr, to: thread_basic_info_t.self)
|
||||||
|
return int8Ptr
|
||||||
|
})
|
||||||
|
if basic_info_th != nil {
|
||||||
|
result.append(basic_info_th!.pointee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: this function is used for get cpu usage of all thread,and this is in developing
|
||||||
|
private class func threadIdentifierInfos() -> [thread_identifier_info] {
|
||||||
|
var result = [thread_identifier_info]()
|
||||||
|
let thinfo : thread_info_t = thread_info_t.allocate(capacity: Int(THREAD_INFO_MAX))
|
||||||
|
let thread_info_count = UnsafeMutablePointer<mach_msg_type_number_t>.allocate(capacity: 128)
|
||||||
|
var identifier_info_th: thread_identifier_info_t? = nil
|
||||||
|
|
||||||
|
for act_t in self.threadActPointers() {
|
||||||
|
thread_info_count.pointee = UInt32(THREAD_INFO_MAX);
|
||||||
|
let kr = thread_info(act_t ,thread_flavor_t(THREAD_IDENTIFIER_INFO),thinfo, thread_info_count);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
return [thread_identifier_info]();
|
||||||
|
}
|
||||||
|
identifier_info_th = withUnsafePointer(to: &thinfo.pointee, { (ptr) -> thread_identifier_info_t in
|
||||||
|
let int8Ptr = unsafeBitCast(ptr, to: thread_identifier_info_t.self)
|
||||||
|
return int8Ptr
|
||||||
|
})
|
||||||
|
if identifier_info_th != nil {
|
||||||
|
result.append(identifier_info_th!.pointee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,18 +8,32 @@
|
|||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
|
struct ItemAction {
|
||||||
|
typealias TriggerClosure = (() -> Void)?
|
||||||
|
|
||||||
|
let trigger: Action.Trigger
|
||||||
|
let closure: TriggerClosure
|
||||||
|
|
||||||
|
init(trigger: Action.Trigger, _ closure: TriggerClosure) {
|
||||||
|
self.trigger = trigger
|
||||||
|
self.closure = closure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||||
var tapClosure: (() -> Void)?
|
|
||||||
var longTapClosure: (() -> Void)? {
|
var actions: [ItemAction] = [] {
|
||||||
didSet {
|
didSet {
|
||||||
longClick.isEnabled = longTapClosure != nil
|
multiClick.isDoubleClickEnabled = actions.filter({ $0.trigger == .doubleTap }).count > 0
|
||||||
|
multiClick.isTripleClickEnabled = actions.filter({ $0.trigger == .tripleTap }).count > 0
|
||||||
|
longClick.isEnabled = actions.filter({ $0.trigger == .longTap }).count > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var finishViewConfiguration: ()->() = {}
|
var finishViewConfiguration: ()->() = {}
|
||||||
|
|
||||||
private var button: NSButton!
|
private var button: NSButton!
|
||||||
private var singleClick: HapticClickGestureRecognizer!
|
|
||||||
private var longClick: LongPressGestureRecognizer!
|
private var longClick: LongPressGestureRecognizer!
|
||||||
|
private var multiClick: MultiClickGestureRecognizer!
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, title: String) {
|
init(identifier: NSTouchBarItem.Identifier, title: String) {
|
||||||
attributedTitle = title.defaultTouchbarAttributedString
|
attributedTitle = title.defaultTouchbarAttributedString
|
||||||
@ -31,10 +45,17 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
longClick.isEnabled = false
|
longClick.isEnabled = false
|
||||||
longClick.allowedTouchTypes = .direct
|
longClick.allowedTouchTypes = .direct
|
||||||
longClick.delegate = self
|
longClick.delegate = self
|
||||||
|
|
||||||
singleClick = HapticClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
multiClick = MultiClickGestureRecognizer(
|
||||||
singleClick.allowedTouchTypes = .direct
|
target: self,
|
||||||
singleClick.delegate = self
|
action: #selector(handleGestureSingleTap),
|
||||||
|
doubleAction: #selector(handleGestureDoubleTap),
|
||||||
|
tripleAction: #selector(handleGestureTripleTap)
|
||||||
|
)
|
||||||
|
multiClick.allowedTouchTypes = .direct
|
||||||
|
multiClick.delegate = self
|
||||||
|
multiClick.isDoubleClickEnabled = false
|
||||||
|
multiClick.isTripleClickEnabled = false
|
||||||
|
|
||||||
reinstallButton()
|
reinstallButton()
|
||||||
button.attributedTitle = attributedTitle
|
button.attributedTitle = attributedTitle
|
||||||
@ -100,33 +121,43 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
view = button
|
view = button
|
||||||
|
|
||||||
view.addGestureRecognizer(longClick)
|
view.addGestureRecognizer(longClick)
|
||||||
view.addGestureRecognizer(singleClick)
|
// view.addGestureRecognizer(singleClick)
|
||||||
|
view.addGestureRecognizer(multiClick)
|
||||||
finishViewConfiguration()
|
finishViewConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
||||||
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick
|
if gestureRecognizer == multiClick && otherGestureRecognizer == longClick
|
||||||
|| gestureRecognizer == longClick && otherGestureRecognizer == singleClick // need it
|
|| gestureRecognizer == longClick && otherGestureRecognizer == multiClick // need it
|
||||||
{
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleGestureSingle(gr: NSClickGestureRecognizer) {
|
func callActions(for trigger: Action.Trigger) {
|
||||||
switch gr.state {
|
let itemActions = self.actions.filter { $0.trigger == trigger }
|
||||||
case .ended:
|
for itemAction in itemActions {
|
||||||
tapClosure?()
|
itemAction.closure?()
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureSingleTap() {
|
||||||
|
callActions(for: .singleTap)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureDoubleTap() {
|
||||||
|
callActions(for: .doubleTap)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureTripleTap() {
|
||||||
|
callActions(for: .tripleTap)
|
||||||
|
}
|
||||||
|
|
||||||
@objc func handleGestureLong(gr: NSPressGestureRecognizer) {
|
@objc func handleGestureLong(gr: NSPressGestureRecognizer) {
|
||||||
switch gr.state {
|
switch gr.state {
|
||||||
case .possible: // tiny hack because we're calling action manually
|
case .possible: // tiny hack because we're calling action manually
|
||||||
(self.longTapClosure ?? self.tapClosure)?()
|
callActions(for: .longTap)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@ -176,15 +207,78 @@ class CustomButtonCell: NSButtonCell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HapticClickGestureRecognizer: NSClickGestureRecognizer {
|
// Thanks to https://stackoverflow.com/a/49843893
|
||||||
override func touchesBegan(with event: NSEvent) {
|
final class MultiClickGestureRecognizer: NSClickGestureRecognizer {
|
||||||
HapticFeedback.shared?.tap(strong: 2)
|
|
||||||
super.touchesBegan(with: event)
|
private let _action: Selector
|
||||||
|
private let _doubleAction: Selector
|
||||||
|
private let _tripleAction: Selector
|
||||||
|
private var _clickCount: Int = 0
|
||||||
|
|
||||||
|
public var isDoubleClickEnabled = true
|
||||||
|
public var isTripleClickEnabled = true
|
||||||
|
|
||||||
|
override var action: Selector? {
|
||||||
|
get {
|
||||||
|
return nil /// prevent base class from performing any actions
|
||||||
|
} set {
|
||||||
|
if newValue != nil { // if they are trying to assign an actual action
|
||||||
|
fatalError("Only use init(target:action:doubleAction) for assigning actions")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
required init(target: AnyObject, action: Selector, doubleAction: Selector, tripleAction: Selector) {
|
||||||
|
_action = action
|
||||||
|
_doubleAction = doubleAction
|
||||||
|
_tripleAction = tripleAction
|
||||||
|
super.init(target: target, action: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(target:action:doubleAction:tripleAction) is only support atm")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func touchesBegan(with event: NSEvent) {
|
||||||
|
HapticFeedback.instance.tap(type: .click)
|
||||||
|
super.touchesBegan(with: event)
|
||||||
|
}
|
||||||
|
|
||||||
override func touchesEnded(with event: NSEvent) {
|
override func touchesEnded(with event: NSEvent) {
|
||||||
HapticFeedback.shared?.tap(strong: 1)
|
HapticFeedback.instance.tap(type: .back)
|
||||||
super.touchesEnded(with: event)
|
super.touchesEnded(with: event)
|
||||||
|
_clickCount += 1
|
||||||
|
|
||||||
|
var delayThreshold: TimeInterval // fine tune this as needed
|
||||||
|
|
||||||
|
guard isDoubleClickEnabled || isTripleClickEnabled else {
|
||||||
|
_ = target?.perform(_action)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTripleClickEnabled) {
|
||||||
|
delayThreshold = 0.4
|
||||||
|
perform(#selector(_resetAndPerformActionIfNecessary), with: nil, afterDelay: delayThreshold)
|
||||||
|
if _clickCount == 3 {
|
||||||
|
_ = target?.perform(_tripleAction)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delayThreshold = 0.3
|
||||||
|
perform(#selector(_resetAndPerformActionIfNecessary), with: nil, afterDelay: delayThreshold)
|
||||||
|
if _clickCount == 2 {
|
||||||
|
_ = target?.perform(_doubleAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func _resetAndPerformActionIfNecessary() {
|
||||||
|
if _clickCount == 1 {
|
||||||
|
_ = target?.perform(_action)
|
||||||
|
}
|
||||||
|
if isTripleClickEnabled && _clickCount == 2 {
|
||||||
|
_ = target?.perform(_doubleAction)
|
||||||
|
}
|
||||||
|
_clickCount = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +322,7 @@ class LongPressGestureRecognizer: NSPressGestureRecognizer {
|
|||||||
@objc private func onTimer() {
|
@objc private func onTimer() {
|
||||||
if let target = self.target, let action = self.action {
|
if let target = self.target, let action = self.action {
|
||||||
target.performSelector(onMainThread: action, with: self, waitUntilDone: false)
|
target.performSelector(onMainThread: action, with: self, waitUntilDone: false)
|
||||||
HapticFeedback.shared?.tap(strong: 6)
|
HapticFeedback.instance.tap(type: .strong)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,81 +9,92 @@
|
|||||||
import IOKit
|
import IOKit
|
||||||
|
|
||||||
class HapticFeedback {
|
class HapticFeedback {
|
||||||
static var shared: HapticFeedback?
|
|
||||||
|
|
||||||
// Here we have list of possible IDs for Haptic Generator Device. They are not constant
|
// Here we have list of possible IDs for Haptic Generator Device. They are not constant
|
||||||
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg
|
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg
|
||||||
// which you can download from https://developer.apple.com/download/more/?=Additional%20Tools
|
// which you can download from https://developer.apple.com/download/more/?=Additional%20Tools
|
||||||
// Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID"
|
// Open IORegistryExplorer app, search for "AppleMultitouchDevice" and get "Multitouch ID"
|
||||||
|
// or "AppleMultitouchTrackpadHIDEventDriver" and get "mt-device-id"
|
||||||
// There should be programmatic way to get it but I can't find, no docs for macOS :(
|
// There should be programmatic way to get it but I can't find, no docs for macOS :(
|
||||||
private let possibleDeviceIDs: [UInt64] = [
|
private let possibleDeviceIDs: [UInt64] = [
|
||||||
0x200_0000_0100_0000, // MacBook Pro 2016/2017
|
0x200_0000_0100_0000, // MacBook Pro 2016/2017
|
||||||
0x300000080500000 // MacBook Pro 2019 (possibly 2018 as well)
|
0x300_0000_8050_0000, // MacBook Pro 2019/2018
|
||||||
|
0x200_0000_0000_0024, // MacBook Pro (13-inch, M1, 2020)
|
||||||
|
0x200_0000_0000_0023 // MacBook Pro M1 13-Inch 2020 with 1tb
|
||||||
|
// 0x300000080500000,
|
||||||
]
|
]
|
||||||
private var correctDeviceID: UInt64?
|
|
||||||
private var actuatorRef: CFTypeRef?
|
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
|
||||||
|
enum HapticType: Int32, CaseIterable {
|
||||||
init() {
|
case back = 1
|
||||||
recreateDevice()
|
case click = 2
|
||||||
|
case weak = 3
|
||||||
|
case medium = 4
|
||||||
|
case weakMedium = 5
|
||||||
|
case strong = 6
|
||||||
|
case reserved1 = 15
|
||||||
|
case reserved2 = 16
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't know how to do strong is enum one of
|
private var actuatorRef: CFTypeRef?
|
||||||
// 1 like back Click
|
|
||||||
// 2 like Click
|
|
||||||
// 3 week
|
|
||||||
// 4 medium
|
|
||||||
// 5 week medium
|
|
||||||
// 6 strong
|
|
||||||
// 15 nothing
|
|
||||||
// 16 nothing
|
|
||||||
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
|
|
||||||
|
|
||||||
func tap(strong: Int32) {
|
static var instance = HapticFeedback()
|
||||||
guard correctDeviceID != nil, actuatorRef != nil else {
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
self.recreateDevice()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func recreateDevice() {
|
||||||
|
if let actuatorRef = self.actuatorRef {
|
||||||
|
MTActuatorClose(actuatorRef)
|
||||||
|
self.actuatorRef = nil // just in case %)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard self.actuatorRef == nil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's find our Haptic device
|
||||||
|
self.possibleDeviceIDs.forEach {(deviceID) in
|
||||||
|
let actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
||||||
|
|
||||||
|
if actuatorRef != nil {
|
||||||
|
self.actuatorRef = actuatorRef
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Tap action
|
||||||
|
|
||||||
|
private func getActuatorIfPosible() -> CFTypeRef? {
|
||||||
|
guard AppSettings.hapticFeedbackState else { return nil }
|
||||||
|
guard let actuatorRef = self.actuatorRef else {
|
||||||
print("guard actuatorRef == nil (no haptic device found?)")
|
print("guard actuatorRef == nil (no haptic device found?)")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var result: IOReturn
|
guard MTActuatorOpen(actuatorRef) == kIOReturnSuccess else {
|
||||||
|
|
||||||
result = MTActuatorOpen(actuatorRef!)
|
|
||||||
guard result == kIOReturnSuccess else {
|
|
||||||
print("guard MTActuatorOpen")
|
print("guard MTActuatorOpen")
|
||||||
recreateDevice()
|
self.recreateDevice()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result = MTActuatorActuate(actuatorRef!, strong, 0, 0, 0)
|
return actuatorRef
|
||||||
guard result == kIOReturnSuccess else {
|
}
|
||||||
|
|
||||||
|
func tap(type: HapticType) {
|
||||||
|
guard let actuator = getActuatorIfPosible() else { return }
|
||||||
|
|
||||||
|
guard MTActuatorActuate(actuator, type.rawValue, 0, 0, 0) == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorActuate")
|
print("guard MTActuatorActuate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result = MTActuatorClose(actuatorRef!)
|
guard MTActuatorClose(actuator) == kIOReturnSuccess else {
|
||||||
guard result == kIOReturnSuccess else {
|
|
||||||
print("guard MTActuatorClose")
|
print("guard MTActuatorClose")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func recreateDevice() {
|
|
||||||
if let actuatorRef = actuatorRef {
|
|
||||||
MTActuatorClose(actuatorRef)
|
|
||||||
self.actuatorRef = nil // just in case %)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let correctDeviceID = correctDeviceID {
|
|
||||||
actuatorRef = MTActuatorCreateFromDeviceID(correctDeviceID).takeRetainedValue()
|
|
||||||
} else {
|
|
||||||
// Let's find our Haptic device
|
|
||||||
possibleDeviceIDs.forEach {(deviceID) in
|
|
||||||
guard correctDeviceID == nil else {return}
|
|
||||||
actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
|
||||||
|
|
||||||
if actuatorRef != nil {
|
|
||||||
correctDeviceID = deviceID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.26</string>
|
<string>0.27</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>401</string>
|
<string>448</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>
|
||||||
|
|||||||
@ -3,47 +3,52 @@ import Foundation
|
|||||||
|
|
||||||
extension Data {
|
extension Data {
|
||||||
func barItemDefinitions() -> [BarItemDefinition]? {
|
func barItemDefinitions() -> [BarItemDefinition]? {
|
||||||
return try? JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
|
return try! JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BarItemDefinition: Decodable {
|
struct BarItemDefinition: Decodable {
|
||||||
let type: ItemType
|
let type: ItemType
|
||||||
let action: ActionType
|
let actions: [Action]
|
||||||
let longAction: LongActionType
|
let legacyAction: LegacyActionType
|
||||||
|
let legacyLongAction: LegacyLongActionType
|
||||||
let additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
let additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case type
|
case type
|
||||||
|
case actions
|
||||||
}
|
}
|
||||||
|
|
||||||
init(type: ItemType, action: ActionType, longAction: LongActionType, additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]) {
|
init(type: ItemType, actions: [Action], action: LegacyActionType, legacyLongAction: LegacyLongActionType, additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]) {
|
||||||
self.type = type
|
self.type = type
|
||||||
self.action = action
|
self.actions = actions
|
||||||
self.longAction = longAction
|
self.legacyAction = action
|
||||||
|
self.legacyLongAction = legacyLongAction
|
||||||
self.additionalParameters = additionalParameters
|
self.additionalParameters = additionalParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
let type = try container.decode(String.self, forKey: .type)
|
let type = try container.decode(String.self, forKey: .type)
|
||||||
let parametersDecoder = SupportedTypesHolder.sharedInstance.lookup(by: type)
|
let actions = try container.decodeIfPresent([Action].self, forKey: .actions)
|
||||||
|
let parametersDecoder = SupportedTypesHolder.sharedInstance.lookup(by: type, actions: actions ?? [])
|
||||||
var additionalParameters = try GeneralParameters(from: decoder).parameters
|
var additionalParameters = try GeneralParameters(from: decoder).parameters
|
||||||
|
|
||||||
if let result = try? parametersDecoder(decoder),
|
if let result = try? parametersDecoder(decoder),
|
||||||
case let (itemType, action, longAction, parameters) = result {
|
case let (itemType, actions, action, longAction, parameters) = result {
|
||||||
parameters.forEach { additionalParameters[$0] = $1 }
|
parameters.forEach { additionalParameters[$0] = $1 }
|
||||||
self.init(type: itemType, action: action, longAction: longAction, additionalParameters: additionalParameters)
|
self.init(type: itemType, actions: actions, action: action, legacyLongAction: longAction, additionalParameters: additionalParameters)
|
||||||
} else {
|
} else {
|
||||||
self.init(type: .staticButton(title: "unknown"), action: .none, longAction: .none, additionalParameters: additionalParameters)
|
self.init(type: .staticButton(title: "unknown"), actions: [], action: .none, legacyLongAction: .none, additionalParameters: additionalParameters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typealias ParametersDecoder = (Decoder) throws -> (
|
typealias ParametersDecoder = (Decoder) throws -> (
|
||||||
item: ItemType,
|
item: ItemType,
|
||||||
action: ActionType,
|
actions: [Action],
|
||||||
longAction: LongActionType,
|
legacyAction: LegacyActionType,
|
||||||
|
legacyLongAction: LegacyLongActionType,
|
||||||
parameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
parameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,15 +56,21 @@ class SupportedTypesHolder {
|
|||||||
private var supportedTypes: [String: ParametersDecoder] = [
|
private var supportedTypes: [String: ParametersDecoder] = [
|
||||||
"escape": { _ in (
|
"escape": { _ in (
|
||||||
item: .staticButton(title: "esc"),
|
item: .staticButton(title: "esc"),
|
||||||
action: .keyPress(keycode: 53),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .keyPress(keycode: 53))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.align: .align(.left)]
|
parameters: [.align: .align(.left)]
|
||||||
) },
|
) },
|
||||||
|
|
||||||
"delete": { _ in (
|
"delete": { _ in (
|
||||||
item: .staticButton(title: "del"),
|
item: .staticButton(title: "del"),
|
||||||
action: .keyPress(keycode: 117),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .keyPress(keycode: 117))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
) },
|
) },
|
||||||
|
|
||||||
@ -67,8 +78,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessUp"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessUp"))
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .keyPress(keycode: 144),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_BRIGHTNESS_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -77,8 +91,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessDown"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessDown"))
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .keyPress(keycode: 145),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_BRIGHTNESS_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -87,8 +104,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_up"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_up"))
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_UP),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -97,8 +117,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_down"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_down"))
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_DOWN),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -107,8 +130,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeDownTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeDownTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_SOUND_DOWN),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_SOUND_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -117,8 +143,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeUpTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeUpTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_SOUND_UP),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_SOUND_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -127,8 +156,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarAudioOutputMuteTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarAudioOutputMuteTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_MUTE),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_MUTE))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -137,8 +169,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarRewindTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarRewindTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_PREVIOUS),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_PREVIOUS))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -147,8 +182,11 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarPlayPauseTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarPlayPauseTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_PLAY),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_PLAY))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -157,23 +195,32 @@ class SupportedTypesHolder {
|
|||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarFastForwardTemplateName)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarFastForwardTemplateName)!)
|
||||||
return (
|
return (
|
||||||
item: .staticButton(title: ""),
|
item: .staticButton(title: ""),
|
||||||
action: .hidKey(keycode: NX_KEYTYPE_NEXT),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_NEXT))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [.image: imageParameter]
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"sleep": { _ in (
|
"sleep": { _ in (
|
||||||
item: .staticButton(title: "☕️"),
|
item: .staticButton(title: "☕️"),
|
||||||
action: .shellScript(executable: "/usr/bin/pmset", parameters: ["sleepnow"]),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .shellScript(executable: "/usr/bin/pmset", parameters: ["sleepnow"]))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
) },
|
) },
|
||||||
|
|
||||||
"displaySleep": { _ in (
|
"displaySleep": { _ in (
|
||||||
item: .staticButton(title: "☕️"),
|
item: .staticButton(title: "☕️"),
|
||||||
action: .shellScript(executable: "/usr/bin/pmset", parameters: ["displaysleepnow"]),
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .shellScript(executable: "/usr/bin/pmset", parameters: ["displaysleepnow"]))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
) },
|
) },
|
||||||
|
|
||||||
@ -181,11 +228,12 @@ class SupportedTypesHolder {
|
|||||||
|
|
||||||
static let sharedInstance = SupportedTypesHolder()
|
static let sharedInstance = SupportedTypesHolder()
|
||||||
|
|
||||||
func lookup(by type: String) -> ParametersDecoder {
|
func lookup(by type: String, actions: [Action]) -> ParametersDecoder {
|
||||||
return supportedTypes[type] ?? { decoder in (
|
return supportedTypes[type] ?? { decoder in (
|
||||||
item: try ItemType(from: decoder),
|
item: try ItemType(from: decoder),
|
||||||
action: try ActionType(from: decoder),
|
actions: actions,
|
||||||
longAction: try LongActionType(from: decoder),
|
legacyAction: try LegacyActionType(from: decoder),
|
||||||
|
legacyLongAction: try LegacyLongActionType(from: decoder),
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
) }
|
) }
|
||||||
}
|
}
|
||||||
@ -194,12 +242,13 @@ class SupportedTypesHolder {
|
|||||||
supportedTypes[typename] = decoder
|
supportedTypes[typename] = decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
func register(typename: String, item: ItemType, action: ActionType, longAction: LongActionType) {
|
func register(typename: String, item: ItemType, actions: [Action], legacyAction: LegacyActionType, legacyLongAction: LegacyLongActionType) {
|
||||||
register(typename: typename) { _ in
|
register(typename: typename) { _ in
|
||||||
(
|
(
|
||||||
item: item,
|
item: item,
|
||||||
action,
|
actions,
|
||||||
longAction,
|
legacyAction,
|
||||||
|
legacyLongAction,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -212,6 +261,7 @@ enum ItemType: Decodable {
|
|||||||
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||||
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
|
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
|
||||||
case battery
|
case battery
|
||||||
|
case cpu(refreshInterval: Double)
|
||||||
case dock(autoResize: Bool, filter: String?)
|
case dock(autoResize: Bool, filter: String?)
|
||||||
case volume
|
case volume
|
||||||
case brightness(refreshInterval: Double)
|
case brightness(refreshInterval: Double)
|
||||||
@ -224,9 +274,10 @@ enum ItemType: Decodable {
|
|||||||
case nightShift
|
case nightShift
|
||||||
case dnd
|
case dnd
|
||||||
case pomodoro(workTime: Double, restTime: Double)
|
case pomodoro(workTime: Double, restTime: Double)
|
||||||
case network(flip: Bool)
|
case network(flip: Bool, units: String)
|
||||||
case darkMode
|
case darkMode
|
||||||
case swipe(direction: String, fingers: Int, minOffset: Float, sourceApple: SourceProtocol?, sourceBash: SourceProtocol?)
|
case swipe(direction: String, fingers: Int, minOffset: Float, sourceApple: SourceProtocol?, sourceBash: SourceProtocol?)
|
||||||
|
case upnext(from: Double, to: Double, maxToShow: Int, autoResize: Bool)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case type
|
case type
|
||||||
@ -258,6 +309,7 @@ enum ItemType: Decodable {
|
|||||||
case direction
|
case direction
|
||||||
case fingers
|
case fingers
|
||||||
case minOffset
|
case minOffset
|
||||||
|
case maxToShow
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ItemTypeRaw: String, Decodable {
|
enum ItemTypeRaw: String, Decodable {
|
||||||
@ -266,6 +318,7 @@ enum ItemType: Decodable {
|
|||||||
case shellScriptTitledButton
|
case shellScriptTitledButton
|
||||||
case timeButton
|
case timeButton
|
||||||
case battery
|
case battery
|
||||||
|
case cpu
|
||||||
case dock
|
case dock
|
||||||
case volume
|
case volume
|
||||||
case brightness
|
case brightness
|
||||||
@ -281,6 +334,7 @@ enum ItemType: Decodable {
|
|||||||
case network
|
case network
|
||||||
case darkMode
|
case darkMode
|
||||||
case swipe
|
case swipe
|
||||||
|
case upnext
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
@ -310,6 +364,10 @@ enum ItemType: Decodable {
|
|||||||
|
|
||||||
case .battery:
|
case .battery:
|
||||||
self = .battery
|
self = .battery
|
||||||
|
|
||||||
|
case .cpu:
|
||||||
|
let refreshInterval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
|
||||||
|
self = .cpu(refreshInterval: refreshInterval)
|
||||||
|
|
||||||
case .dock:
|
case .dock:
|
||||||
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
||||||
@ -366,7 +424,8 @@ enum ItemType: Decodable {
|
|||||||
|
|
||||||
case .network:
|
case .network:
|
||||||
let flip = try container.decodeIfPresent(Bool.self, forKey: .flip) ?? false
|
let flip = try container.decodeIfPresent(Bool.self, forKey: .flip) ?? false
|
||||||
self = .network(flip: flip)
|
let units = try container.decodeIfPresent(String.self, forKey: .units) ?? "dynamic"
|
||||||
|
self = .network(flip: flip, units: units)
|
||||||
|
|
||||||
case .darkMode:
|
case .darkMode:
|
||||||
self = .darkMode
|
self = .darkMode
|
||||||
@ -378,11 +437,106 @@ enum ItemType: Decodable {
|
|||||||
let fingers = try container.decode(Int.self, forKey: .fingers)
|
let fingers = try container.decode(Int.self, forKey: .fingers)
|
||||||
let minOffset = try container.decodeIfPresent(Float.self, forKey: .minOffset) ?? 0.0
|
let minOffset = try container.decodeIfPresent(Float.self, forKey: .minOffset) ?? 0.0
|
||||||
self = .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
self = .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
||||||
|
|
||||||
|
case .upnext:
|
||||||
|
let from = try container.decodeIfPresent(Double.self, forKey: .from) ?? 0 // Lower bounds of period of time in hours to search for events
|
||||||
|
let to = try container.decodeIfPresent(Double.self, forKey: .to) ?? 12 // Upper bounds of period of time in hours to search for events
|
||||||
|
let maxToShow = try container.decodeIfPresent(Int.self, forKey: .maxToShow) ?? 3 // 1 indexed array. Get the 1st, 2nd, 3rd event to display multiple notifications
|
||||||
|
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
||||||
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 60.0
|
||||||
|
self = .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ActionType: Decodable {
|
struct FailableDecodable<Base : Decodable> : Decodable {
|
||||||
|
|
||||||
|
let base: Base?
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.singleValueContainer()
|
||||||
|
self.base = try? container.decode(Base.self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Action: Decodable {
|
||||||
|
enum Trigger: String, Decodable {
|
||||||
|
case singleTap
|
||||||
|
case doubleTap
|
||||||
|
case tripleTap
|
||||||
|
case longTap
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Value {
|
||||||
|
case none
|
||||||
|
case hidKey(keycode: Int32)
|
||||||
|
case keyPress(keycode: Int)
|
||||||
|
case appleScript(source: SourceProtocol)
|
||||||
|
case shellScript(executable: String, parameters: [String])
|
||||||
|
case custom(closure: () -> Void)
|
||||||
|
case openUrl(url: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum ActionTypeRaw: String, Decodable {
|
||||||
|
case hidKey
|
||||||
|
case keyPress
|
||||||
|
case appleScript
|
||||||
|
case shellScript
|
||||||
|
case openUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case trigger
|
||||||
|
case action
|
||||||
|
case keycode
|
||||||
|
case actionAppleScript
|
||||||
|
case executablePath
|
||||||
|
case shellArguments
|
||||||
|
case url
|
||||||
|
}
|
||||||
|
|
||||||
|
let trigger: Trigger
|
||||||
|
let value: Value
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
|
trigger = try container.decode(Trigger.self, forKey: .trigger)
|
||||||
|
let type = try container.decodeIfPresent(ActionTypeRaw.self, forKey: .action)
|
||||||
|
|
||||||
|
switch type {
|
||||||
|
case .some(.hidKey):
|
||||||
|
let keycode = try container.decode(Int32.self, forKey: .keycode)
|
||||||
|
value = .hidKey(keycode: keycode)
|
||||||
|
|
||||||
|
case .some(.keyPress):
|
||||||
|
let keycode = try container.decode(Int.self, forKey: .keycode)
|
||||||
|
value = .keyPress(keycode: keycode)
|
||||||
|
|
||||||
|
case .some(.appleScript):
|
||||||
|
let source = try container.decode(Source.self, forKey: .actionAppleScript)
|
||||||
|
value = .appleScript(source: source)
|
||||||
|
|
||||||
|
case .some(.shellScript):
|
||||||
|
let executable = try container.decode(String.self, forKey: .executablePath)
|
||||||
|
let parameters = try container.decodeIfPresent([String].self, forKey: .shellArguments) ?? []
|
||||||
|
value = .shellScript(executable: executable, parameters: parameters)
|
||||||
|
|
||||||
|
case .some(.openUrl):
|
||||||
|
let url = try container.decode(String.self, forKey: .url)
|
||||||
|
value = .openUrl(url: url)
|
||||||
|
case .none:
|
||||||
|
value = .none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(trigger: Trigger, value: Value) {
|
||||||
|
self.trigger = trigger
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LegacyActionType: Decodable {
|
||||||
case none
|
case none
|
||||||
case hidKey(keycode: Int32)
|
case hidKey(keycode: Int32)
|
||||||
case keyPress(keycode: Int)
|
case keyPress(keycode: Int)
|
||||||
@ -440,7 +594,7 @@ enum ActionType: Decodable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LongActionType: Decodable {
|
enum LegacyLongActionType: Decodable {
|
||||||
case none
|
case none
|
||||||
case hidKey(keycode: Int32)
|
case hidKey(keycode: Int32)
|
||||||
case keyPress(keycode: Int)
|
case keyPress(keycode: Int)
|
||||||
@ -505,6 +659,7 @@ enum GeneralParameter {
|
|||||||
case bordered(_: Bool)
|
case bordered(_: Bool)
|
||||||
case background(_: NSColor)
|
case background(_: NSColor)
|
||||||
case title(_: String)
|
case title(_: String)
|
||||||
|
case matchAppId(_: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GeneralParameters: Decodable {
|
struct GeneralParameters: Decodable {
|
||||||
@ -517,6 +672,7 @@ struct GeneralParameters: Decodable {
|
|||||||
case bordered
|
case bordered
|
||||||
case background
|
case background
|
||||||
case title
|
case title
|
||||||
|
case matchAppId
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
@ -546,6 +702,10 @@ struct GeneralParameters: Decodable {
|
|||||||
result[.title] = .title(title)
|
result[.title] = .title(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let matchAppId = try container.decodeIfPresent(String.self, forKey: .matchAppId) {
|
||||||
|
result[.matchAppId] = .matchAppId(matchAppId)
|
||||||
|
}
|
||||||
|
|
||||||
parameters = result
|
parameters = result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,11 @@ class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
private let source: String
|
private let source: String
|
||||||
private var forceHideConstraint: NSLayoutConstraint!
|
private var forceHideConstraint: NSLayoutConstraint!
|
||||||
|
|
||||||
|
struct ScriptResult: Decodable {
|
||||||
|
var title: String?
|
||||||
|
var image: Source?
|
||||||
|
}
|
||||||
|
|
||||||
init?(identifier: NSTouchBarItem.Identifier, source: SourceProtocol, interval: TimeInterval) {
|
init?(identifier: NSTouchBarItem.Identifier, source: SourceProtocol, interval: TimeInterval) {
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
self.source = source.string ?? "echo No \"source\""
|
self.source = source.string ?? "echo No \"source\""
|
||||||
@ -31,12 +36,25 @@ class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
func refreshAndSchedule() {
|
func refreshAndSchedule() {
|
||||||
// Execute script and get result
|
// Execute script and get result
|
||||||
let scriptResult = execute(source)
|
let scriptResult = execute(source)
|
||||||
|
var rawTitle: String, image: NSImage?
|
||||||
|
var json: Bool
|
||||||
|
|
||||||
|
do {
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
let result = try decoder.decode(ScriptResult.self, from: scriptResult.data(using: .utf8)!)
|
||||||
|
json = true
|
||||||
|
rawTitle = result.title ?? ""
|
||||||
|
image = result.image?.image
|
||||||
|
} catch {
|
||||||
|
json = false
|
||||||
|
rawTitle = scriptResult
|
||||||
|
}
|
||||||
|
|
||||||
// Apply returned text attributes (if they were returned) to our result string
|
// Apply returned text attributes (if they were returned) to our result string
|
||||||
let helper = AMR_ANSIEscapeHelper.init()
|
let helper = AMR_ANSIEscapeHelper.init()
|
||||||
helper.defaultStringColor = NSColor.white
|
helper.defaultStringColor = NSColor.white
|
||||||
helper.font = "1".defaultTouchbarAttributedString.attribute(.font, at: 0, effectiveRange: nil) as? NSFont
|
helper.font = "1".defaultTouchbarAttributedString.attribute(.font, at: 0, effectiveRange: nil) as? NSFont
|
||||||
let title = NSMutableAttributedString.init(attributedString: helper.attributedString(withANSIEscapedString: scriptResult) ?? NSAttributedString(string: ""))
|
let title = NSMutableAttributedString.init(attributedString: helper.attributedString(withANSIEscapedString: rawTitle) ?? NSAttributedString(string: ""))
|
||||||
title.addAttributes([.baselineOffset: 1], range: NSRange(location: 0, length: title.length))
|
title.addAttributes([.baselineOffset: 1], range: NSRange(location: 0, length: title.length))
|
||||||
let newBackgoundColor: NSColor? = title.length != 0 ? title.attribute(.backgroundColor, at: 0, effectiveRange: nil) as? NSColor : nil
|
let newBackgoundColor: NSColor? = title.length != 0 ? title.attribute(.backgroundColor, at: 0, effectiveRange: nil) as? NSColor : nil
|
||||||
|
|
||||||
@ -46,6 +64,9 @@ class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
self?.backgroundColor = newBackgoundColor
|
self?.backgroundColor = newBackgoundColor
|
||||||
}
|
}
|
||||||
self?.attributedTitle = title
|
self?.attributedTitle = title
|
||||||
|
if json {
|
||||||
|
self?.image = image
|
||||||
|
}
|
||||||
self?.forceHideConstraint.isActive = scriptResult == ""
|
self?.forceHideConstraint.isActive = scriptResult == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +78,11 @@ class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
func execute(_ command: String) -> String {
|
func execute(_ command: String) -> String {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = "/bin/bash"
|
if let shell = getenv("SHELL") {
|
||||||
|
task.launchPath = String.init(cString: shell)
|
||||||
|
} else {
|
||||||
|
task.launchPath = "/bin/bash"
|
||||||
|
}
|
||||||
task.arguments = ["-c", command]
|
task.arguments = ["-c", command]
|
||||||
|
|
||||||
let pipe = Pipe()
|
let pipe = Pipe()
|
||||||
|
|||||||
@ -51,7 +51,11 @@ class SwipeItem: NSCustomTouchBarItem {
|
|||||||
if scriptBash != nil {
|
if scriptBash != nil {
|
||||||
DispatchQueue.shellScriptQueue.async {
|
DispatchQueue.shellScriptQueue.async {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = "/bin/bash"
|
if let shell = getenv("SHELL") {
|
||||||
|
task.launchPath = String.init(cString: shell)
|
||||||
|
} else {
|
||||||
|
task.launchPath = "/bin/bash"
|
||||||
|
}
|
||||||
task.arguments = ["-c", self.scriptBash!]
|
task.arguments = ["-c", self.scriptBash!]
|
||||||
task.launch()
|
task.launch()
|
||||||
task.waitUntilExit()
|
task.waitUntilExit()
|
||||||
@ -63,4 +67,12 @@ class SwipeItem: NSCustomTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isEqual(_ object: AnyObject?) -> Bool {
|
||||||
|
if let object = object as? SwipeItem {
|
||||||
|
return self.scriptApple?.source as String? == object.scriptApple?.source as String? && self.scriptBash == object.scriptBash && self.direction == object.direction && self.fingers == object.fingers && self.minOffset == object.minOffset
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,8 @@ extension ItemType {
|
|||||||
return "com.toxblh.mtmr.timeButton."
|
return "com.toxblh.mtmr.timeButton."
|
||||||
case .battery:
|
case .battery:
|
||||||
return "com.toxblh.mtmr.battery."
|
return "com.toxblh.mtmr.battery."
|
||||||
|
case .cpu(refreshInterval: _):
|
||||||
|
return "com.toxblh.mtmr.cpu."
|
||||||
case .dock(autoResize: _, filter: _):
|
case .dock(autoResize: _, filter: _):
|
||||||
return "com.toxblh.mtmr.dock"
|
return "com.toxblh.mtmr.dock"
|
||||||
case .volume:
|
case .volume:
|
||||||
@ -59,6 +61,8 @@ extension ItemType {
|
|||||||
return DarkModeBarItem.identifier
|
return DarkModeBarItem.identifier
|
||||||
case .swipe(direction: _, fingers: _, minOffset: _, sourceApple: _, sourceBash: _):
|
case .swipe(direction: _, fingers: _, minOffset: _, sourceApple: _, sourceBash: _):
|
||||||
return "com.toxblh.mtmr.swipe."
|
return "com.toxblh.mtmr.swipe."
|
||||||
|
case .upnext(from: _, to: _, maxToShow: _, autoResize: _):
|
||||||
|
return "com.connorgmeehan.mtmrup.next."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,17 +94,32 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
|
|
||||||
private override init() {
|
private override init() {
|
||||||
super.init()
|
super.init()
|
||||||
SupportedTypesHolder.sharedInstance.register(typename: "exitTouchbar", item: .staticButton(title: "exit"), action: .custom(closure: { [weak self] in self?.dismissTouchBar() }), longAction: .none)
|
SupportedTypesHolder.sharedInstance.register(
|
||||||
|
typename: "exitTouchbar",
|
||||||
|
item: .staticButton(title: "exit"),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .custom(closure: { [weak self] in self?.dismissTouchBar() }))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none
|
||||||
|
)
|
||||||
|
|
||||||
SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in
|
SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in
|
||||||
(item: .staticButton(title: ""), action: .custom(closure: { [weak self] in
|
(
|
||||||
guard let `self` = self else { return }
|
item: .staticButton(title: ""),
|
||||||
self.reloadPreset(path: self.lastPresetPath)
|
actions: [
|
||||||
}), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
|
Action(trigger: .singleTap, value: .custom(closure: { [weak self] in
|
||||||
|
guard let `self` = self else { return }
|
||||||
|
self.reloadPreset(path: self.lastPresetPath)
|
||||||
|
}))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
|
||||||
}
|
}
|
||||||
|
|
||||||
blacklistAppIdentifiers = AppSettings.blacklistedAppIds
|
blacklistAppIdentifiers = AppSettings.blacklistedAppIds
|
||||||
|
|
||||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||||
@ -115,32 +134,69 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
touchBar = NSTouchBar()
|
touchBar = NSTouchBar()
|
||||||
jsonItems = newJsonItems
|
jsonItems = newJsonItems
|
||||||
itemDefinitions = [:]
|
itemDefinitions = [:]
|
||||||
items = [:]
|
|
||||||
|
|
||||||
loadItemDefinitions(jsonItems: jsonItems)
|
loadItemDefinitions(jsonItems: jsonItems)
|
||||||
|
|
||||||
|
updateActiveApp()
|
||||||
|
}
|
||||||
|
|
||||||
|
func didItemsChange(prevItems: [NSTouchBarItem.Identifier: NSTouchBarItem], prevSwipeItems: [SwipeItem]) -> Bool {
|
||||||
|
var changed = items.count != prevItems.count || swipeItems.count != prevSwipeItems.count
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
for (item, prevItem) in zip(items, prevItems) {
|
||||||
|
if item.key != prevItem.key {
|
||||||
|
changed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
for (swipeItem, prevSwipeItem) in zip(swipeItems, prevSwipeItems) {
|
||||||
|
if !swipeItem.isEqual(prevSwipeItem) {
|
||||||
|
changed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepareTouchBar() {
|
||||||
|
let prevItems = items
|
||||||
|
let prevSwipeItems = swipeItems
|
||||||
|
|
||||||
createItems()
|
createItems()
|
||||||
|
|
||||||
|
let changed = didItemsChange(prevItems: prevItems, prevSwipeItems: prevSwipeItems)
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
let centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
items[identifier]
|
items[identifier]
|
||||||
})
|
})
|
||||||
|
|
||||||
let centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
let centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||||
let scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
let scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
||||||
|
|
||||||
|
basicViewIdentifier = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollView.".appending(UUID().uuidString))
|
||||||
|
|
||||||
touchBar.delegate = self
|
touchBar.delegate = self
|
||||||
touchBar.defaultItemIdentifiers = [basicViewIdentifier]
|
touchBar.defaultItemIdentifiers = [basicViewIdentifier]
|
||||||
|
|
||||||
let leftItems = leftIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
let leftItems = leftIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
items[identifier]
|
items[identifier]
|
||||||
})
|
})
|
||||||
let rightItems = rightIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
let rightItems = rightIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
items[identifier]
|
items[identifier]
|
||||||
})
|
})
|
||||||
|
|
||||||
basicView = BasicView(identifier: basicViewIdentifier, items:leftItems + [scrollArea] + rightItems, swipeItems: swipeItems)
|
basicView = BasicView(identifier: basicViewIdentifier, items:leftItems + [scrollArea] + rightItems, swipeItems: swipeItems)
|
||||||
basicView?.legacyGesturesEnabled = AppSettings.multitouchGestures
|
basicView?.legacyGesturesEnabled = AppSettings.multitouchGestures
|
||||||
|
|
||||||
updateActiveApp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func activeApplicationChanged(_: Notification) {
|
@objc func activeApplicationChanged(_: Notification) {
|
||||||
@ -151,9 +207,18 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil {
|
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil {
|
||||||
dismissTouchBar()
|
dismissTouchBar()
|
||||||
} else {
|
} else {
|
||||||
presentTouchBar()
|
prepareTouchBar()
|
||||||
|
if touchBarContainsAnyItems() {
|
||||||
|
presentTouchBar()
|
||||||
|
} else {
|
||||||
|
dismissTouchBar()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func touchBarContainsAnyItems() -> Bool {
|
||||||
|
return items.count != 0 || swipeItems.count != 0
|
||||||
|
}
|
||||||
|
|
||||||
func reloadStandardConfig() {
|
func reloadStandardConfig() {
|
||||||
let presetPath = standardConfigPath
|
let presetPath = standardConfigPath
|
||||||
@ -168,7 +233,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
|
|
||||||
func reloadPreset(path: String) {
|
func reloadPreset(path: String) {
|
||||||
lastPresetPath = path
|
lastPresetPath = path
|
||||||
let items = path.fileData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])]
|
let items = path.fileData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), actions: [], action: .none, legacyLongAction: .none, additionalParameters: [:])]
|
||||||
createAndUpdatePreset(newJsonItems: items)
|
createAndUpdatePreset(newJsonItems: items)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,12 +258,29 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createItems() {
|
func createItems() {
|
||||||
|
items = [:]
|
||||||
|
swipeItems = []
|
||||||
|
|
||||||
for (identifier, definition) in itemDefinitions {
|
for (identifier, definition) in itemDefinitions {
|
||||||
let item = createItem(forIdentifier: identifier, definition: definition)
|
var show = true
|
||||||
if item is SwipeItem {
|
|
||||||
swipeItems.append(item as! SwipeItem)
|
if let frontApp = frontmostApplicationIdentifier {
|
||||||
} else {
|
if case let .matchAppId(regexString)? = definition.additionalParameters[.matchAppId] {
|
||||||
items[identifier] = item
|
let regex = try! NSRegularExpression(pattern: regexString)
|
||||||
|
let range = NSRange(location: 0, length: frontApp.count)
|
||||||
|
if regex.firstMatch(in: frontApp, range: range) == nil {
|
||||||
|
show = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if show {
|
||||||
|
let item = createItem(forIdentifier: identifier, definition: definition)
|
||||||
|
if item is SwipeItem {
|
||||||
|
swipeItems.append(item as! SwipeItem)
|
||||||
|
} else {
|
||||||
|
items[identifier] = item
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,26 +294,29 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateControlStripPresence() {
|
func updateControlStripPresence() {
|
||||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
let showMtmrButtonOnControlStrip = touchBarContainsAnyItems()
|
||||||
|
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, showMtmrButtonOnControlStrip)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func presentTouchBar() {
|
@objc private func presentTouchBar() {
|
||||||
if AppSettings.showControlStripState {
|
if AppSettings.showControlStripState {
|
||||||
updateControlStripPresence()
|
|
||||||
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||||
} else {
|
} else {
|
||||||
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||||
}
|
}
|
||||||
|
updateControlStripPresence()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func dismissTouchBar() {
|
@objc private func dismissTouchBar() {
|
||||||
minimizeSystemModal(touchBar)
|
if touchBarContainsAnyItems() {
|
||||||
|
minimizeSystemModal(touchBar)
|
||||||
|
}
|
||||||
updateControlStripPresence()
|
updateControlStripPresence()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func resetControlStrip() {
|
@objc func resetControlStrip() {
|
||||||
dismissTouchBar()
|
dismissTouchBar()
|
||||||
presentTouchBar()
|
updateActiveApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func touchBar(_: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
func touchBar(_: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
||||||
@ -255,6 +340,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
|
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||||
case .battery:
|
case .battery:
|
||||||
barItem = BatteryBarItem(identifier: identifier)
|
barItem = BatteryBarItem(identifier: identifier)
|
||||||
|
case let .cpu(refreshInterval: refreshInterval):
|
||||||
|
barItem = CPUBarItem(identifier: identifier, refreshInterval: refreshInterval)
|
||||||
case let .dock(autoResize: autoResize, filter: regexString):
|
case let .dock(autoResize: autoResize, filter: regexString):
|
||||||
if let regexString = regexString {
|
if let regexString = regexString {
|
||||||
guard let regex = try? NSRegularExpression(pattern: regexString, options: []) else {
|
guard let regex = try? NSRegularExpression(pattern: regexString, options: []) else {
|
||||||
@ -295,19 +382,27 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
barItem = DnDBarItem(identifier: identifier)
|
barItem = DnDBarItem(identifier: identifier)
|
||||||
case let .pomodoro(workTime: workTime, restTime: restTime):
|
case let .pomodoro(workTime: workTime, restTime: restTime):
|
||||||
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
||||||
case let .network(flip: flip):
|
case let .network(flip: flip, units: units):
|
||||||
barItem = NetworkBarItem(identifier: identifier, flip: flip)
|
barItem = NetworkBarItem(identifier: identifier, flip: flip, units: units)
|
||||||
case .darkMode:
|
case .darkMode:
|
||||||
barItem = DarkModeBarItem(identifier: identifier)
|
barItem = DarkModeBarItem(identifier: identifier)
|
||||||
case let .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash):
|
case let .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash):
|
||||||
barItem = SwipeItem(identifier: identifier, direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
barItem = SwipeItem(identifier: identifier, direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
||||||
|
case let .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize):
|
||||||
|
barItem = UpNextScrubberTouchBarItem(identifier: identifier, interval: 60, from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.tapClosure = action
|
item.actions.append(ItemAction(trigger: .singleTap, action))
|
||||||
}
|
}
|
||||||
if let longAction = self.longAction(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
if let longAction = self.longAction(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.longTapClosure = longAction
|
item.actions.append(ItemAction(trigger: .longTap, longAction))
|
||||||
|
}
|
||||||
|
|
||||||
|
if let touchBarItem = barItem as? CustomButtonTouchBarItem {
|
||||||
|
for action in item.actions {
|
||||||
|
touchBarItem.actions.append(ItemAction(trigger: action.trigger, self.closure(for: action)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if case let .bordered(bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
if case let .bordered(bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.isBordered = bordered
|
item.isBordered = bordered
|
||||||
@ -330,9 +425,53 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
return barItem
|
return barItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func closure(for action: Action) -> (() -> Void)? {
|
||||||
|
switch action.value {
|
||||||
|
case let .hidKey(keycode: keycode):
|
||||||
|
return { HIDPostAuxKey(keycode) }
|
||||||
|
case let .keyPress(keycode: keycode):
|
||||||
|
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
||||||
|
case let .appleScript(source: source):
|
||||||
|
guard let appleScript = source.appleScript else {
|
||||||
|
print("cannot create apple script for item \(action)")
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
DispatchQueue.appleScriptQueue.async {
|
||||||
|
var error: NSDictionary?
|
||||||
|
appleScript.executeAndReturnError(&error)
|
||||||
|
if let error = error {
|
||||||
|
print("error \(error) when handling \(action) ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case let .shellScript(executable: executable, parameters: parameters):
|
||||||
|
return {
|
||||||
|
let task = Process()
|
||||||
|
task.launchPath = executable
|
||||||
|
task.arguments = parameters
|
||||||
|
task.launch()
|
||||||
|
}
|
||||||
|
case let .openUrl(url: url):
|
||||||
|
return {
|
||||||
|
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
||||||
|
#if DEBUG
|
||||||
|
print("URL was successfully opened")
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
print("error", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case let .custom(closure: closure):
|
||||||
|
return closure
|
||||||
|
case .none:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func action(forItem item: BarItemDefinition) -> (() -> Void)? {
|
func action(forItem item: BarItemDefinition) -> (() -> Void)? {
|
||||||
switch item.action {
|
switch item.legacyAction {
|
||||||
case let .hidKey(keycode: keycode):
|
case let .hidKey(keycode: keycode):
|
||||||
return { HIDPostAuxKey(keycode) }
|
return { HIDPostAuxKey(keycode) }
|
||||||
case let .keyPress(keycode: keycode):
|
case let .keyPress(keycode: keycode):
|
||||||
@ -376,7 +515,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func longAction(forItem item: BarItemDefinition) -> (() -> Void)? {
|
func longAction(forItem item: BarItemDefinition) -> (() -> Void)? {
|
||||||
switch item.longAction {
|
switch item.legacyLongAction {
|
||||||
case let .hidKey(keycode: keycode):
|
case let .hidKey(keycode: keycode):
|
||||||
return { HIDPostAuxKey(keycode) }
|
return { HIDPostAuxKey(keycode) }
|
||||||
case let .keyPress(keycode: keycode):
|
case let .keyPress(keycode: keycode):
|
||||||
@ -428,6 +567,12 @@ extension NSCustomTouchBarItem: CanSetWidth {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension NSPopoverTouchBarItem: CanSetWidth {
|
||||||
|
func setWidth(value: CGFloat) {
|
||||||
|
view?.widthAnchor.constraint(equalToConstant: value).isActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension BarItemDefinition {
|
extension BarItemDefinition {
|
||||||
var align: Align {
|
var align: Align {
|
||||||
if case let .align(result)? = additionalParameters[.align] {
|
if case let .align(result)? = additionalParameters[.align] {
|
||||||
|
|||||||
@ -82,12 +82,14 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem {
|
|||||||
public func createAppButton(for app: DockItem) -> DockBarItem {
|
public func createAppButton(for app: DockItem) -> DockBarItem {
|
||||||
let item = DockBarItem(app)
|
let item = DockBarItem(app)
|
||||||
item.isBordered = false
|
item.isBordered = false
|
||||||
item.tapClosure = { [weak self] in
|
item.actions.append(contentsOf: [
|
||||||
self?.switchToApp(app: app)
|
ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
}
|
self?.switchToApp(app: app)
|
||||||
item.longTapClosure = { [weak self] in
|
},
|
||||||
self?.handleHalfLongPress(item: app)
|
ItemAction(trigger: .longTap) { [weak self] in
|
||||||
}
|
self?.handleHalfLongPress(item: app)
|
||||||
|
}
|
||||||
|
])
|
||||||
item.killAppClosure = {[weak self] in
|
item.killAppClosure = {[weak self] in
|
||||||
self?.handleLongPress(item: app)
|
self?.handleLongPress(item: app)
|
||||||
}
|
}
|
||||||
|
|||||||
82
MTMR/Widgets/CPUBarItem.swift
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// CPUBarItem.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by bobrosoft on 17/08/2021.
|
||||||
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class CPUBarItem: CustomButtonTouchBarItem {
|
||||||
|
private let refreshInterval: TimeInterval
|
||||||
|
private var refreshQueue: DispatchQueue? = DispatchQueue(label: "mtmr.cpu")
|
||||||
|
private let defaultSingleTapScript: NSAppleScript! = "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell".appleScript
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, refreshInterval: TimeInterval) {
|
||||||
|
self.refreshInterval = refreshInterval
|
||||||
|
super.init(identifier: identifier, title: "⏳")
|
||||||
|
|
||||||
|
// Set default image
|
||||||
|
if self.image == nil {
|
||||||
|
self.image = #imageLiteral(resourceName: "cpu").resize(maxSize: NSSize(width: 24, height: 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default action
|
||||||
|
if actions.filter({ $0.trigger == .singleTap }).isEmpty {
|
||||||
|
actions.append(ItemAction(
|
||||||
|
trigger: .singleTap,
|
||||||
|
defaultTapAction
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshAndSchedule()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshAndSchedule() {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
// Get CPU load
|
||||||
|
let usage = 100 - CPU.systemUsage().idle
|
||||||
|
guard usage.isFinite else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose color based on CPU load
|
||||||
|
var color: NSColor? = nil
|
||||||
|
var bgColor: NSColor? = nil
|
||||||
|
if usage > 70 {
|
||||||
|
color = .black
|
||||||
|
bgColor = .yellow
|
||||||
|
} else if usage > 30 {
|
||||||
|
color = .yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update layout
|
||||||
|
let attrTitle = NSMutableAttributedString.init(attributedString: String(format: "%.1f%%", usage).defaultTouchbarAttributedString)
|
||||||
|
if let color = color {
|
||||||
|
attrTitle.addAttributes([.foregroundColor: color], range: NSRange(location: 0, length: attrTitle.length))
|
||||||
|
}
|
||||||
|
self.attributedTitle = attrTitle
|
||||||
|
self.backgroundColor = bgColor
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshQueue?.asyncAfter(deadline: .now() + refreshInterval) { [weak self] in
|
||||||
|
self?.refreshAndSchedule()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultTapAction() {
|
||||||
|
refreshQueue?.async { [weak self] in
|
||||||
|
self?.defaultSingleTapScript.executeAndReturnError(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
refreshQueue?.suspend()
|
||||||
|
refreshQueue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -38,6 +38,13 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
"BTC": "฿",
|
"BTC": "฿",
|
||||||
"LTC": "Ł",
|
"LTC": "Ł",
|
||||||
"ETH": "Ξ",
|
"ETH": "Ξ",
|
||||||
|
"SOL": "◎",
|
||||||
|
"DOT": "●",
|
||||||
|
"DOGE": "Ð",
|
||||||
|
"XMR": "ɱ",
|
||||||
|
"ADA": "₳",
|
||||||
|
"PLN": "zł",
|
||||||
|
"UAH": "₴",
|
||||||
]
|
]
|
||||||
private let decimals = [
|
private let decimals = [
|
||||||
"USD": 4,
|
"USD": 4,
|
||||||
@ -54,9 +61,13 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
"MXN": 2,
|
"MXN": 2,
|
||||||
"SGD": 4,
|
"SGD": 4,
|
||||||
"CHF": 4,
|
"CHF": 4,
|
||||||
"BTC": 2,
|
"BTC": 3,
|
||||||
"LTC": 2,
|
"LTC": 2,
|
||||||
"ETH": 2,
|
"ETH": 2,
|
||||||
|
"DOT": 3,
|
||||||
|
"DOGE": 4,
|
||||||
|
"ADA": 3,
|
||||||
|
"USDT": 3
|
||||||
]
|
]
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, full: Bool) {
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, full: Bool) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ class DarkModeBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
isBordered = false
|
isBordered = false
|
||||||
setWidth(value: 24)
|
setWidth(value: 24)
|
||||||
|
|
||||||
tapClosure = { [weak self] in self?.DarkModeToggle() }
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in self?.DarkModeToggle() })
|
||||||
|
|
||||||
timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class DnDBarItem: CustomButtonTouchBarItem {
|
|||||||
isBordered = false
|
isBordered = false
|
||||||
setWidth(value: 32)
|
setWidth(value: 32)
|
||||||
|
|
||||||
tapClosure = { [weak self] in self?.DnDToggle() }
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in self?.DnDToggle() })
|
||||||
|
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,10 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
observeIputSourceChangedNotification()
|
observeIputSourceChangedNotification()
|
||||||
textInputSourceDidChange()
|
textInputSourceDidChange()
|
||||||
tapClosure = { [weak self] in
|
|
||||||
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
self?.switchInputSource()
|
self?.switchInputSource()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder _: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
|
|||||||
@ -41,9 +41,12 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
super.init(identifier: identifier, title: "⏳")
|
super.init(identifier: identifier, title: "⏳")
|
||||||
isBordered = false
|
isBordered = false
|
||||||
|
|
||||||
tapClosure = { [weak self] in self?.playPause() }
|
actions = [
|
||||||
longTapClosure = { [weak self] in self?.nextTrack() }
|
ItemAction(trigger: .singleTap) { [weak self] in self?.playPause() },
|
||||||
|
ItemAction(trigger: .doubleTap) { [weak self] in self?.previousTrack() },
|
||||||
|
ItemAction(trigger: .longTap) { [weak self] in self?.nextTrack() }
|
||||||
|
]
|
||||||
|
|
||||||
refreshAndSchedule()
|
refreshAndSchedule()
|
||||||
}
|
}
|
||||||
@ -177,6 +180,31 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func previousTrack() {
|
||||||
|
for ident in playerBundleIdentifiers {
|
||||||
|
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||||
|
if musicPlayer.isRunning {
|
||||||
|
if ident == .Spotify {
|
||||||
|
let mp = (musicPlayer as SpotifyApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
} else if ident == .iTunes {
|
||||||
|
let mp = (musicPlayer as iTunesApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
} else if ident == .Music {
|
||||||
|
let mp = (musicPlayer as MusicApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func refreshAndSchedule() {
|
func refreshAndSchedule() {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|||||||
@ -13,9 +13,11 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
static var identifier: String = "com.toxblh.mtmr.network"
|
static var identifier: String = "com.toxblh.mtmr.network"
|
||||||
|
|
||||||
private let flip: Bool
|
private let flip: Bool
|
||||||
|
private let units: String
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, flip: Bool = false) {
|
init(identifier: NSTouchBarItem.Identifier, flip: Bool = false, units: String) {
|
||||||
self.flip = flip
|
self.flip = flip
|
||||||
|
self.units = units
|
||||||
super.init(identifier: identifier, title: " ")
|
super.init(identifier: identifier, title: " ")
|
||||||
startMonitoringProcess()
|
startMonitoringProcess()
|
||||||
}
|
}
|
||||||
@ -86,15 +88,42 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
|
|
||||||
func getHumanizeSize(speed: UInt64) -> String {
|
func getHumanizeSize(speed: UInt64) -> String {
|
||||||
let humanText: String
|
let humanText: String
|
||||||
|
|
||||||
if speed < 1024 {
|
func speedB(speed: UInt64)-> String {
|
||||||
humanText = String(format: "%.0f", Double(speed)) + " B/s"
|
return String(format: "%.0f", Double(speed)) + " B/s"
|
||||||
} else if speed < (1024 * 1024) {
|
}
|
||||||
humanText = String(format: "%.1f", Double(speed) / 1024) + " KB/s"
|
|
||||||
} else if speed < (1024 * 1024 * 1024) {
|
func speedKB(speed: UInt64)-> String {
|
||||||
humanText = String(format: "%.1f", Double(speed) / (1024 * 1024)) + " MB/s"
|
return String(format: "%.1f", Double(speed) / 1024) + " KB/s"
|
||||||
} else {
|
}
|
||||||
humanText = String(format: "%.2f", Double(speed) / (1024 * 1024 * 1024)) + " GB/s"
|
|
||||||
|
func speedMB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.1f", Double(speed) / (1024 * 1024)) + " MB/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
func speedGB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.2f", Double(speed) / (1024 * 1024 * 1024)) + " GB/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch self.units {
|
||||||
|
case "B/s":
|
||||||
|
humanText = speedB(speed: speed)
|
||||||
|
case "KB/s":
|
||||||
|
humanText = speedKB(speed: speed)
|
||||||
|
case "MB/s":
|
||||||
|
humanText = speedMB(speed: speed)
|
||||||
|
case "GB/s":
|
||||||
|
humanText = speedGB(speed: speed)
|
||||||
|
default:
|
||||||
|
if speed < 1024 {
|
||||||
|
humanText = speedB(speed: speed)
|
||||||
|
} else if speed < (1024 * 1024) {
|
||||||
|
humanText = speedKB(speed: speed)
|
||||||
|
} else if speed < (1024 * 1024 * 1024) {
|
||||||
|
humanText = speedMB(speed: speed)
|
||||||
|
} else {
|
||||||
|
humanText = speedGB(speed: speed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return humanText
|
return humanText
|
||||||
|
|||||||
@ -30,8 +30,8 @@ class NightShiftBarItem: CustomButtonTouchBarItem {
|
|||||||
super.init(identifier: identifier, title: "")
|
super.init(identifier: identifier, title: "")
|
||||||
isBordered = false
|
isBordered = false
|
||||||
setWidth(value: 28)
|
setWidth(value: 28)
|
||||||
|
|
||||||
tapClosure = { [weak self] in self?.nightShiftAction() }
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in self?.nightShiftAction() })
|
||||||
|
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
|
|||||||
@ -23,8 +23,9 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300),
|
item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300),
|
||||||
action: .none,
|
actions: [],
|
||||||
longAction: .none,
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -50,8 +51,10 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
|||||||
self.workTime = workTime
|
self.workTime = workTime
|
||||||
self.restTime = restTime
|
self.restTime = restTime
|
||||||
super.init(identifier: identifier, title: defaultTitle)
|
super.init(identifier: identifier, title: defaultTitle)
|
||||||
tapClosure = { [weak self] in self?.startStopWork() }
|
actions.append(contentsOf: [
|
||||||
longTapClosure = { [weak self] in self?.startStopRest() }
|
ItemAction(trigger: .singleTap) { [weak self] in self?.startStopWork() },
|
||||||
|
ItemAction(trigger: .longTap) { [weak self] in self?.startStopRest() }
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder _: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
|
|||||||
256
MTMR/Widgets/UpNextScrubberTouchBarItem.swift
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
//
|
||||||
|
// UpNextScrubberTouchBarItems.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Connor Meehan on 13/7/20.
|
||||||
|
// Copyright © 2020 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import EventKit
|
||||||
|
|
||||||
|
class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||||
|
// Dependencies
|
||||||
|
private let scrollView = NSScrollView()
|
||||||
|
private let activity: NSBackgroundActivityScheduler // Update scheduler
|
||||||
|
private var eventSources : [IUpNextSource] = []
|
||||||
|
private var items: [UpNextItem] = []
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
private var futureSearchCutoff: Double
|
||||||
|
private var pastSearchCutoff: Double
|
||||||
|
private var maxToShow: Int
|
||||||
|
private var widthConstraint: NSLayoutConstraint?
|
||||||
|
private var autoResize: Bool = false
|
||||||
|
|
||||||
|
/// <#Description#>
|
||||||
|
/// - Parameters:
|
||||||
|
/// - identifier: Unique identifier of widget
|
||||||
|
/// - interval: Update view interval in seconds
|
||||||
|
/// - from: Relative to current time, how far back we search for events in hours
|
||||||
|
/// - to: Relative to current time, how far forward we search for events in hours
|
||||||
|
/// - maxToShow: Which event to show (1 is first, 2 is second, and so on)
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: Double, to: Double, maxToShow: Int, autoResize: Bool) {
|
||||||
|
// Initialise member properties
|
||||||
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updateCheck")
|
||||||
|
pastSearchCutoff = from * 3600
|
||||||
|
futureSearchCutoff = to * 3600
|
||||||
|
self.maxToShow = maxToShow
|
||||||
|
self.autoResize = autoResize
|
||||||
|
UpNextItem.df.dateFormat = "HH:mm"
|
||||||
|
// Error handling
|
||||||
|
if (maxToShow <= 0) {
|
||||||
|
fatalError("Error on UpNext bar item. maxToShow property must be greater than 0.")
|
||||||
|
}
|
||||||
|
// Init super
|
||||||
|
super.init(identifier: identifier)
|
||||||
|
view = scrollView
|
||||||
|
// Add event sources
|
||||||
|
// Can optionally pass an update view callback to an event source to redraw element
|
||||||
|
self.eventSources.append(UpNextCalenderSource(updateCallback: self.updateView))
|
||||||
|
// Fallback interactivity via interval
|
||||||
|
activity.interval = interval
|
||||||
|
activity.repeats = true
|
||||||
|
activity.qualityOfService = .utility
|
||||||
|
activity.schedule { (completion: NSBackgroundActivityScheduler.CompletionHandler) in
|
||||||
|
self.updateView()
|
||||||
|
completion(NSBackgroundActivityScheduler.Result.finished)
|
||||||
|
}
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateView() -> Void {
|
||||||
|
items = []
|
||||||
|
var upcomingEvents = self.getUpcomingEvents()
|
||||||
|
upcomingEvents.sort(by: {$0.startDate.compare($1.startDate) == .orderedAscending})
|
||||||
|
var index = 1
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
for event in upcomingEvents {
|
||||||
|
// Create UpNextItem
|
||||||
|
let item = UpNextItem(event: event)
|
||||||
|
item.backgroundColor = self.getBackgroundColor(startDate: event.startDate)
|
||||||
|
// Bind tap event
|
||||||
|
item.actions.append(ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
|
self?.switchToApp(event: event)
|
||||||
|
})
|
||||||
|
// Add to view
|
||||||
|
self.items.append(item)
|
||||||
|
// Check if should display any more
|
||||||
|
if (index == self.maxToShow) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
self.reloadData()
|
||||||
|
self.updateSize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reloadData() {
|
||||||
|
let stackView = NSStackView(views: items.compactMap { $0.view })
|
||||||
|
stackView.spacing = 5
|
||||||
|
stackView.orientation = .horizontal
|
||||||
|
let visibleRect = self.scrollView.documentVisibleRect
|
||||||
|
self.scrollView.documentView = stackView
|
||||||
|
stackView.scroll(visibleRect.origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateSize() {
|
||||||
|
if self.autoResize {
|
||||||
|
self.widthConstraint?.isActive = false
|
||||||
|
|
||||||
|
let width = self.scrollView.documentView?.fittingSize.width ?? 0
|
||||||
|
self.widthConstraint = self.scrollView.widthAnchor.constraint(equalToConstant: width)
|
||||||
|
self.widthConstraint!.isActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private func getUpcomingEvents() -> [UpNextEventModel] {
|
||||||
|
var upcomingEvents: [UpNextEventModel] = []
|
||||||
|
|
||||||
|
// Calculate the range we're going to search for events in
|
||||||
|
let dateLowerBounds = Date(timeIntervalSinceNow: self.pastSearchCutoff)
|
||||||
|
let dateUpperBounds = Date(timeIntervalSinceNow: self.futureSearchCutoff)
|
||||||
|
|
||||||
|
// Get all events from all sources
|
||||||
|
for eventSource in self.eventSources {
|
||||||
|
if (eventSource.hasPermission) {
|
||||||
|
let events = eventSource.getUpcomingEvents(dateLowerBounds: dateLowerBounds, dateUpperBounds: dateUpperBounds)
|
||||||
|
upcomingEvents.append(contentsOf: events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return upcomingEvents
|
||||||
|
}
|
||||||
|
|
||||||
|
public func switchToApp(event: UpNextEventModel) {
|
||||||
|
var bundleIdentifier: String
|
||||||
|
switch(event.sourceType) {
|
||||||
|
case .iCalendar:
|
||||||
|
bundleIdentifier = UpNextCalenderSource.bundleIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
||||||
|
|
||||||
|
// NB: if you can't open app which on another space, try to check mark
|
||||||
|
// "When switching to an application, switch to a Space with open windows for the application"
|
||||||
|
// in Mission control settings
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func getBackgroundColor(startDate: Date) -> NSColor {
|
||||||
|
let distance = startDate.timeIntervalSinceReferenceDate/60 - Date().timeIntervalSinceReferenceDate/60 // Get time difference in minutes
|
||||||
|
if (distance < 0 as TimeInterval) { // If it's in the past, draw as blue
|
||||||
|
return NSColor.systemBlue
|
||||||
|
} else if (distance < 30 as TimeInterval) { // Less than 30 minutes, backround is red
|
||||||
|
return NSColor.systemRed
|
||||||
|
}
|
||||||
|
return NSColor.clear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class UpNextItem : CustomButtonTouchBarItem {
|
||||||
|
static public let df = DateFormatter()
|
||||||
|
|
||||||
|
init(event: UpNextEventModel) {
|
||||||
|
let identifier = UpNextItem.getIdentifier(event: event)
|
||||||
|
let title = UpNextItem.getTitle(event: event)
|
||||||
|
super.init(identifier: NSTouchBarItem.Identifier(rawValue: identifier), title: title)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func getTitle(event: UpNextEventModel) -> String {
|
||||||
|
var title = ""
|
||||||
|
let startDateString = UpNextItem.df.string(for: event.startDate)
|
||||||
|
switch event.sourceType {
|
||||||
|
case .iCalendar:
|
||||||
|
title = String.init(format: "🗓 %@ - %@ ", event.title, startDateString!)
|
||||||
|
}
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func getIdentifier(event: UpNextEventModel) -> String {
|
||||||
|
var identifier : String
|
||||||
|
switch event.sourceType {
|
||||||
|
case .iCalendar:
|
||||||
|
identifier = "com.mtmr.iCalendarEvent"
|
||||||
|
}
|
||||||
|
return identifier + "." + event.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum UpNextSourceType {
|
||||||
|
case iCalendar
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model for events to be displayed in dock
|
||||||
|
struct UpNextEventModel {
|
||||||
|
let title: String
|
||||||
|
let startDate: Date
|
||||||
|
let sourceType: UpNextSourceType
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Interface for any event source
|
||||||
|
protocol IUpNextSource {
|
||||||
|
static var bundleIdentifier: String { get }
|
||||||
|
var hasPermission : Bool { get }
|
||||||
|
var updateCallback : () -> Void { get set }
|
||||||
|
|
||||||
|
init(updateCallback: @escaping () -> Void)
|
||||||
|
func getUpcomingEvents(dateLowerBounds: Date, dateUpperBounds: Date) -> [UpNextEventModel]
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpNextCalenderSource : IUpNextSource {
|
||||||
|
static public let bundleIdentifier: String = "com.apple.iCal"
|
||||||
|
|
||||||
|
public var hasPermission: Bool = false
|
||||||
|
private var eventStore : EKEventStore
|
||||||
|
internal var updateCallback: () -> Void
|
||||||
|
|
||||||
|
required init(updateCallback: @escaping () -> Void = {}) {
|
||||||
|
self.updateCallback = updateCallback
|
||||||
|
eventStore = EKEventStore()
|
||||||
|
NotificationCenter.default.addObserver(forName: .EKEventStoreChanged, object: eventStore, queue: nil, using: handleUpdate)
|
||||||
|
let authStatus = EKEventStore.authorizationStatus(for: .event)
|
||||||
|
if (authStatus != .authorized) {
|
||||||
|
eventStore.requestAccess(to: .event){ granted, error in
|
||||||
|
self.hasPermission = granted;
|
||||||
|
self.handleUpdate()
|
||||||
|
if(!granted) {
|
||||||
|
NSLog("Error: MTMR UpNextBarWidget not given calendar access.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.handleUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public func handleUpdate() {
|
||||||
|
self.handleUpdate(note: Notification(name: Notification.Name("refresh view")))
|
||||||
|
}
|
||||||
|
public func handleUpdate(note: Notification) {
|
||||||
|
self.updateCallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getUpcomingEvents(dateLowerBounds: Date, dateUpperBounds: Date) -> [UpNextEventModel] {
|
||||||
|
var upcomingEvents: [UpNextEventModel] = []
|
||||||
|
let calendars = self.eventStore.calendars(for: .event)
|
||||||
|
let predicate = self.eventStore.predicateForEvents(withStart: dateLowerBounds, end: dateUpperBounds, calendars: calendars)
|
||||||
|
let events = self.eventStore.events(matching: predicate)
|
||||||
|
for event in events {
|
||||||
|
upcomingEvents.append(UpNextEventModel(title: event.title, startDate: event.startDate, sourceType: UpNextSourceType.iCalendar))
|
||||||
|
}
|
||||||
|
return upcomingEvents
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,18 +5,11 @@ import CoreAudio
|
|||||||
|
|
||||||
class VolumeViewController: NSCustomTouchBarItem {
|
class VolumeViewController: NSCustomTouchBarItem {
|
||||||
private(set) var sliderItem: CustomSlider!
|
private(set) var sliderItem: CustomSlider!
|
||||||
|
private var currentDeviceId: AudioObjectID = AudioObjectID(0)
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, image: NSImage? = nil) {
|
init(identifier: NSTouchBarItem.Identifier, image: NSImage? = nil) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
|
||||||
var forPropertyAddress = AudioObjectPropertyAddress(
|
|
||||||
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume,
|
|
||||||
mScope: kAudioDevicePropertyScopeOutput,
|
|
||||||
mElement: kAudioObjectPropertyElementMaster
|
|
||||||
)
|
|
||||||
|
|
||||||
AudioObjectAddPropertyListenerBlock(defaultDeviceID, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
|
||||||
|
|
||||||
if image == nil {
|
if image == nil {
|
||||||
sliderItem = CustomSlider()
|
sliderItem = CustomSlider()
|
||||||
} else {
|
} else {
|
||||||
@ -29,6 +22,49 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
sliderItem.floatValue = getInputGain() * 100
|
sliderItem.floatValue = getInputGain() * 100
|
||||||
|
|
||||||
view = sliderItem
|
view = sliderItem
|
||||||
|
|
||||||
|
currentDeviceId = defaultDeviceID
|
||||||
|
self.addAudioRouteChangedListener()
|
||||||
|
self.addCurrentAudioVolumeChangedListener()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func addAudioRouteChangedListener() {
|
||||||
|
let audioId = AudioObjectID(bitPattern: kAudioObjectSystemObject)
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwarePropertyDefaultOutputDevice,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster)
|
||||||
|
AudioObjectAddPropertyListenerBlock(audioId, &forPropertyAddress, nil, audioRouteChanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func audioRouteChanged(numberAddresses _: UInt32, addresses _: UnsafePointer<AudioObjectPropertyAddress>) {
|
||||||
|
self.removeLastAudioVolumeChangeListener()
|
||||||
|
currentDeviceId = defaultDeviceID
|
||||||
|
self.addCurrentAudioVolumeChangedListener()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.sliderItem.floatValue = self.getInputGain() * 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func addCurrentAudioVolumeChangedListener() {
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||||
|
mScope: kAudioDevicePropertyScopeOutput,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster
|
||||||
|
)
|
||||||
|
|
||||||
|
AudioObjectAddPropertyListenerBlock(defaultDeviceID, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removeLastAudioVolumeChangeListener() {
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||||
|
mScope: kAudioDevicePropertyScopeOutput,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster
|
||||||
|
)
|
||||||
|
|
||||||
|
AudioObjectRemovePropertyListenerBlock(currentDeviceId, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
func audioObjectPropertyListenerBlock(numberAddresses _: UInt32, addresses _: UnsafePointer<AudioObjectPropertyAddress>) {
|
func audioObjectPropertyListenerBlock(numberAddresses _: UInt32, addresses _: UnsafePointer<AudioObjectPropertyAddress>) {
|
||||||
@ -66,7 +102,7 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
var volume: Float32 = 0.5
|
var volume: Float32 = 0.5
|
||||||
var size: UInt32 = UInt32(MemoryLayout.size(ofValue: volume))
|
var size: UInt32 = UInt32(MemoryLayout.size(ofValue: volume))
|
||||||
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
||||||
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMasterVolume)
|
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMainVolume)
|
||||||
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
||||||
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
||||||
AudioObjectGetPropertyData(defaultDeviceID, &address, 0, nil, &size, &volume)
|
AudioObjectGetPropertyData(defaultDeviceID, &address, 0, nil, &size, &volume)
|
||||||
@ -86,7 +122,7 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
||||||
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
||||||
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
||||||
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMasterVolume)
|
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMainVolume)
|
||||||
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &inputVolume)
|
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &inputVolume)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,12 +13,26 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
|||||||
private let activity: NSBackgroundActivityScheduler
|
private let activity: NSBackgroundActivityScheduler
|
||||||
private let unitsStr = "°C"
|
private let unitsStr = "°C"
|
||||||
private let iconsSource = [
|
private let iconsSource = [
|
||||||
"Ясно": "☀️", "Малооблачно": "🌤", "Облачно с прояснениями": "⛅️", "Пасмурно": "☁️", "Небольшой дождь": "🌦", "Дождь": "🌧", "Ливень": "⛈", "Гроза": "🌩", "Дождь со снегом": "☔️", "Небольшой снег": "❄️", "Снег": "🌨", "Туман": "🌫",
|
"clear": "☀️",
|
||||||
"Clear": "☀️", "Mostly clear": "🌤", "Partly cloudy": "⛅️", "Overcast": "☁️", "Light rain": "🌦", "Rain": "🌧", "Heavy rain": "⛈", "Storm": "🌩", "Sleet": "☔️", "Light snow": "❄️", "Snow": "🌨", "Fog": "🌫"
|
"mostly-clear": "🌤",
|
||||||
|
"partly-cloudy": "⛅️",
|
||||||
|
"overcast": "☁️",
|
||||||
|
"cloudy": "☁️",
|
||||||
|
"light-rain": "🌦",
|
||||||
|
"drizzle": "💦",
|
||||||
|
"rain": "🌧",
|
||||||
|
"heavy-rain": "⛈",
|
||||||
|
"storm": "🌩",
|
||||||
|
"thunderstorm-with-rain": "⛈",
|
||||||
|
"sleet": "☔️",
|
||||||
|
"light-snow": "❄️",
|
||||||
|
"snow": "🌨",
|
||||||
|
"fog": "🌫"
|
||||||
]
|
]
|
||||||
private var location: CLLocation!
|
private var location: CLLocation!
|
||||||
private var prevLocation: CLLocation!
|
private var prevLocation: CLLocation!
|
||||||
private var manager: CLLocationManager!
|
private var manager: CLLocationManager!
|
||||||
|
private var updateWeatherTask: URLSessionDataTask?
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
||||||
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||||
@ -49,8 +63,13 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
|||||||
manager.delegate = self
|
manager.delegate = self
|
||||||
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
||||||
manager.startUpdatingLocation()
|
manager.startUpdatingLocation()
|
||||||
|
|
||||||
tapClosure = tapClosure ?? defaultTapAction
|
if actions.filter({ $0.trigger == .singleTap }).isEmpty {
|
||||||
|
actions.append(ItemAction(
|
||||||
|
trigger: .singleTap,
|
||||||
|
defaultTapAction
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder _: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
@ -61,7 +80,8 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
|||||||
var urlRequest = URLRequest(url: URL(string: getWeatherUrl())!)
|
var urlRequest = URLRequest(url: URL(string: getWeatherUrl())!)
|
||||||
urlRequest.addValue("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36", forHTTPHeaderField: "user-agent") // important for the right format
|
urlRequest.addValue("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36", forHTTPHeaderField: "user-agent") // important for the right format
|
||||||
|
|
||||||
let task = URLSession.shared.dataTask(with: urlRequest) { data, _, error in
|
updateWeatherTask?.cancel()
|
||||||
|
updateWeatherTask = URLSession.shared.dataTask(with: urlRequest) { data, _, error in
|
||||||
guard error == nil, let response = data?.utf8string else {
|
guard error == nil, let response = data?.utf8string else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -73,7 +93,7 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
|||||||
temperature = matches.first?.item(at: 1)
|
temperature = matches.first?.item(at: 1)
|
||||||
|
|
||||||
var icon: String?
|
var icon: String?
|
||||||
matches = response.matchingStrings(regex: "link__condition.*?>(.*?)<")
|
matches = response.matchingStrings(regex: "\"condition\":\"(.*?)\"")
|
||||||
icon = matches.first?.item(at: 1)
|
icon = matches.first?.item(at: 1)
|
||||||
if let _ = icon, let test = self.iconsSource[icon!] {
|
if let _ = icon, let test = self.iconsSource[icon!] {
|
||||||
icon = test
|
icon = test
|
||||||
@ -86,12 +106,12 @@ class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task.resume()
|
updateWeatherTask?.resume()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWeatherUrl() -> String {
|
func getWeatherUrl() -> String {
|
||||||
if location != nil {
|
if location != nil {
|
||||||
return "https://yandex.ru/pogoda/?lat=\(location.coordinate.latitude)&lon=\(location.coordinate.longitude)?lang=ru"
|
return "https://yandex.ru/pogoda/?lat=\(location.coordinate.latitude)&lon=\(location.coordinate.longitude)&lang=ru"
|
||||||
} else {
|
} else {
|
||||||
return "https://yandex.ru/pogoda/?lang=ru" // Yandex will try to determine your location by default
|
return "https://yandex.ru/pogoda/?lang=ru" // Yandex will try to determine your location by default
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .none? = result?.first?.action else {
|
guard result?.first?.actions.count == 0 else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -18,14 +18,29 @@ class ParseConfig: XCTestCase {
|
|||||||
|
|
||||||
func testButtonKeyCodeAction() {
|
func testButtonKeyCodeAction() {
|
||||||
let buttonKeycodeFixture = """
|
let buttonKeycodeFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123} ]
|
[ { "type": "staticButton", "title": "Pew", "actions": [ { "trigger": "singleTap", "action": "hidKey", "keycode": 123 } ] } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
||||||
guard case .staticButton("Pew")? = result?.first?.type else {
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .hidKey(keycode: 123)? = result?.first?.action else {
|
guard case .hidKey(keycode: 123)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
|
XCTFail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testButtonKeyCodeLegacyAction() {
|
||||||
|
let buttonKeycodeFixture = """
|
||||||
|
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123 } ]
|
||||||
|
""".data(using: .utf8)!
|
||||||
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
||||||
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
||||||
|
XCTFail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard case .hidKey(keycode: 123)? = result?.first?.legacyAction else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -40,7 +55,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -55,7 +70,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
170
README.md
@ -14,11 +14,11 @@ My idea is to create a platform for creating plugins to customize the TouchBar.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://discord.gg/CmNcDuQ"><img height="20px" src="https://camo.githubusercontent.com/88f53948f291c54736bf08f5fd7b037a848dfc62/68747470733a2f2f646973636f72646170702e636f6d2f6173736574732f30376463613830613130326434313439653937333664346231363263666636662e69636f"> Discord</a>
|
<a href="https://discord.gg/CmNcDuQ"><img height="20px" src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/62fddf0fde45a8baedcc7ee5_847541504914fd33810e70a0ea73177e%20(2)-1.png"> Discord</a>
|
||||||
<a href="https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g"><img height="20px" src="https://telegram.org/img/t_logo.png" /> Telegram</a>
|
<a href="https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g"><img height="20px" src="https://telegram.org/img/t_logo.png" /> Telegram</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center"><a href="https://www.paypal.me/toxblh/10" title="Donate via Paypal"><img height="36px" src="Resources/support_paypal.svg" alt="PayPal donate button" /></a>
|
<p align="center"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WUAAG2HH58WE4" title="Donate via Paypal"><img height="36px" src="Resources/support_paypal.svg" alt="PayPal donate button" /></a>
|
||||||
<a href="https://www.buymeacoffee.com/toxblh" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" height="36px" ></a>
|
<a href="https://www.buymeacoffee.com/toxblh" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" height="36px" ></a>
|
||||||
<a href="https://www.patreon.com/bePatron?u=9900748"><img height="36px" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" srcset="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png 2x"></a>
|
<a href="https://www.patreon.com/bePatron?u=9900748"><img height="36px" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" srcset="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png 2x"></a>
|
||||||
<a href="https://www.producthunt.com/posts/my-touchbar-my-rules-mtmr">
|
<a href="https://www.producthunt.com/posts/my-touchbar-my-rules-mtmr">
|
||||||
@ -27,11 +27,11 @@ My idea is to create a platform for creating plugins to customize the TouchBar.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- Download lastest [release](https://github.com/Toxblh/MTMR/releases) (.dmg) from github
|
- Download latest [release](https://github.com/Toxblh/MTMR/releases) (.dmg) from github
|
||||||
- Or via Homebrew `brew cask install mtmr`
|
- Or via Homebrew `brew install --cask mtmr`
|
||||||
- [Dario Prski](https://medium.com/@urdigitalpulse) has written a [fantastic article on medium](https://medium.com/@urdigitalpulse/customise-your-macbook-pro-touch-bar-966998e606b5) that goes into more detail on installing MTMR
|
- [Dario Prski](https://medium.com/@urdigitalpulse) has written a [fantastic article on medium](https://medium.com/@urdigitalpulse/customise-your-macbook-pro-touch-bar-966998e606b5) that goes into more detail on installing MTMR
|
||||||
|
|
||||||
**On first install** you need to allow access for MTMR in Accessibility otherwise buttons like <kbd>Esc</kbd>, <kbd>Volume</kbd>, <kbd>Brightness</kbd> and other system keys won't work
|
**On first install** you need to allow access for MTMR in Accessibility otherwise buttons like <kbd>Esc</kbd>, <kbd>Volume</kbd>, <kbd>Brightness</kbd> and other system keys won't work.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img width="450" alt="screenshot 2019-02-24 at 23 19 20" src="https://user-images.githubusercontent.com/2198153/53307057-2b078200-388c-11e9-8212-8c2b1aff0aa6.png">
|
<img width="450" alt="screenshot 2019-02-24 at 23 19 20" src="https://user-images.githubusercontent.com/2198153/53307057-2b078200-388c-11e9-8212-8c2b1aff0aa6.png">
|
||||||
@ -51,7 +51,7 @@ My idea is to create a platform for creating plugins to customize the TouchBar.
|
|||||||
|
|
||||||
## Customization
|
## Customization
|
||||||
|
|
||||||
MTMR preferences are stored under `~/Library/Application\ Support/MTMR/items.json`.
|
MTMR preferences are stored in `~/Library/Application\ Support/MTMR/items.json`.
|
||||||
|
|
||||||
The pre-installed configuration contains less or more than you'll probably want, try to configure:
|
The pre-installed configuration contains less or more than you'll probably want, try to configure:
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ The pre-installed configuration contains less or more than you'll probably want,
|
|||||||
|
|
||||||
- timeButton
|
- timeButton
|
||||||
- battery
|
- battery
|
||||||
|
- cpu
|
||||||
- currency
|
- currency
|
||||||
- weather
|
- weather
|
||||||
- yandexWeather
|
- yandexWeather
|
||||||
@ -84,6 +85,7 @@ The pre-installed configuration contains less or more than you'll probably want,
|
|||||||
- darkMode
|
- darkMode
|
||||||
- pomodoro
|
- pomodoro
|
||||||
- network
|
- network
|
||||||
|
- upnext (Calendar events)
|
||||||
|
|
||||||
> Media Keys
|
> Media Keys
|
||||||
|
|
||||||
@ -116,7 +118,7 @@ You can add custom actions for two/three/four finger swipes. To do it, you need
|
|||||||
"type": "swipe",
|
"type": "swipe",
|
||||||
"fingers": 2, // number of fingers required (2,3 or 4)
|
"fingers": 2, // number of fingers required (2,3 or 4)
|
||||||
"direction": "right", // direction of swipe (right/left)
|
"direction": "right", // direction of swipe (right/left)
|
||||||
"minOffset" 10, // optional: minimal required offset for gesture to emit event
|
"minOffset": 10, // optional: minimal required offset for gesture to emit event
|
||||||
"sourceApple": { // optional: apple script to run
|
"sourceApple": { // optional: apple script to run
|
||||||
"inline": "beep"
|
"inline": "beep"
|
||||||
},
|
},
|
||||||
@ -157,8 +159,8 @@ You may create as many `swipe` objects in the preset as you want.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: appleScriptTitledButton can change its icon. To do it, you need to do the following things:
|
> Note: You can change appleScriptTitledButton's icon by following these steps:
|
||||||
1. Declarate dictionary of icons in `alternativeImages` field
|
1. Declare dictionary of icons in `alternativeImages` field
|
||||||
2. Make you script return array of two values - `{"TITLE", "IMAGE_LABEL"}`
|
2. Make you script return array of two values - `{"TITLE", "IMAGE_LABEL"}`
|
||||||
3. Make sure that your `IMAGE_LABEL` is declared in `alternativeImages` field
|
3. Make sure that your `IMAGE_LABEL` is declared in `alternativeImages` field
|
||||||
|
|
||||||
@ -185,10 +187,10 @@ Example:
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### `shellScriptTitledButton`
|
#### `shellScriptTitledButton`
|
||||||
> Note: script may return also colors using escape sequences (read more here https://misc.flogisoft.com/bash/tip_colors_and_formatting)
|
> Note: script may also use escape sequences to return colors (read https://misc.flogisoft.com/bash/tip_colors_and_formatting for more information)
|
||||||
> Only "16 Colors" mode supported atm. If background color returned, button will pick it up as own background color.
|
> "16 Colors" is the only mode supported presently. Buttons will set their own background color to the color returned.
|
||||||
|
|
||||||
Example of "CPU load" button which also changes color based on load value.
|
Example of "CPU load" button which also changes color based on load value (Note: The native `cpu` plugin runs runs better):
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"type": "shellScriptTitledButton",
|
"type": "shellScriptTitledButton",
|
||||||
@ -197,10 +199,15 @@ Example of "CPU load" button which also changes color based on load value.
|
|||||||
"source": {
|
"source": {
|
||||||
"inline": "top -l 2 -n 0 -F | egrep -o ' \\d*\\.\\d+% idle' | tail -1 | awk -F% '{p = 100 - $1; if (p > 30) c = \"\\033[33m\"; if (p > 70) c = \"\\033[30;43m\"; printf \"%s%4.1f%%\\n\", c, p}'"
|
"inline": "top -l 2 -n 0 -F | egrep -o ' \\d*\\.\\d+% idle' | tail -1 | awk -F% '{p = 100 - $1; if (p > 30) c = \"\\033[33m\"; if (p > 70) c = \"\\033[30;43m\"; printf \"%s%4.1f%%\\n\", c, p}'"
|
||||||
},
|
},
|
||||||
"action": "appleScript",
|
"actions": [
|
||||||
"actionAppleScript": {
|
{
|
||||||
"inline": "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell"
|
"trigger": "singleTap",
|
||||||
},
|
"action": "appleScript",
|
||||||
|
"actionAppleScript": {
|
||||||
|
"inline": "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"align": "right",
|
"align": "right",
|
||||||
"image": {
|
"image": {
|
||||||
// Or you can specify a filePath here.
|
// Or you can specify a filePath here.
|
||||||
@ -240,9 +247,22 @@ To close a group, use the button:
|
|||||||
|
|
||||||
## Native plugins
|
## Native plugins
|
||||||
|
|
||||||
|
#### `cpu`
|
||||||
|
|
||||||
|
> Shows current CPU load in percent, changes color based on load value.
|
||||||
|
> Has lower power consumption and higher stability than the shell-based solution.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"refreshInterval": 3,
|
||||||
|
"width": 80
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### `timeButton`
|
#### `timeButton`
|
||||||
|
|
||||||
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
> NOTE: Some values don't work properly: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
||||||
|
|
||||||
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
|
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
|
||||||
|
|
||||||
@ -260,22 +280,22 @@ To close a group, use the button:
|
|||||||
#### `weather`
|
#### `weather`
|
||||||
|
|
||||||
> Provider: https://openweathermap.org \
|
> Provider: https://openweathermap.org \
|
||||||
> Note: you need to register on https://openweathermap.org to get your API key \
|
> Note: Register at https://openweathermap.org to get your API key \
|
||||||
> Note: you may need to wait for near 20 mins until your API key will be activated by Openweathermap \
|
> Note: Wait for 20 minutes or so for Openweathermap to activate your API key.\
|
||||||
> Note: you need to allow using "Location Services" in your Mac OS "Security & Privacy" settings for MTMR
|
> Note: Enable MTMR in "Location Services" in the "Security & Privacy" System Preferences pane
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"type": "weather",
|
"type": "weather",
|
||||||
"refreshInterval": 600, // in seconds
|
"refreshInterval": 600, // in seconds
|
||||||
"units": "metric", // or imperial
|
"units": "metric", // or imperial
|
||||||
"icon_type": "text" // or images
|
"icon_type": "text", // or images
|
||||||
"api_key": "" // you can get the key on openweather
|
"api_key": "" // you can get the key on openweather
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `yandexWeather` (experimental)
|
#### `yandexWeather` (experimental)
|
||||||
|
|
||||||
> Provider: https://yandex.ru/pogoda. One click to open up weather forecast in your browser. \
|
> Provider: https://yandex.ru/pogoda. One click to open up weather forecast in your browser. \
|
||||||
> Note: you need to allow using "Location Services" in your Mac OS "Security & Privacy" settings for MTMR
|
> Note: Enable MTMR in "Location Services" in the "Security & Privacy" System Preferences pane
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"type": "yandexWeather",
|
"type": "yandexWeather",
|
||||||
@ -310,7 +330,7 @@ To close a group, use the button:
|
|||||||
|
|
||||||
#### `pomodoro`
|
#### `pomodoro`
|
||||||
|
|
||||||
> Pomodoro plugin. One click to start the work timer, longclick to start the rest timer. Click in progress for reset.
|
> Pomodoro plugin. One tap starts the work timer, long-press to start the rest timer. Tap an in-progress timer to reset.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
@ -322,12 +342,13 @@ To close a group, use the button:
|
|||||||
|
|
||||||
#### `network`
|
#### `network`
|
||||||
|
|
||||||
> Network plugin. The plugin to show usage a network
|
> Network plugin. The plugin to show network usage
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"type": "network",
|
"type": "network",
|
||||||
"flip": true
|
"flip": true,
|
||||||
|
"units": "dynamic" // or B/s, KB/s, MB/s, GB/s
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -343,8 +364,46 @@ To close a group, use the button:
|
|||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `upnext`
|
||||||
|
|
||||||
|
> Calendar next event plugin
|
||||||
|
Displays upcoming events from macOS Calendar. Does not display current event.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "upnext",
|
||||||
|
"from": 0, // Lower bound of search range for next event in hours. Default 0 (current time)(can be negative to view events in the past)
|
||||||
|
"to": 12, // Upper bounds of search range for next event in hours. Default 12 (12 hours in the future)
|
||||||
|
"maxToShow": 3, // Limits the maximum number of events displayed. Default 3 (the first 3 upcoming events)
|
||||||
|
"autoResize": false // If true, widget will expand to display all events. Default false (scrollable view within "width")
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Actions:
|
## Actions:
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"trigger": "singleTap",
|
||||||
|
"action": "hidKey",
|
||||||
|
"keycode": 53
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Triggers:
|
||||||
|
|
||||||
|
- `singleTap`
|
||||||
|
- `doubleTap`
|
||||||
|
- `tripleTap`
|
||||||
|
- `longTap`
|
||||||
|
|
||||||
|
### Types
|
||||||
|
|
||||||
- `hidKey`
|
- `hidKey`
|
||||||
> https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers
|
> https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers
|
||||||
|
|
||||||
@ -354,6 +413,7 @@ To close a group, use the button:
|
|||||||
```
|
```
|
||||||
|
|
||||||
- `keyPress`
|
- `keyPress`
|
||||||
|
> https://eastmanreference.com/complete-list-of-applescript-key-codes
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"action": "keyPress",
|
"action": "keyPress",
|
||||||
@ -386,22 +446,6 @@ To close a group, use the button:
|
|||||||
"url": "https://google.com",
|
"url": "https://google.com",
|
||||||
```
|
```
|
||||||
|
|
||||||
## LongActions
|
|
||||||
|
|
||||||
If you want to longPress for some operations, it is similar to the configuration for Actions but with additional parameters, for example:
|
|
||||||
|
|
||||||
```js
|
|
||||||
"longAction": "hidKey",
|
|
||||||
"longKeycode": 53,
|
|
||||||
```
|
|
||||||
|
|
||||||
- longAction
|
|
||||||
- longKeycode
|
|
||||||
- longActionAppleScript
|
|
||||||
- longExecutablePath
|
|
||||||
- longShellArguments
|
|
||||||
- longUrl
|
|
||||||
|
|
||||||
## Additional parameters:
|
## Additional parameters:
|
||||||
|
|
||||||
- `width` restrict how much room a particular button will take
|
- `width` restrict how much room a particular button will take
|
||||||
@ -446,40 +490,28 @@ by using background with color "#000000" and bordered == false you can create bu
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `matchAppId` displays the button only when active app's id matches given regexp
|
||||||
|
|
||||||
### Roadmap
|
```json
|
||||||
|
"matchAppId": "Safari"
|
||||||
|
```
|
||||||
|
|
||||||
- [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!
|
|
||||||
- [x] First the weather plugin
|
|
||||||
- [x] Find how to open full-screen TouchBar without the cross and stripe menu
|
|
||||||
- [x] Find how to add haptic feedback
|
|
||||||
- [x] Add icon and menu in StatusBar
|
|
||||||
- [x] Hide from Dock
|
|
||||||
- [x] Status menu: "preferences", "quit"
|
|
||||||
- [x] JSON or another approch for save preset, maybe in `~/Library/Application Support/MTMR/`
|
|
||||||
- [x] Custom buttons size, actions by click
|
|
||||||
- [x] Layout: [always left, NSSliderView for center, always right]
|
|
||||||
- [x] System for autoupdate (https://sparkle-project.org/)
|
|
||||||
- [ ] Overwrite default values from item types (e.g. title for brightness)
|
|
||||||
- [ ] Custom settings for paddings and margins for buttons
|
|
||||||
- [ ] XPC Service for scripts
|
|
||||||
- [ ] UI for settings
|
|
||||||
- [ ] Import config from BTT
|
|
||||||
|
|
||||||
Settings:
|
## Troubleshooting
|
||||||
|
|
||||||
- [ ] Interface for plugins and export like presets
|
#### If you can't open preferences:
|
||||||
- [x] Startup at login
|
- Opening another program which can't edit text
|
||||||
- [ ] Show on/off in Dock
|
1. Open Terminal.app
|
||||||
- [ ] Show on/off in StatusBar
|
2. Put `open -a TextEdit ~/Library/Application\ Support/MTMR/items.json` command and press <kbd>Enter</kbd>
|
||||||
- [ x] On/off Haptic Feedback
|
|
||||||
|
|
||||||
Maybe:
|
|
||||||
|
|
||||||
- [ ] Refactoring the application into packages (AppleScript, JavaScript? and Swift?)
|
#### Buttons or gestures doesn't work:
|
||||||
|
- "After the last update my mtmr is not working anymore!"
|
||||||
|
- "Buttons sometimes do not trigger action"
|
||||||
|
- "ESC don't work"
|
||||||
|
- "Gestures don't work"
|
||||||
|
|
||||||
|
Re-tick or check a tick for access 🍏→ System Preferences → Security and Privacy → tab Privacy → Accessibility → MTMR
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 68 KiB |
1
Sparkle.framework/Autoupdate
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Autoupdate
|
||||||
1
Sparkle.framework/Updater.app
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Updater.app
|
||||||
@ -1,25 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUDownloader.h
|
|
||||||
// Downloader
|
|
||||||
//
|
|
||||||
// Created by Mayur Pawashe on 4/1/16.
|
|
||||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SPUDownloaderProtocol.h"
|
|
||||||
|
|
||||||
@protocol SPUDownloaderDelegate;
|
|
||||||
|
|
||||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
|
||||||
@interface SPUDownloader : NSObject <SPUDownloaderProtocol>
|
|
||||||
|
|
||||||
// Due to XPC remote object reasons, this delegate is strongly referenced
|
|
||||||
// Invoke cleanup when done with this instance
|
|
||||||
- (instancetype)initWithDelegate:(id <SPUDownloaderDelegate>)delegate;
|
|
||||||
|
|
||||||
@end
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUDownloaderDelegate.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Mayur Pawashe on 4/1/16.
|
|
||||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@class SPUDownloadData;
|
|
||||||
|
|
||||||
@protocol SPUDownloaderDelegate <NSObject>
|
|
||||||
|
|
||||||
// This is only invoked for persistent downloads
|
|
||||||
- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory;
|
|
||||||
|
|
||||||
// Under rare cases, this may be called more than once, in which case the current progress should be reset back to 0
|
|
||||||
// This is only invoked for persistent downloads
|
|
||||||
- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength;
|
|
||||||
|
|
||||||
// This is only invoked for persistent downloads
|
|
||||||
- (void)downloaderDidReceiveDataOfLength:(uint64_t)length;
|
|
||||||
|
|
||||||
// downloadData is nil if this is a persisent download, otherwise it's non-nil if it's a temporary download
|
|
||||||
- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData;
|
|
||||||
|
|
||||||
- (void)downloaderDidFailWithError:(NSError *)error;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUDownloaderDeprecated.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Deadpikle on 12/20/17.
|
|
||||||
// Copyright © 2017 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "SPUDownloader.h"
|
|
||||||
|
|
||||||
@interface SPUDownloaderDeprecated : SPUDownloader <SPUDownloaderProtocol>
|
|
||||||
|
|
||||||
@end
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUDownloaderProtocol.h
|
|
||||||
// PersistentDownloader
|
|
||||||
//
|
|
||||||
// Created by Mayur Pawashe on 4/1/16.
|
|
||||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@class SPUURLRequest;
|
|
||||||
|
|
||||||
// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service.
|
|
||||||
@protocol SPUDownloaderProtocol
|
|
||||||
|
|
||||||
- (void)startPersistentDownloadWithRequest:(SPUURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename;
|
|
||||||
|
|
||||||
- (void)startTemporaryDownloadWithRequest:(SPUURLRequest *)request;
|
|
||||||
|
|
||||||
- (void)downloadDidFinish;
|
|
||||||
|
|
||||||
- (void)cleanup;
|
|
||||||
|
|
||||||
- (void)cancel;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUDownloaderSession.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Deadpikle on 12/20/17.
|
|
||||||
// Copyright © 2017 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SPUDownloader.h"
|
|
||||||
#import "SPUDownloaderProtocol.h"
|
|
||||||
|
|
||||||
NS_CLASS_AVAILABLE(NSURLSESSION_AVAILABLE, 7_0)
|
|
||||||
@interface SPUDownloaderSession : SPUDownloader <SPUDownloaderProtocol>
|
|
||||||
|
|
||||||
@end
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
//
|
|
||||||
// SPUURLRequest.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Mayur Pawashe on 5/19/16.
|
|
||||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
// A class that wraps NSURLRequest and implements NSSecureCoding
|
|
||||||
// This class exists because NSURLRequest did not support NSSecureCoding in macOS 10.8
|
|
||||||
// I have not verified if NSURLRequest in 10.9 implements NSSecureCoding or not
|
|
||||||
@interface SPUURLRequest : NSObject <NSSecureCoding>
|
|
||||||
|
|
||||||
// Creates a new URL request
|
|
||||||
// Only these properties are currently tracked:
|
|
||||||
// * URL
|
|
||||||
// * Cache policy
|
|
||||||
// * Timeout interval
|
|
||||||
// * HTTP header fields
|
|
||||||
// * networkServiceType
|
|
||||||
+ (instancetype)URLRequestWithRequest:(NSURLRequest *)request;
|
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSURLRequest *request;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
//
|
|
||||||
// SUAppcast.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 3/12/06.
|
|
||||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SUAPPCAST_H
|
|
||||||
#define SUAPPCAST_H
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SUExport.h"
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@class SUAppcastItem;
|
|
||||||
SU_EXPORT @interface SUAppcast : NSObject
|
|
||||||
|
|
||||||
@property (copy, nullable) NSString *userAgentString;
|
|
||||||
@property (copy, nullable) NSDictionary<NSString *, NSString *> *httpHeaders;
|
|
||||||
|
|
||||||
- (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)bg completionBlock:(void (^)(NSError *_Nullable))err;
|
|
||||||
- (SUAppcast *)copyWithoutDeltaUpdates;
|
|
||||||
|
|
||||||
@property (readonly, copy, nullable) NSArray *items;
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,51 +0,0 @@
|
|||||||
//
|
|
||||||
// SUAppcastItem.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 3/12/06.
|
|
||||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SUAPPCASTITEM_H
|
|
||||||
#define SUAPPCASTITEM_H
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SUExport.h"
|
|
||||||
|
|
||||||
SU_EXPORT @interface SUAppcastItem : NSObject
|
|
||||||
@property (copy, readonly) NSString *title;
|
|
||||||
@property (copy, readonly) NSString *dateString;
|
|
||||||
@property (copy, readonly) NSString *itemDescription;
|
|
||||||
@property (strong, readonly) NSURL *releaseNotesURL;
|
|
||||||
@property (copy, readonly) NSString *DSASignature;
|
|
||||||
@property (copy, readonly) NSString *minimumSystemVersion;
|
|
||||||
@property (copy, readonly) NSString *maximumSystemVersion;
|
|
||||||
@property (strong, readonly) NSURL *fileURL;
|
|
||||||
@property (nonatomic, readonly) uint64_t contentLength;
|
|
||||||
@property (copy, readonly) NSString *versionString;
|
|
||||||
@property (copy, readonly) NSString *osString;
|
|
||||||
@property (copy, readonly) NSString *displayVersionString;
|
|
||||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
|
||||||
@property (strong, readonly) NSURL *infoURL;
|
|
||||||
|
|
||||||
// Initializes with data from a dictionary provided by the RSS class.
|
|
||||||
- (instancetype)initWithDictionary:(NSDictionary *)dict;
|
|
||||||
- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString **)error;
|
|
||||||
|
|
||||||
@property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate;
|
|
||||||
@property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate;
|
|
||||||
@property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate;
|
|
||||||
@property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate;
|
|
||||||
|
|
||||||
// Returns the dictionary provided in initWithDictionary; this might be useful later for extensions.
|
|
||||||
@property (readonly, copy) NSDictionary *propertiesDictionary;
|
|
||||||
|
|
||||||
- (NSURL *)infoURL;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
//
|
|
||||||
// SUCodeSigningVerifier.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 7/5/12.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SUCODESIGNINGVERIFIER_H
|
|
||||||
#define SUCODESIGNINGVERIFIER_H
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import "SUExport.h"
|
|
||||||
|
|
||||||
SU_EXPORT @interface SUCodeSigningVerifier : NSObject
|
|
||||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundlePath matchesSignatureAtBundleURL:(NSURL *)newBundlePath error:(NSError **)error;
|
|
||||||
+ (BOOL)codeSignatureIsValidAtBundleURL:(NSURL *)bundlePath error:(NSError **)error;
|
|
||||||
+ (BOOL)bundleAtURLIsCodeSigned:(NSURL *)bundlePath;
|
|
||||||
+ (NSDictionary *)codeSignatureInfoAtBundleURL:(NSURL *)bundlePath;
|
|
||||||
@end
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
//
|
|
||||||
// SUErrors.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by C.W. Betts on 10/13/14.
|
|
||||||
// Copyright (c) 2014 Sparkle Project. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SUERRORS_H
|
|
||||||
#define SUERRORS_H
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SUExport.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error domain used by Sparkle
|
|
||||||
*/
|
|
||||||
SU_EXPORT extern NSString *const SUSparkleErrorDomain;
|
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wc++98-compat"
|
|
||||||
typedef NS_ENUM(OSStatus, SUError) {
|
|
||||||
// Appcast phase errors.
|
|
||||||
SUAppcastParseError = 1000,
|
|
||||||
SUNoUpdateError = 1001,
|
|
||||||
SUAppcastError = 1002,
|
|
||||||
SURunningFromDiskImageError = 1003,
|
|
||||||
|
|
||||||
// Download phase errors.
|
|
||||||
SUTemporaryDirectoryError = 2000,
|
|
||||||
SUDownloadError = 2001,
|
|
||||||
|
|
||||||
// Extraction phase errors.
|
|
||||||
SUUnarchivingError = 3000,
|
|
||||||
SUSignatureError = 3001,
|
|
||||||
|
|
||||||
// Installation phase errors.
|
|
||||||
SUFileCopyFailure = 4000,
|
|
||||||
SUAuthenticationFailure = 4001,
|
|
||||||
SUMissingUpdateError = 4002,
|
|
||||||
SUMissingInstallerToolError = 4003,
|
|
||||||
SURelaunchError = 4004,
|
|
||||||
SUInstallationError = 4005,
|
|
||||||
SUDowngradeError = 4006,
|
|
||||||
SUInstallationCancelledError = 4007,
|
|
||||||
|
|
||||||
// System phase errors
|
|
||||||
SUSystemPowerOffError = 5000
|
|
||||||
};
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
//
|
|
||||||
// SUStandardVersionComparator.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 12/21/07.
|
|
||||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SUSTANDARDVERSIONCOMPARATOR_H
|
|
||||||
#define SUSTANDARDVERSIONCOMPARATOR_H
|
|
||||||
|
|
||||||
#if __has_feature(modules)
|
|
||||||
@import Foundation;
|
|
||||||
#else
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#endif
|
|
||||||
#import "SUExport.h"
|
|
||||||
#import "SUVersionComparisonProtocol.h"
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sparkle's default version comparator.
|
|
||||||
|
|
||||||
This comparator is adapted from MacPAD, by Kevin Ballard.
|
|
||||||
It's "dumb" in that it does essentially string comparison,
|
|
||||||
in components split by character type.
|
|
||||||
*/
|
|
||||||
SU_EXPORT @interface SUStandardVersionComparator : NSObject <SUVersionComparison>
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Initializes a new instance of the standard version comparator.
|
|
||||||
*/
|
|
||||||
- (instancetype)init;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Returns a singleton instance of the comparator.
|
|
||||||
|
|
||||||
It is usually preferred to alloc/init new a comparator instead.
|
|
||||||
*/
|
|
||||||
+ (SUStandardVersionComparator *)defaultComparator;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Compares version strings through textual analysis.
|
|
||||||
|
|
||||||
See the implementation for more details.
|
|
||||||
*/
|
|
||||||
- (NSComparisonResult)compareVersion:(NSString *)versionA toVersion:(NSString *)versionB;
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
#endif
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
//
|
|
||||||
// Sparkle.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 3/16/06. (Modified by CDHW on 23/12/07)
|
|
||||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef SPARKLE_H
|
|
||||||
#define SPARKLE_H
|
|
||||||
|
|
||||||
// This list should include the shared headers. It doesn't matter if some of them aren't shared (unless
|
|
||||||
// there are name-space collisions) so we can list all of them to start with:
|
|
||||||
|
|
||||||
#import "SUAppcast.h"
|
|
||||||
#import "SUAppcastItem.h"
|
|
||||||
#import "SUStandardVersionComparator.h"
|
|
||||||
#import "SUUpdater.h"
|
|
||||||
#import "SUUpdaterDelegate.h"
|
|
||||||
#import "SUVersionComparisonProtocol.h"
|
|
||||||
#import "SUVersionDisplayProtocol.h"
|
|
||||||
#import "SUErrors.h"
|
|
||||||
|
|
||||||
#import "SPUDownloader.h"
|
|
||||||
#import "SPUDownloaderDelegate.h"
|
|
||||||
#import "SPUDownloaderDeprecated.h"
|
|
||||||
#import "SPUDownloadData.h"
|
|
||||||
#import "SPUDownloaderProtocol.h"
|
|
||||||
#import "SPUDownloaderSession.h"
|
|
||||||
#import "SPUURLRequest.h"
|
|
||||||
#import "SUCodeSigningVerifier.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// SUUnarchiver.h
|
|
||||||
// Sparkle
|
|
||||||
//
|
|
||||||
// Created by Andy Matuschak on 3/16/06.
|
|
||||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
|
|
||||||
@protocol SUUnarchiverProtocol;
|
|
||||||
|
|
||||||
@interface SUUnarchiver : NSObject
|
|
||||||
|
|
||||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
BIN
Sparkle.framework/Versions/A/Resources/SUStatus.nib
generated
@ -1 +0,0 @@
|
|||||||
fr.lproj
|
|
||||||