mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-10-31 02:18:35 +00:00
Compare commits
171
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b569e0631 | ||
|
|
31a5a7c59c | ||
|
|
75d2bdf92c | ||
|
|
b4c4067fd0 | ||
|
|
e1583e5255 | ||
|
|
d4762ab81d | ||
|
|
a35b77bfe3 | ||
|
|
281f6d711e | ||
|
|
d52d84c3d1 | ||
|
|
3141755da7 | ||
|
|
94c3c141e8 | ||
|
|
df3beb90f5 | ||
|
|
a8ca5b3713 | ||
|
|
42101f092b | ||
|
|
a161341bca | ||
|
|
093faa2c02 | ||
|
|
aeee9983d1 | ||
|
|
bdfb7118c9 | ||
|
|
878cd346c1 | ||
|
|
712448f207 | ||
|
|
e9e5a6f739 | ||
|
|
466c0e5f68 | ||
|
|
85e3deac79 | ||
|
|
9e49cf8beb | ||
|
|
d81998862a | ||
|
|
1ae2041d0d | ||
|
|
5eb2d73c94 | ||
|
|
855ddea44e | ||
|
|
eaa26645c5 | ||
|
|
2cdb705b37 | ||
|
|
fa413f2fa2 | ||
|
|
6920664fad | ||
|
|
e9a7b6d32a | ||
|
|
dd23a3bda8 | ||
|
|
f82d7694eb | ||
|
|
94717a5ea3 | ||
|
|
b155cac2b0 | ||
|
|
cd2ec3d032 | ||
|
|
c4928ee382 | ||
|
|
0eef872f2b | ||
|
|
3f78bbe42c | ||
|
|
f2e6959b71 | ||
|
|
820853d300 | ||
|
|
2635e2611f | ||
|
|
e68fa10c42 | ||
|
|
92975cb8e4 | ||
|
|
0b39795bd7 | ||
|
|
d4b950ab64 | ||
|
|
41a9544c3a | ||
|
|
e44ff00f3b | ||
|
|
f378de675e | ||
|
|
66b175d5ba | ||
|
|
59cde098f2 | ||
|
|
f3015df82a | ||
|
|
6629cfd11c | ||
|
|
d6e48c8197 | ||
|
|
0e8dab4677 | ||
|
|
aa73fd1dc3 | ||
|
|
29da70c477 | ||
|
|
aa67dc10b7 | ||
|
|
aaa54e2709 | ||
|
|
a110e00b9c | ||
|
|
12137c6732 | ||
|
|
36d1028af1 | ||
|
|
77f56df144 | ||
|
|
80b56779fb | ||
|
|
580f0275fc | ||
|
|
168b629810 | ||
|
|
2d64c091e3 | ||
|
|
63e3de7313 | ||
|
|
229c55c367 | ||
|
|
11530ef180 | ||
|
|
96f26ab7f7 | ||
|
|
95271dba0e | ||
|
|
67aaa2abf4 | ||
|
|
58e4160649 | ||
|
|
77846d0436 | ||
|
|
bc66b375d3 | ||
|
|
ce8004641d | ||
|
|
155e48a693 | ||
|
|
76a7d59fe5 | ||
|
|
6a85bea5b5 | ||
|
|
000b825ec9 | ||
|
|
3432e24a55 | ||
|
|
705d0a64b5 | ||
|
|
9f0944b06b | ||
|
|
efc52293a8 | ||
|
|
7b853b5d47 | ||
|
|
439246e85b | ||
|
|
c254ee430d | ||
|
|
cfcda6e46f | ||
|
|
144ff9cf79 | ||
|
|
91a4e5bded | ||
|
|
68dfcddb29 | ||
|
|
82ec231700 | ||
|
|
ed261c2349 | ||
|
|
f06d1f4329 | ||
|
|
3dabd598f4 | ||
|
|
0a09ea7117 | ||
|
|
02cf911336 | ||
|
|
d831069025 | ||
|
|
33206ab457 | ||
|
|
c6c808369f | ||
|
|
cbad06ac07 | ||
|
|
64171d5c51 | ||
|
|
5504e5d640 | ||
|
|
164295820b | ||
|
|
ae469bb92a | ||
|
|
57b5129135 | ||
|
|
7cc72de66f | ||
|
|
2e5db4ffa0 | ||
|
|
8a73fe01e4 | ||
|
|
5fbb2bafc6 | ||
|
|
5b6b6dfa56 | ||
|
|
65e5a52383 | ||
|
|
03304bd030 | ||
|
|
f264425ba7 | ||
|
|
c377b9494c | ||
|
|
f5b36ec012 | ||
|
|
999c4cf6e2 | ||
|
|
b8d5d0a8a5 | ||
|
|
6bb5aade07 | ||
|
|
b6bcc31456 | ||
|
|
9d09646742 | ||
|
|
55f988e393 | ||
|
|
2f4cf9e5f6 | ||
|
|
327d38e47d | ||
|
|
cd380b289d | ||
|
|
6a26b2f5ca | ||
|
|
d7186aac18 | ||
|
|
cef07dc965 | ||
|
|
471c0c5d57 | ||
|
|
5b93525806 | ||
|
|
b87bc632ab | ||
|
|
1763a24942 | ||
|
|
627e6951c1 | ||
|
|
918054df78 | ||
|
|
25fb0d4f04 | ||
|
|
61a357ffc3 | ||
|
|
f4116a95df | ||
|
|
c952505c1c | ||
|
|
f10b58b996 | ||
|
|
88a8ae3ae8 | ||
|
|
d783448567 | ||
|
|
595ae165d3 | ||
|
|
da406713dd | ||
|
|
938b83f37e | ||
|
|
a8a085df1e | ||
|
|
b188f45c8e | ||
|
|
3319c5d45a | ||
|
|
6174d14925 | ||
|
|
c8197239d7 | ||
|
|
d2854e3dae | ||
|
|
4f9c3258ae | ||
|
|
dfeda1e874 | ||
|
|
82f82039ae | ||
|
|
324c3f711e | ||
|
|
a81d6fc595 | ||
|
|
3bde1fe4b1 | ||
|
|
7c9dd26eb0 | ||
|
|
40fa61fcb5 | ||
|
|
5a8117ac7f | ||
|
|
a606767ddc | ||
|
|
6badc37dc3 | ||
|
|
4497c7102c | ||
|
|
b6c6bb945b | ||
|
|
3e399d14c2 | ||
|
|
624c8ac6d8 | ||
|
|
ea68ce33c1 | ||
|
|
e68f930efa | ||
|
|
647ac0ba20 |
@@ -0,0 +1,6 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
issuehunt: Toxblh
|
||||
patreon: toxblh
|
||||
ko_fi: toxblh
|
||||
custom: https://www.paypal.me/toxblh
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Swift
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macOS-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Run tests
|
||||
run: xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}
|
||||
|
||||
build:
|
||||
runs-on: macOS-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Build
|
||||
run: xcodebuild archive -project "MTMR.xcodeproj" -scheme "MTMR" -archivePath Release/App.xcarchive DEVELOPMENT_TEAM="" CODE_SIGN_IDENTITY="" | xcpretty -c && exit ${PIPESTATUS[0]}
|
||||
@@ -0,0 +1,31 @@
|
||||
name: Swift
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macOS-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install create-dmg
|
||||
run: npm i -g create-dmg
|
||||
|
||||
- name: Build Archive
|
||||
run: xcodebuild archive -project "MTMR.xcodeproj" -scheme "MTMR" -archivePath Release/App.xcarchive DEVELOPMENT_TEAM="" CODE_SIGN_IDENTITY="" | xcpretty -c && exit ${PIPESTATUS[0]}
|
||||
|
||||
- name: Build App
|
||||
run: xcodebuild -project "MTMR.xcodeproj" -exportArchive -archivePath Release/App.xcarchive -exportOptionsPlist export-options.plist -exportPath Release | xcpretty -c && exit ${PIPESTATUS[0]}
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
language: swift
|
||||
xcode_project: MTMR.xcodeproj
|
||||
xcode_scheme: UnitTests
|
||||
osx_image: xcode10
|
||||
install: gem install xcpretty
|
||||
script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}"
|
||||
@@ -18,6 +18,10 @@
|
||||
36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */; };
|
||||
36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */; };
|
||||
36C2ECE0207CB1B0003CDA33 /* defaultPreset.json in Resources */ = {isa = PBXBuildFile; fileRef = 36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */; };
|
||||
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FEF871235A1CFC00A0ABCE /* AppSettings.swift */; };
|
||||
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */; };
|
||||
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */; };
|
||||
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */; };
|
||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60173D3D20C0031B002C305F /* LaunchAtLoginController.m */; };
|
||||
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */; };
|
||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */; };
|
||||
@@ -61,6 +65,7 @@
|
||||
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */; };
|
||||
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */; };
|
||||
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */; };
|
||||
B0F54A7A2295AC7D00B4C509 /* DarkModeBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */; };
|
||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@@ -90,6 +95,11 @@
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsParsing.swift; sourceTree = "<group>"; };
|
||||
36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseConfigTests.swift; sourceTree = "<group>"; };
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = defaultPreset.json; sourceTree = "<group>"; };
|
||||
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; 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>"; };
|
||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellScriptTouchBarItem.swift; sourceTree = "<group>"; };
|
||||
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YandexWeatherBarItem.swift; sourceTree = "<group>"; };
|
||||
60173D3C20C0031B002C305F /* LaunchAtLoginController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = "<group>"; };
|
||||
60173D3D20C0031B002C305F /* LaunchAtLoginController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
|
||||
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrightnessViewController.swift; sourceTree = "<group>"; };
|
||||
@@ -142,6 +152,7 @@
|
||||
B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||
B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iTunes.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||
B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportNSTouchBar.swift; sourceTree = "<group>"; };
|
||||
B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkModeBarItem.swift; sourceTree = "<group>"; };
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = "<group>"; };
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
@@ -216,8 +227,10 @@
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */,
|
||||
B082B252205C7D8000BC04DC /* AppDelegate.swift */,
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */,
|
||||
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */,
|
||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */,
|
||||
B0008E542080286C003AD4DD /* SupportHelpers.swift */,
|
||||
@@ -262,6 +275,8 @@
|
||||
B0B1743B207D6ED40004B740 /* CBridge */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4CC9FEDA22FDEA65001512EB /* AMR_ANSIEscapeHelper.h */,
|
||||
4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */,
|
||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */,
|
||||
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */,
|
||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||
@@ -292,7 +307,9 @@
|
||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
||||
6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */,
|
||||
607EEA4A2087835F009DA5F0 /* WeatherBarItem.swift */,
|
||||
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */,
|
||||
B08126F0217BE19000A98970 /* WidgetProtocol.swift */,
|
||||
B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */,
|
||||
);
|
||||
path = Widgets;
|
||||
sourceTree = "<group>";
|
||||
@@ -348,7 +365,7 @@
|
||||
TargetAttributes = {
|
||||
B082B24E205C7D8000BC04DC = {
|
||||
CreatedOnToolsVersion = 9.2;
|
||||
LastSwiftMigration = 1000;
|
||||
LastSwiftMigration = 1020;
|
||||
ProvisioningStyle = Manual;
|
||||
SystemCapabilities = {
|
||||
com.apple.Sandbox = {
|
||||
@@ -358,7 +375,7 @@
|
||||
};
|
||||
B082B260205C7D8000BC04DC = {
|
||||
CreatedOnToolsVersion = 9.2;
|
||||
LastSwiftMigration = 1000;
|
||||
LastSwiftMigration = 1020;
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -446,17 +463,21 @@
|
||||
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */,
|
||||
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */,
|
||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||
B0F54A7A2295AC7D00B4C509 /* DarkModeBarItem.swift in Sources */,
|
||||
B08126EF217BD0B900A98970 /* PomodoroBarItem.swift in Sources */,
|
||||
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */,
|
||||
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
||||
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */,
|
||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
||||
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */,
|
||||
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
||||
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
|
||||
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */,
|
||||
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
||||
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */,
|
||||
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */,
|
||||
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */,
|
||||
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */,
|
||||
36A778BE20A6C27100B38714 /* GeneralExtensions.swift in Sources */,
|
||||
60669B4320AD8FA80074E817 /* GroupBarItem.swift in Sources */,
|
||||
@@ -464,6 +485,7 @@
|
||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
||||
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */,
|
||||
607EEA4D2087A8DA009DA5F0 /* CurrencyBarItem.swift in Sources */,
|
||||
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */,
|
||||
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */,
|
||||
368EDDE720812A1D00E10953 /* ScrollViewItem.swift in Sources */,
|
||||
B04B7BB72087398C00C835D0 /* BatteryBarItem.swift in Sources */,
|
||||
@@ -622,7 +644,7 @@
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_VERSION = 4.2;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -645,7 +667,7 @@
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||
SWIFT_VERSION = 4.2;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -658,7 +680,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.2;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -673,7 +695,7 @@
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 4.2;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildSystemType</key>
|
||||
<string>Original</string>
|
||||
</dict>
|
||||
<dict/>
|
||||
</plist>
|
||||
|
||||
+36
-23
@@ -25,6 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
|
||||
|
||||
TouchBarController.shared.setupControlStripPresence()
|
||||
HapticFeedbackUpdate()
|
||||
|
||||
if let button = statusItem.button {
|
||||
button.image = #imageLiteral(resourceName: "StatusImage")
|
||||
@@ -40,18 +41,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
func applicationWillTerminate(_: Notification) {}
|
||||
|
||||
@objc func updateIsBlockedApp() {
|
||||
var blacklistAppIdentifiers: [String] = []
|
||||
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
|
||||
blacklistAppIdentifiers = blackListed
|
||||
}
|
||||
var frontmostApplicationIdentifier: String? {
|
||||
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
|
||||
return frontmostId
|
||||
}
|
||||
func HapticFeedbackUpdate() {
|
||||
HapticFeedback.shared = AppSettings.hapticFeedbackState ? HapticFeedback() : nil
|
||||
}
|
||||
|
||||
if frontmostApplicationIdentifier != nil {
|
||||
isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil
|
||||
@objc func updateIsBlockedApp() {
|
||||
if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||
isBlockedApp = AppSettings.blacklistedAppIds.firstIndex(of: frontmostAppId) != nil
|
||||
} else {
|
||||
isBlockedApp = false
|
||||
}
|
||||
@@ -67,29 +63,38 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
task.launch()
|
||||
}
|
||||
|
||||
@objc func toggleControlStrip(_: Any?) {
|
||||
TouchBarController.shared.showControlStripState = !TouchBarController.shared.showControlStripState
|
||||
@objc func toggleControlStrip(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.showControlStripState = item.state == .off
|
||||
TouchBarController.shared.resetControlStrip()
|
||||
createMenu()
|
||||
}
|
||||
|
||||
@objc func toggleBlackListedApp(_: Any?) {
|
||||
let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier
|
||||
if appIdentifier != nil {
|
||||
if let index = TouchBarController.shared.blacklistAppIdentifiers.index(of: appIdentifier!) {
|
||||
if let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||
if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier) {
|
||||
TouchBarController.shared.blacklistAppIdentifiers.remove(at: index)
|
||||
} else {
|
||||
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!)
|
||||
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier)
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps")
|
||||
UserDefaults.standard.synchronize()
|
||||
|
||||
|
||||
AppSettings.blacklistedAppIds = TouchBarController.shared.blacklistAppIdentifiers
|
||||
TouchBarController.shared.updateActiveApp()
|
||||
updateIsBlockedApp()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleHapticFeedback(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.hapticFeedbackState = item.state == .on
|
||||
HapticFeedbackUpdate()
|
||||
}
|
||||
|
||||
@objc func toggleMultitouch(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.multitouchGestures = item.state == .on
|
||||
TouchBarController.shared.scrollArea?.gesturesEnabled = item.state == .on
|
||||
}
|
||||
|
||||
@objc func openPreset(_: Any?) {
|
||||
let dialog = NSOpenPanel()
|
||||
|
||||
@@ -122,7 +127,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
toggleBlackList.state = isBlockedApp ? .on : .off
|
||||
|
||||
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
||||
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
|
||||
hideControlStrip.state = AppSettings.showControlStripState ? .off : .on
|
||||
|
||||
let hapticFeedback = NSMenuItem(title: "Haptic Feedback", action: #selector(toggleHapticFeedback(_:)), keyEquivalent: "H")
|
||||
hapticFeedback.state = AppSettings.hapticFeedbackState ? .on : .off
|
||||
|
||||
let multitouchGestures = NSMenuItem(title: "Volume/Brightness gestures", action: #selector(toggleMultitouch(_:)), keyEquivalent: "")
|
||||
multitouchGestures.state = AppSettings.multitouchGestures ? .on : .off
|
||||
|
||||
let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
|
||||
settingSeparator.isEnabled = false
|
||||
@@ -133,9 +144,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(settingSeparator)
|
||||
menu.addItem(hapticFeedback)
|
||||
menu.addItem(hideControlStrip)
|
||||
menu.addItem(toggleBlackList)
|
||||
menu.addItem(startAtLogin)
|
||||
menu.addItem(multitouchGestures)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||
statusItem.menu = menu
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import Foundation
|
||||
|
||||
struct AppSettings {
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.showControlStrip", defaultValue: false)
|
||||
static var showControlStripState: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.hapticFeedback", defaultValue: true)
|
||||
static var hapticFeedbackState: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.multitouchGestures", defaultValue: true)
|
||||
static var multitouchGestures: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.blackListedApps", defaultValue: [])
|
||||
static var blacklistedAppIds: [String]
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.dock.persistent", defaultValue: [])
|
||||
static var dockPersistentAppIds: [String]
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct UserDefault<T> {
|
||||
let key: String
|
||||
let defaultValue: T
|
||||
var wrappedValue: T {
|
||||
get {
|
||||
return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: key)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
tell application "Finder"
|
||||
make new Finder window
|
||||
set target of front window to path to home folder as string
|
||||
if not (exists window 1) then
|
||||
make new Finder window
|
||||
set target of front window to path to home folder as string
|
||||
end if
|
||||
activate
|
||||
end tell
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "sun-icon-256.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "39857.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"properties" : {
|
||||
"template-rendering-intent" : "template"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
@@ -619,7 +619,7 @@
|
||||
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
|
||||
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
//
|
||||
// ANSIEscapeHelper.h
|
||||
// AnsiColorsTest
|
||||
//
|
||||
// Created by Ali Rantakari on 18.3.09.
|
||||
//
|
||||
// Version 0.9.6
|
||||
//
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2008-2009,2013 Ali Rantakari
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
#warning "This code requires ARC to be enabled."
|
||||
#endif
|
||||
|
||||
|
||||
// dictionary keys for the SGR code dictionaries that the array
|
||||
// escapeCodesForString:cleanString: returns contains
|
||||
#define kAMRCodeDictKey_code @"code"
|
||||
#define kAMRCodeDictKey_location @"location"
|
||||
|
||||
// dictionary keys for the string formatting attribute
|
||||
// dictionaries that the array attributesForString:cleanString:
|
||||
// returns contains
|
||||
#define kAMRAttrDictKey_range @"range"
|
||||
#define kAMRAttrDictKey_attrName @"attributeName"
|
||||
#define kAMRAttrDictKey_attrValue @"attributeValue"
|
||||
|
||||
|
||||
/*!
|
||||
@enum AMR_SGRCode
|
||||
|
||||
@abstract SGR (Select Graphic Rendition) ANSI control codes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
AMR_SGRCodeNoneOrInvalid = -1,
|
||||
|
||||
AMR_SGRCodeAllReset = 0,
|
||||
|
||||
AMR_SGRCodeIntensityBold = 1,
|
||||
AMR_SGRCodeIntensityFaint = 2,
|
||||
AMR_SGRCodeIntensityNormal = 22,
|
||||
|
||||
AMR_SGRCodeItalicOn = 3,
|
||||
|
||||
AMR_SGRCodeUnderlineSingle = 4,
|
||||
AMR_SGRCodeUnderlineDouble = 21,
|
||||
AMR_SGRCodeUnderlineNone = 24,
|
||||
|
||||
AMR_SGRCodeFgBlack = 30,
|
||||
AMR_SGRCodeFgRed = 31,
|
||||
AMR_SGRCodeFgGreen = 32,
|
||||
AMR_SGRCodeFgYellow = 33,
|
||||
AMR_SGRCodeFgBlue = 34,
|
||||
AMR_SGRCodeFgMagenta = 35,
|
||||
AMR_SGRCodeFgCyan = 36,
|
||||
AMR_SGRCodeFgWhite = 37,
|
||||
AMR_SGRCodeFgReset = 39,
|
||||
|
||||
AMR_SGRCodeBgBlack = 40,
|
||||
AMR_SGRCodeBgRed = 41,
|
||||
AMR_SGRCodeBgGreen = 42,
|
||||
AMR_SGRCodeBgYellow = 43,
|
||||
AMR_SGRCodeBgBlue = 44,
|
||||
AMR_SGRCodeBgMagenta = 45,
|
||||
AMR_SGRCodeBgCyan = 46,
|
||||
AMR_SGRCodeBgWhite = 47,
|
||||
AMR_SGRCodeBgReset = 49,
|
||||
|
||||
AMR_SGRCodeFgBrightBlack = 90,
|
||||
AMR_SGRCodeFgBrightRed = 91,
|
||||
AMR_SGRCodeFgBrightGreen = 92,
|
||||
AMR_SGRCodeFgBrightYellow = 93,
|
||||
AMR_SGRCodeFgBrightBlue = 94,
|
||||
AMR_SGRCodeFgBrightMagenta = 95,
|
||||
AMR_SGRCodeFgBrightCyan = 96,
|
||||
AMR_SGRCodeFgBrightWhite = 97,
|
||||
|
||||
AMR_SGRCodeBgBrightBlack = 100,
|
||||
AMR_SGRCodeBgBrightRed = 101,
|
||||
AMR_SGRCodeBgBrightGreen = 102,
|
||||
AMR_SGRCodeBgBrightYellow = 103,
|
||||
AMR_SGRCodeBgBrightBlue = 104,
|
||||
AMR_SGRCodeBgBrightMagenta = 105,
|
||||
AMR_SGRCodeBgBrightCyan = 106,
|
||||
AMR_SGRCodeBgBrightWhite = 107
|
||||
} AMR_SGRCode;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
@class AMR_ANSIEscapeHelper
|
||||
|
||||
@abstract Contains helper methods for dealing with strings
|
||||
that contain ANSI escape sequences for formatting (colors,
|
||||
underlining, bold etc.)
|
||||
*/
|
||||
@interface AMR_ANSIEscapeHelper : NSObject
|
||||
|
||||
/*!
|
||||
@property defaultStringColor
|
||||
|
||||
@abstract The default color used when creating an attributed string (default is black).
|
||||
*/
|
||||
@property(copy) NSColor *defaultStringColor;
|
||||
|
||||
|
||||
/*!
|
||||
@property font
|
||||
|
||||
@abstract The font to use when creating string formatting attribute values.
|
||||
*/
|
||||
@property(copy) NSFont *font;
|
||||
|
||||
/*!
|
||||
@property ansiColors
|
||||
|
||||
@abstract The colors to use for displaying ANSI colors.
|
||||
|
||||
@discussion Keys in this dictionary should be NSNumber objects containing SGR code
|
||||
values from the AMR_SGRCode enum. The corresponding values for these keys
|
||||
should be NSColor objects. If this property is nil or if it doesn't
|
||||
contain a key for a specific SGR code, the default color will be used
|
||||
instead.
|
||||
*/
|
||||
@property(retain) NSMutableDictionary *ansiColors;
|
||||
|
||||
|
||||
/*!
|
||||
@method attributedStringWithANSIEscapedString:
|
||||
|
||||
@abstract Returns an attributed string that corresponds both in contents
|
||||
and formatting to a given string that contains ANSI escape
|
||||
sequences.
|
||||
|
||||
@param aString A String containing ANSI escape sequences
|
||||
|
||||
@result An attributed string that mimics as closely as possible
|
||||
the formatting of the given ANSI-escaped string.
|
||||
*/
|
||||
- (NSAttributedString*) attributedStringWithANSIEscapedString:(NSString*)aString;
|
||||
|
||||
|
||||
/*!
|
||||
@method ansiEscapedStringWithAttributedString:
|
||||
|
||||
@abstract Returns a string containing ANSI escape sequences that corresponds
|
||||
both in contents and formatting to a given attributed string.
|
||||
|
||||
@param aAttributedString An attributed string
|
||||
|
||||
@result A string that mimics as closely as possible
|
||||
the formatting of the given attributed string with
|
||||
ANSI escape sequences.
|
||||
*/
|
||||
- (NSString*) ansiEscapedStringWithAttributedString:(NSAttributedString*)aAttributedString;
|
||||
|
||||
|
||||
/*!
|
||||
@method escapeCodesForString:cleanString:
|
||||
|
||||
@abstract Returns an array of SGR codes and their locations from a
|
||||
string containing ANSI escape sequences as well as a "clean"
|
||||
version of the string (i.e. one without the ANSI escape
|
||||
sequences.)
|
||||
|
||||
@param aString A String containing ANSI escape sequences
|
||||
@param aCleanString Upon return, contains a "clean" version of aString (i.e. aString
|
||||
without the ANSI escape sequences)
|
||||
|
||||
@result An array of NSDictionary objects, each of which has
|
||||
an NSNumber value for the key "code" (specifying an SGR code) and
|
||||
another NSNumber value for the key "location" (specifying the
|
||||
location of the code within aCleanString.)
|
||||
*/
|
||||
- (NSArray*) escapeCodesForString:(NSString*)aString cleanString:(NSString**)aCleanString;
|
||||
|
||||
|
||||
/*!
|
||||
@method ansiEscapedStringWithCodesAndLocations:cleanString:
|
||||
|
||||
@abstract Returns a string containing ANSI escape codes for formatting based
|
||||
on a string and an array of SGR codes and their locations within
|
||||
the given string.
|
||||
|
||||
@param aCodesArray An array of NSDictionary objects, each of which should have
|
||||
an NSNumber value for the key "code" (specifying an SGR
|
||||
code) and another NSNumber value for the key "location"
|
||||
(specifying the location of this SGR code in aCleanString.)
|
||||
@param aCleanString The string to which to insert the ANSI escape codes
|
||||
described in aCodesArray.
|
||||
|
||||
@result A string containing ANSI escape sequences.
|
||||
*/
|
||||
- (NSString*) ansiEscapedStringWithCodesAndLocations:(NSArray*)aCodesArray cleanString:(NSString*)aCleanString;
|
||||
|
||||
|
||||
/*!
|
||||
@method attributesForString:cleanString:
|
||||
|
||||
@abstract Convert ANSI escape sequences in a string to string formatting attributes.
|
||||
|
||||
@discussion Given a string with some ANSI escape sequences in it, this method returns
|
||||
attributes for formatting the specified string according to those ANSI
|
||||
escape sequences as well as a "clean" (i.e. free of the escape sequences)
|
||||
version of this string.
|
||||
|
||||
@param aString A String containing ANSI escape sequences
|
||||
@param aCleanString Upon return, contains a "clean" version of aString (i.e. aString
|
||||
without the ANSI escape sequences.) Pass in NULL if you're not
|
||||
interested in this.
|
||||
|
||||
@result An array containing NSDictionary objects, each of which has keys "range"
|
||||
(an NSValue containing an NSRange, specifying the range for the
|
||||
attribute within the "clean" version of aString), "attributeName" (an
|
||||
NSString) and "attributeValue" (an NSObject). You may use these as
|
||||
arguments for NSMutableAttributedString's methods for setting the
|
||||
visual formatting.
|
||||
*/
|
||||
- (NSArray*) attributesForString:(NSString*)aString cleanString:(NSString**)aCleanString;
|
||||
|
||||
|
||||
/*!
|
||||
@method AMR_SGRCode:endsFormattingIntroducedByCode:
|
||||
|
||||
@abstract Whether the occurrence of a given SGR code would end the formatting run
|
||||
introduced by another SGR code.
|
||||
|
||||
@discussion For example, AMR_SGRCodeFgReset, AMR_SGRCodeAllReset or any SGR code
|
||||
specifying a foreground color would end the formatting run
|
||||
introduced by a foreground color -specifying SGR code.
|
||||
|
||||
@param endCode The SGR code to test as a candidate for ending the formatting run
|
||||
introduced by startCode
|
||||
@param startCode The SGR code that has introduced a formatting run
|
||||
|
||||
@result YES if the occurrence of endCode would end the formatting run
|
||||
introduced by startCode, NO otherwise.
|
||||
*/
|
||||
- (BOOL) AMR_SGRCode:(AMR_SGRCode)endCode endsFormattingIntroducedByCode:(AMR_SGRCode)startCode;
|
||||
|
||||
|
||||
/*!
|
||||
@method colorForSGRCode:
|
||||
|
||||
@abstract Returns the color to use for displaying a specific ANSI color.
|
||||
|
||||
@discussion This method first considers the values set in the ansiColors
|
||||
property and only then the standard basic colors (NSColor's
|
||||
redColor, blueColor etc.)
|
||||
|
||||
@param code An SGR code that specifies an ANSI color.
|
||||
|
||||
@result The color to use for displaying the ANSI color specified by code.
|
||||
*/
|
||||
- (NSColor*) colorForSGRCode:(AMR_SGRCode)code;
|
||||
|
||||
|
||||
/*!
|
||||
@method AMR_SGRCodeForColor:isForegroundColor:
|
||||
|
||||
@abstract Returns a color SGR code that corresponds to a given color.
|
||||
|
||||
@discussion This method matches colors to their equivalent SGR codes
|
||||
by going through the colors specified in the ansiColors
|
||||
dictionary, and if ansiColors is null or if a match is
|
||||
not found there, by comparing the given color to the
|
||||
standard basic colors (NSColor's redColor, blueColor
|
||||
etc.) The comparison is done simply by checking for
|
||||
equality.
|
||||
|
||||
@param aColor The color to get a corresponding SGR code for
|
||||
@param aForeground Whether you want a foreground or background color code
|
||||
|
||||
@result SGR code that corresponds with aColor.
|
||||
*/
|
||||
- (AMR_SGRCode) AMR_SGRCodeForColor:(NSColor*)aColor isForegroundColor:(BOOL)aForeground;
|
||||
|
||||
|
||||
/*!
|
||||
@method closestSGRCodeForColor:isForegroundColor:
|
||||
|
||||
@abstract Returns a color SGR code that represents the closest ANSI
|
||||
color to a given color.
|
||||
|
||||
@discussion This method attempts to find the closest ANSI color to
|
||||
aColor and return its SGR code.
|
||||
|
||||
@param color The color to get a closest color SGR code match for
|
||||
@param foreground Whether you want a foreground or background color code
|
||||
|
||||
@result SGR code for the ANSI color that is closest to aColor.
|
||||
*/
|
||||
- (AMR_SGRCode) closestSGRCodeForColor:(NSColor *)color isForegroundColor:(BOOL)foreground;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,996 @@
|
||||
//
|
||||
// ANSIEscapeHelper.m
|
||||
//
|
||||
// Created by Ali Rantakari on 18.3.09.
|
||||
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2008-2009,2013 Ali Rantakari
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
todo:
|
||||
|
||||
- don't add useless "reset" escape codes to the string in
|
||||
-ansiEscapedStringWithAttributedString:
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#import "AMR_ANSIEscapeHelper.h"
|
||||
|
||||
|
||||
// the CSI (Control Sequence Initiator) -- i.e. "escape sequence prefix".
|
||||
// (add your own CSI:Miami joke here)
|
||||
#define kANSIEscapeCSI @"\033["
|
||||
|
||||
// the end byte of an SGR (Select Graphic Rendition)
|
||||
// ANSI Escape Sequence
|
||||
#define kANSIEscapeSGREnd @"m"
|
||||
|
||||
|
||||
// color definition helper macros
|
||||
#define kBrightColorBrightness 1.0
|
||||
#define kBrightColorSaturation 0.4
|
||||
#define kBrightColorAlpha 1.0
|
||||
#define kBrightColorWithHue(h) [NSColor colorWithCalibratedHue:(h) saturation:kBrightColorSaturation brightness:kBrightColorBrightness alpha:kBrightColorAlpha]
|
||||
|
||||
// default colors
|
||||
#define kDefaultANSIColorFgBlack NSColor.blackColor
|
||||
#define kDefaultANSIColorFgRed NSColor.redColor
|
||||
#define kDefaultANSIColorFgGreen NSColor.greenColor
|
||||
#define kDefaultANSIColorFgYellow NSColor.yellowColor
|
||||
#define kDefaultANSIColorFgBlue NSColor.blueColor
|
||||
#define kDefaultANSIColorFgMagenta NSColor.magentaColor
|
||||
#define kDefaultANSIColorFgCyan NSColor.cyanColor
|
||||
#define kDefaultANSIColorFgWhite NSColor.whiteColor
|
||||
|
||||
#define kDefaultANSIColorFgBrightBlack [NSColor colorWithCalibratedWhite:0.337 alpha:1.0]
|
||||
#define kDefaultANSIColorFgBrightRed kBrightColorWithHue(1.0)
|
||||
#define kDefaultANSIColorFgBrightGreen kBrightColorWithHue(1.0/3.0)
|
||||
#define kDefaultANSIColorFgBrightYellow kBrightColorWithHue(1.0/6.0)
|
||||
#define kDefaultANSIColorFgBrightBlue kBrightColorWithHue(2.0/3.0)
|
||||
#define kDefaultANSIColorFgBrightMagenta kBrightColorWithHue(5.0/6.0)
|
||||
#define kDefaultANSIColorFgBrightCyan kBrightColorWithHue(0.5)
|
||||
#define kDefaultANSIColorFgBrightWhite NSColor.whiteColor
|
||||
|
||||
#define kDefaultANSIColorBgBlack NSColor.blackColor
|
||||
#define kDefaultANSIColorBgRed NSColor.redColor
|
||||
#define kDefaultANSIColorBgGreen NSColor.greenColor
|
||||
#define kDefaultANSIColorBgYellow NSColor.yellowColor
|
||||
#define kDefaultANSIColorBgBlue NSColor.blueColor
|
||||
#define kDefaultANSIColorBgMagenta NSColor.magentaColor
|
||||
#define kDefaultANSIColorBgCyan NSColor.cyanColor
|
||||
#define kDefaultANSIColorBgWhite NSColor.whiteColor
|
||||
|
||||
#define kDefaultANSIColorBgBrightBlack kDefaultANSIColorFgBrightBlack
|
||||
#define kDefaultANSIColorBgBrightRed kDefaultANSIColorFgBrightRed
|
||||
#define kDefaultANSIColorBgBrightGreen kDefaultANSIColorFgBrightGreen
|
||||
#define kDefaultANSIColorBgBrightYellow kDefaultANSIColorFgBrightYellow
|
||||
#define kDefaultANSIColorBgBrightBlue kDefaultANSIColorFgBrightBlue
|
||||
#define kDefaultANSIColorBgBrightMagenta kDefaultANSIColorFgBrightMagenta
|
||||
#define kDefaultANSIColorBgBrightCyan kDefaultANSIColorFgBrightCyan
|
||||
#define kDefaultANSIColorBgBrightWhite kDefaultANSIColorFgBrightWhite
|
||||
|
||||
#define kDefaultFontSize [NSFont systemFontOfSize:NSFont.systemFontSize]
|
||||
#define kDefaultForegroundColor NSColor.blackColor
|
||||
|
||||
// minimum weight for an NSFont for it to be considered bold
|
||||
#define kBoldFontMinWeight 9
|
||||
|
||||
|
||||
@implementation AMR_ANSIEscapeHelper
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if (!(self = [super init]))
|
||||
return nil;
|
||||
|
||||
self.ansiColors = [NSMutableDictionary dictionary];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (NSAttributedString*) attributedStringWithANSIEscapedString:(NSString*)aString
|
||||
{
|
||||
if (aString == nil)
|
||||
return nil;
|
||||
|
||||
NSString *cleanString;
|
||||
NSArray *attributesAndRanges = [self attributesForString:aString cleanString:&cleanString];
|
||||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
|
||||
initWithString:cleanString
|
||||
attributes:@{
|
||||
NSFontAttributeName: self.font ?: kDefaultFontSize,
|
||||
NSForegroundColorAttributeName: self.defaultStringColor ?: kDefaultForegroundColor
|
||||
}];
|
||||
|
||||
for (NSDictionary *thisAttributeDict in attributesAndRanges)
|
||||
{
|
||||
[attributedString
|
||||
addAttribute:thisAttributeDict[kAMRAttrDictKey_attrName]
|
||||
value:thisAttributeDict[kAMRAttrDictKey_attrValue]
|
||||
range:[thisAttributeDict[kAMRAttrDictKey_range] rangeValue]
|
||||
];
|
||||
}
|
||||
|
||||
return attributedString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (NSString*) ansiEscapedStringWithAttributedString:(NSAttributedString*)aAttributedString
|
||||
{
|
||||
NSMutableArray *codesAndLocations = [NSMutableArray array];
|
||||
|
||||
NSArray *attrNames = @[
|
||||
NSFontAttributeName, NSForegroundColorAttributeName,
|
||||
NSBackgroundColorAttributeName, NSUnderlineStyleAttributeName,
|
||||
];
|
||||
|
||||
for (NSString *thisAttrName in attrNames)
|
||||
{
|
||||
NSRange limitRange = NSMakeRange(0, aAttributedString.length);
|
||||
id attributeValue;
|
||||
NSRange effectiveRange;
|
||||
|
||||
while (limitRange.length > 0)
|
||||
{
|
||||
attributeValue = [aAttributedString
|
||||
attribute:thisAttrName
|
||||
atIndex:limitRange.location
|
||||
longestEffectiveRange:&effectiveRange
|
||||
inRange:limitRange
|
||||
];
|
||||
|
||||
AMR_SGRCode thisSGRCode = AMR_SGRCodeNoneOrInvalid;
|
||||
|
||||
if ([thisAttrName isEqualToString:NSForegroundColorAttributeName])
|
||||
{
|
||||
if (attributeValue != nil)
|
||||
thisSGRCode = [self closestSGRCodeForColor:attributeValue isForegroundColor:YES];
|
||||
else
|
||||
thisSGRCode = AMR_SGRCodeFgReset;
|
||||
}
|
||||
else if ([thisAttrName isEqualToString:NSBackgroundColorAttributeName])
|
||||
{
|
||||
if (attributeValue != nil)
|
||||
thisSGRCode = [self closestSGRCodeForColor:attributeValue isForegroundColor:NO];
|
||||
else
|
||||
thisSGRCode = AMR_SGRCodeBgReset;
|
||||
}
|
||||
else if ([thisAttrName isEqualToString:NSFontAttributeName])
|
||||
{
|
||||
// we currently only use NSFontAttributeName for bolding so
|
||||
// here we assume that the formatting "type" in ANSI SGR
|
||||
// terms is indeed intensity
|
||||
if (attributeValue != nil)
|
||||
thisSGRCode = ([NSFontManager.sharedFontManager weightOfFont:attributeValue] >= kBoldFontMinWeight)
|
||||
? AMR_SGRCodeIntensityBold : AMR_SGRCodeIntensityNormal;
|
||||
else
|
||||
thisSGRCode = AMR_SGRCodeIntensityNormal;
|
||||
}
|
||||
else if ([thisAttrName isEqualToString:NSUnderlineStyleAttributeName])
|
||||
{
|
||||
if (attributeValue != nil)
|
||||
{
|
||||
if ([attributeValue intValue] == NSUnderlineStyleSingle)
|
||||
thisSGRCode = AMR_SGRCodeUnderlineSingle;
|
||||
else if ([attributeValue intValue] == NSUnderlineStyleDouble)
|
||||
thisSGRCode = AMR_SGRCodeUnderlineDouble;
|
||||
else
|
||||
thisSGRCode = AMR_SGRCodeUnderlineNone;
|
||||
}
|
||||
else
|
||||
thisSGRCode = AMR_SGRCodeUnderlineNone;
|
||||
}
|
||||
|
||||
if (thisSGRCode != AMR_SGRCodeNoneOrInvalid)
|
||||
{
|
||||
[codesAndLocations addObject: @{
|
||||
kAMRCodeDictKey_code: @(thisSGRCode),
|
||||
kAMRCodeDictKey_location: @(effectiveRange.location),
|
||||
}];
|
||||
}
|
||||
|
||||
limitRange = NSMakeRange(NSMaxRange(effectiveRange),
|
||||
NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
|
||||
}
|
||||
}
|
||||
|
||||
return [self ansiEscapedStringWithCodesAndLocations:codesAndLocations cleanString:aAttributedString.string];
|
||||
}
|
||||
|
||||
|
||||
- (NSArray*) escapeCodesForString:(NSString*)aString cleanString:(NSString**)aCleanString
|
||||
{
|
||||
if (aString == nil)
|
||||
return nil;
|
||||
if (aString.length <= kANSIEscapeCSI.length)
|
||||
{
|
||||
if (aCleanString)
|
||||
*aCleanString = aString.copy;
|
||||
return @[];
|
||||
}
|
||||
|
||||
NSString *cleanString = @"";
|
||||
|
||||
// find all escape sequence codes from aString and put them in this array
|
||||
// along with their start locations within the "clean" version of aString
|
||||
NSMutableArray *formatCodes = [NSMutableArray array];
|
||||
|
||||
NSUInteger aStringLength = aString.length;
|
||||
NSUInteger coveredLength = 0;
|
||||
NSRange searchRange = NSMakeRange(0,aStringLength);
|
||||
NSRange thisEscapeSequenceRange;
|
||||
do
|
||||
{
|
||||
thisEscapeSequenceRange = [aString rangeOfString:kANSIEscapeCSI options:NSLiteralSearch range:searchRange];
|
||||
if (thisEscapeSequenceRange.location != NSNotFound)
|
||||
{
|
||||
// adjust range's length so that it encompasses the whole ANSI escape sequence
|
||||
// and not just the Control Sequence Initiator (the "prefix") by finding the
|
||||
// final byte of the control sequence (one that has an ASCII decimal value
|
||||
// between 64 and 126.) at the same time, read all formatting codes from inside
|
||||
// this escape sequence (there may be several, separated by semicolons.)
|
||||
NSMutableArray *codes = [NSMutableArray array];
|
||||
unsigned int code = 0;
|
||||
unsigned int lengthAddition = 1;
|
||||
NSUInteger thisIndex;
|
||||
for (;;)
|
||||
{
|
||||
thisIndex = (NSMaxRange(thisEscapeSequenceRange)+lengthAddition-1);
|
||||
if (thisIndex >= aStringLength)
|
||||
break;
|
||||
|
||||
unichar c = [aString characterAtIndex:thisIndex];
|
||||
|
||||
if (('0' <= c) && (c <= '9'))
|
||||
{
|
||||
int digit = c - '0';
|
||||
code = (code == 0) ? digit : code*10+digit;
|
||||
}
|
||||
|
||||
// ASCII decimal 109 is the SGR (Select Graphic Rendition) final byte
|
||||
// ("m"). this means that the code value we've just read specifies formatting
|
||||
// for the output; exactly what we're interested in.
|
||||
if (c == 'm')
|
||||
{
|
||||
[codes addObject:@(code)];
|
||||
break;
|
||||
}
|
||||
else if ((64 <= c) && (c <= 126)) // any other valid final byte
|
||||
{
|
||||
[codes removeAllObjects];
|
||||
break;
|
||||
}
|
||||
else if (c == ';') // separates codes within the same sequence
|
||||
{
|
||||
[codes addObject:@(code)];
|
||||
code = 0;
|
||||
}
|
||||
|
||||
lengthAddition++;
|
||||
}
|
||||
thisEscapeSequenceRange.length += lengthAddition;
|
||||
|
||||
NSUInteger locationInCleanString = coveredLength+thisEscapeSequenceRange.location-searchRange.location;
|
||||
|
||||
for (NSNumber *codeToAdd in codes)
|
||||
{
|
||||
[formatCodes addObject: @{
|
||||
kAMRCodeDictKey_code: codeToAdd,
|
||||
kAMRCodeDictKey_location: @(locationInCleanString)
|
||||
}];
|
||||
}
|
||||
|
||||
NSUInteger thisCoveredLength = thisEscapeSequenceRange.location-searchRange.location;
|
||||
if (thisCoveredLength > 0)
|
||||
cleanString = [cleanString stringByAppendingString:[aString substringWithRange:NSMakeRange(searchRange.location, thisCoveredLength)]];
|
||||
|
||||
coveredLength += thisCoveredLength;
|
||||
searchRange.location = NSMaxRange(thisEscapeSequenceRange);
|
||||
searchRange.length = aStringLength-searchRange.location;
|
||||
}
|
||||
}
|
||||
while(thisEscapeSequenceRange.location != NSNotFound);
|
||||
|
||||
if (searchRange.length > 0)
|
||||
cleanString = [cleanString stringByAppendingString:[aString substringWithRange:searchRange]];
|
||||
|
||||
if (aCleanString)
|
||||
*aCleanString = cleanString;
|
||||
return formatCodes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (NSString*) ansiEscapedStringWithCodesAndLocations:(NSArray*)aCodesArray cleanString:(NSString*)aCleanString
|
||||
{
|
||||
NSMutableString* retStr = [NSMutableString stringWithCapacity:aCleanString.length];
|
||||
|
||||
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:kAMRCodeDictKey_location ascending:YES];
|
||||
NSArray *codesArray = [aCodesArray sortedArrayUsingDescriptors:@[sortDescriptor]];
|
||||
|
||||
NSUInteger aCleanStringIndex = 0;
|
||||
NSUInteger aCleanStringLength = aCleanString.length;
|
||||
for (NSDictionary *thisCodeDict in codesArray)
|
||||
{
|
||||
if (!( thisCodeDict[kAMRCodeDictKey_code] &&
|
||||
thisCodeDict[kAMRCodeDictKey_location]
|
||||
))
|
||||
continue;
|
||||
|
||||
AMR_SGRCode thisCode = [thisCodeDict[kAMRCodeDictKey_code] unsignedIntValue];
|
||||
NSUInteger formattingRunStartLocation = [thisCodeDict[kAMRCodeDictKey_location] unsignedIntegerValue];
|
||||
|
||||
if (formattingRunStartLocation > aCleanStringLength)
|
||||
continue;
|
||||
|
||||
if (aCleanStringIndex < formattingRunStartLocation)
|
||||
[retStr appendString:[aCleanString substringWithRange:NSMakeRange(aCleanStringIndex, formattingRunStartLocation-aCleanStringIndex)]];
|
||||
[retStr appendFormat:@"%@%d%@", kANSIEscapeCSI, thisCode, kANSIEscapeSGREnd];
|
||||
|
||||
aCleanStringIndex = formattingRunStartLocation;
|
||||
}
|
||||
|
||||
if (aCleanStringIndex < aCleanStringLength)
|
||||
[retStr appendString:[aCleanString substringFromIndex:aCleanStringIndex]];
|
||||
|
||||
[retStr appendFormat:@"%@%d%@", kANSIEscapeCSI, AMR_SGRCodeAllReset, kANSIEscapeSGREnd];
|
||||
|
||||
return retStr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
- (NSArray*) attributesForString:(NSString*)aString cleanString:(NSString**)aCleanString
|
||||
{
|
||||
if (aString == nil)
|
||||
return nil;
|
||||
if (aString.length <= kANSIEscapeCSI.length)
|
||||
{
|
||||
if (aCleanString)
|
||||
*aCleanString = aString.copy;
|
||||
return @[];
|
||||
}
|
||||
|
||||
NSMutableArray *attrsAndRanges = [NSMutableArray array];
|
||||
|
||||
NSString *cleanString;
|
||||
NSArray *formatCodes = [self escapeCodesForString:aString cleanString:&cleanString];
|
||||
|
||||
// go through all the found escape sequence codes and for each one, create
|
||||
// the string formatting attribute name and value, find the next escape
|
||||
// sequence that specifies the end of the formatting run started by
|
||||
// the currently handled code, and generate a range from the difference
|
||||
// in those codes' locations within the clean aString.
|
||||
for (NSUInteger iCode = 0; iCode < formatCodes.count; iCode++)
|
||||
{
|
||||
NSDictionary *thisCodeDict = formatCodes[iCode];
|
||||
AMR_SGRCode thisCode = [thisCodeDict[kAMRCodeDictKey_code] unsignedIntValue];
|
||||
NSUInteger formattingRunStartLocation = [thisCodeDict[kAMRCodeDictKey_location] unsignedIntegerValue];
|
||||
|
||||
// the attributed string attribute name for the formatting run introduced
|
||||
// by this code
|
||||
NSString *thisAttributeName = nil;
|
||||
|
||||
// the attributed string attribute value for this formatting run introduced
|
||||
// by this code
|
||||
NSObject *thisAttributeValue = nil;
|
||||
|
||||
// set attribute name
|
||||
switch(thisCode)
|
||||
{
|
||||
case AMR_SGRCodeFgBlack:
|
||||
case AMR_SGRCodeFgRed:
|
||||
case AMR_SGRCodeFgGreen:
|
||||
case AMR_SGRCodeFgYellow:
|
||||
case AMR_SGRCodeFgBlue:
|
||||
case AMR_SGRCodeFgMagenta:
|
||||
case AMR_SGRCodeFgCyan:
|
||||
case AMR_SGRCodeFgWhite:
|
||||
case AMR_SGRCodeFgBrightBlack:
|
||||
case AMR_SGRCodeFgBrightRed:
|
||||
case AMR_SGRCodeFgBrightGreen:
|
||||
case AMR_SGRCodeFgBrightYellow:
|
||||
case AMR_SGRCodeFgBrightBlue:
|
||||
case AMR_SGRCodeFgBrightMagenta:
|
||||
case AMR_SGRCodeFgBrightCyan:
|
||||
case AMR_SGRCodeFgBrightWhite:
|
||||
thisAttributeName = NSForegroundColorAttributeName;
|
||||
break;
|
||||
case AMR_SGRCodeBgBlack:
|
||||
case AMR_SGRCodeBgRed:
|
||||
case AMR_SGRCodeBgGreen:
|
||||
case AMR_SGRCodeBgYellow:
|
||||
case AMR_SGRCodeBgBlue:
|
||||
case AMR_SGRCodeBgMagenta:
|
||||
case AMR_SGRCodeBgCyan:
|
||||
case AMR_SGRCodeBgWhite:
|
||||
case AMR_SGRCodeBgBrightBlack:
|
||||
case AMR_SGRCodeBgBrightRed:
|
||||
case AMR_SGRCodeBgBrightGreen:
|
||||
case AMR_SGRCodeBgBrightYellow:
|
||||
case AMR_SGRCodeBgBrightBlue:
|
||||
case AMR_SGRCodeBgBrightMagenta:
|
||||
case AMR_SGRCodeBgBrightCyan:
|
||||
case AMR_SGRCodeBgBrightWhite:
|
||||
thisAttributeName = NSBackgroundColorAttributeName;
|
||||
break;
|
||||
case AMR_SGRCodeIntensityBold:
|
||||
case AMR_SGRCodeIntensityNormal:
|
||||
case AMR_SGRCodeIntensityFaint:
|
||||
thisAttributeName = NSFontAttributeName;
|
||||
break;
|
||||
case AMR_SGRCodeUnderlineSingle:
|
||||
case AMR_SGRCodeUnderlineDouble:
|
||||
case AMR_SGRCodeUnderlineNone:
|
||||
thisAttributeName = NSUnderlineStyleAttributeName;
|
||||
break;
|
||||
case AMR_SGRCodeAllReset:
|
||||
case AMR_SGRCodeFgReset:
|
||||
case AMR_SGRCodeBgReset:
|
||||
case AMR_SGRCodeNoneOrInvalid:
|
||||
case AMR_SGRCodeItalicOn:
|
||||
continue;
|
||||
}
|
||||
|
||||
// set attribute value
|
||||
switch(thisCode)
|
||||
{
|
||||
case AMR_SGRCodeBgBlack:
|
||||
case AMR_SGRCodeFgBlack:
|
||||
case AMR_SGRCodeBgRed:
|
||||
case AMR_SGRCodeFgRed:
|
||||
case AMR_SGRCodeBgGreen:
|
||||
case AMR_SGRCodeFgGreen:
|
||||
case AMR_SGRCodeBgYellow:
|
||||
case AMR_SGRCodeFgYellow:
|
||||
case AMR_SGRCodeBgBlue:
|
||||
case AMR_SGRCodeFgBlue:
|
||||
case AMR_SGRCodeBgMagenta:
|
||||
case AMR_SGRCodeFgMagenta:
|
||||
case AMR_SGRCodeBgCyan:
|
||||
case AMR_SGRCodeFgCyan:
|
||||
case AMR_SGRCodeBgWhite:
|
||||
case AMR_SGRCodeFgWhite:
|
||||
case AMR_SGRCodeBgBrightBlack:
|
||||
case AMR_SGRCodeFgBrightBlack:
|
||||
case AMR_SGRCodeBgBrightRed:
|
||||
case AMR_SGRCodeFgBrightRed:
|
||||
case AMR_SGRCodeBgBrightGreen:
|
||||
case AMR_SGRCodeFgBrightGreen:
|
||||
case AMR_SGRCodeBgBrightYellow:
|
||||
case AMR_SGRCodeFgBrightYellow:
|
||||
case AMR_SGRCodeBgBrightBlue:
|
||||
case AMR_SGRCodeFgBrightBlue:
|
||||
case AMR_SGRCodeBgBrightMagenta:
|
||||
case AMR_SGRCodeFgBrightMagenta:
|
||||
case AMR_SGRCodeBgBrightCyan:
|
||||
case AMR_SGRCodeFgBrightCyan:
|
||||
case AMR_SGRCodeBgBrightWhite:
|
||||
case AMR_SGRCodeFgBrightWhite:
|
||||
thisAttributeValue = [self colorForSGRCode:thisCode];
|
||||
break;
|
||||
case AMR_SGRCodeIntensityBold:
|
||||
{
|
||||
NSFont *boldFont = [NSFontManager.sharedFontManager convertFont:self.font toHaveTrait:NSBoldFontMask];
|
||||
thisAttributeValue = boldFont;
|
||||
}
|
||||
break;
|
||||
case AMR_SGRCodeIntensityNormal:
|
||||
case AMR_SGRCodeIntensityFaint:
|
||||
{
|
||||
NSFont *unboldFont = [NSFontManager.sharedFontManager convertFont:self.font toHaveTrait:NSUnboldFontMask];
|
||||
thisAttributeValue = unboldFont;
|
||||
}
|
||||
break;
|
||||
case AMR_SGRCodeUnderlineSingle:
|
||||
thisAttributeValue = @(NSUnderlineStyleSingle);
|
||||
break;
|
||||
case AMR_SGRCodeUnderlineDouble:
|
||||
thisAttributeValue = @(NSUnderlineStyleDouble);
|
||||
break;
|
||||
case AMR_SGRCodeUnderlineNone:
|
||||
thisAttributeValue = @(NSUnderlineStyleNone);
|
||||
break;
|
||||
case AMR_SGRCodeAllReset:
|
||||
case AMR_SGRCodeFgReset:
|
||||
case AMR_SGRCodeBgReset:
|
||||
case AMR_SGRCodeNoneOrInvalid:
|
||||
case AMR_SGRCodeItalicOn:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// find the next sequence that specifies the end of this formatting run
|
||||
NSInteger formattingRunEndLocation = -1;
|
||||
if (iCode < (formatCodes.count - 1))
|
||||
{
|
||||
NSDictionary *thisEndCodeCandidateDict;
|
||||
unichar thisEndCodeCandidate;
|
||||
for (NSUInteger iEndCode = iCode+1; iEndCode < formatCodes.count; iEndCode++)
|
||||
{
|
||||
thisEndCodeCandidateDict = formatCodes[iEndCode];
|
||||
thisEndCodeCandidate = [thisEndCodeCandidateDict[kAMRCodeDictKey_code] unsignedIntValue];
|
||||
|
||||
if ([self AMR_SGRCode:thisEndCodeCandidate endsFormattingIntroducedByCode:thisCode])
|
||||
{
|
||||
formattingRunEndLocation = [thisEndCodeCandidateDict[kAMRCodeDictKey_location] unsignedIntegerValue];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (formattingRunEndLocation == -1)
|
||||
formattingRunEndLocation = cleanString.length;
|
||||
|
||||
if (thisAttributeName && thisAttributeValue)
|
||||
{
|
||||
[attrsAndRanges addObject:@{
|
||||
kAMRAttrDictKey_range: [NSValue valueWithRange:NSMakeRange(formattingRunStartLocation, (formattingRunEndLocation-formattingRunStartLocation))],
|
||||
kAMRAttrDictKey_attrName: thisAttributeName,
|
||||
kAMRAttrDictKey_attrValue: thisAttributeValue,
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
if (aCleanString)
|
||||
*aCleanString = cleanString;
|
||||
return attrsAndRanges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
- (BOOL) AMR_SGRCode:(AMR_SGRCode)endCode endsFormattingIntroducedByCode:(AMR_SGRCode)startCode
|
||||
{
|
||||
switch(startCode)
|
||||
{
|
||||
case AMR_SGRCodeFgBlack:
|
||||
case AMR_SGRCodeFgRed:
|
||||
case AMR_SGRCodeFgGreen:
|
||||
case AMR_SGRCodeFgYellow:
|
||||
case AMR_SGRCodeFgBlue:
|
||||
case AMR_SGRCodeFgMagenta:
|
||||
case AMR_SGRCodeFgCyan:
|
||||
case AMR_SGRCodeFgWhite:
|
||||
case AMR_SGRCodeFgBrightBlack:
|
||||
case AMR_SGRCodeFgBrightRed:
|
||||
case AMR_SGRCodeFgBrightGreen:
|
||||
case AMR_SGRCodeFgBrightYellow:
|
||||
case AMR_SGRCodeFgBrightBlue:
|
||||
case AMR_SGRCodeFgBrightMagenta:
|
||||
case AMR_SGRCodeFgBrightCyan:
|
||||
case AMR_SGRCodeFgBrightWhite:
|
||||
return (endCode == AMR_SGRCodeAllReset || endCode == AMR_SGRCodeFgReset ||
|
||||
endCode == AMR_SGRCodeFgBlack || endCode == AMR_SGRCodeFgRed ||
|
||||
endCode == AMR_SGRCodeFgGreen || endCode == AMR_SGRCodeFgYellow ||
|
||||
endCode == AMR_SGRCodeFgBlue || endCode == AMR_SGRCodeFgMagenta ||
|
||||
endCode == AMR_SGRCodeFgCyan || endCode == AMR_SGRCodeFgWhite ||
|
||||
endCode == AMR_SGRCodeFgBrightBlack || endCode == AMR_SGRCodeFgBrightRed ||
|
||||
endCode == AMR_SGRCodeFgBrightGreen || endCode == AMR_SGRCodeFgBrightYellow ||
|
||||
endCode == AMR_SGRCodeFgBrightBlue || endCode == AMR_SGRCodeFgBrightMagenta ||
|
||||
endCode == AMR_SGRCodeFgBrightCyan || endCode == AMR_SGRCodeFgBrightWhite);
|
||||
case AMR_SGRCodeBgBlack:
|
||||
case AMR_SGRCodeBgRed:
|
||||
case AMR_SGRCodeBgGreen:
|
||||
case AMR_SGRCodeBgYellow:
|
||||
case AMR_SGRCodeBgBlue:
|
||||
case AMR_SGRCodeBgMagenta:
|
||||
case AMR_SGRCodeBgCyan:
|
||||
case AMR_SGRCodeBgWhite:
|
||||
case AMR_SGRCodeBgBrightBlack:
|
||||
case AMR_SGRCodeBgBrightRed:
|
||||
case AMR_SGRCodeBgBrightGreen:
|
||||
case AMR_SGRCodeBgBrightYellow:
|
||||
case AMR_SGRCodeBgBrightBlue:
|
||||
case AMR_SGRCodeBgBrightMagenta:
|
||||
case AMR_SGRCodeBgBrightCyan:
|
||||
case AMR_SGRCodeBgBrightWhite:
|
||||
return (endCode == AMR_SGRCodeAllReset || endCode == AMR_SGRCodeBgReset ||
|
||||
endCode == AMR_SGRCodeBgBlack || endCode == AMR_SGRCodeBgRed ||
|
||||
endCode == AMR_SGRCodeBgGreen || endCode == AMR_SGRCodeBgYellow ||
|
||||
endCode == AMR_SGRCodeBgBlue || endCode == AMR_SGRCodeBgMagenta ||
|
||||
endCode == AMR_SGRCodeBgCyan || endCode == AMR_SGRCodeBgWhite ||
|
||||
endCode == AMR_SGRCodeBgBrightBlack || endCode == AMR_SGRCodeBgBrightRed ||
|
||||
endCode == AMR_SGRCodeBgBrightGreen || endCode == AMR_SGRCodeBgBrightYellow ||
|
||||
endCode == AMR_SGRCodeBgBrightBlue || endCode == AMR_SGRCodeBgBrightMagenta ||
|
||||
endCode == AMR_SGRCodeBgBrightCyan || endCode == AMR_SGRCodeBgBrightWhite);
|
||||
case AMR_SGRCodeIntensityBold:
|
||||
case AMR_SGRCodeIntensityNormal:
|
||||
return (endCode == AMR_SGRCodeAllReset || endCode == AMR_SGRCodeIntensityNormal ||
|
||||
endCode == AMR_SGRCodeIntensityBold || endCode == AMR_SGRCodeIntensityFaint);
|
||||
case AMR_SGRCodeUnderlineSingle:
|
||||
case AMR_SGRCodeUnderlineDouble:
|
||||
return (endCode == AMR_SGRCodeAllReset || endCode == AMR_SGRCodeUnderlineNone ||
|
||||
endCode == AMR_SGRCodeUnderlineSingle || endCode == AMR_SGRCodeUnderlineDouble);
|
||||
case AMR_SGRCodeNoneOrInvalid:
|
||||
case AMR_SGRCodeItalicOn:
|
||||
case AMR_SGRCodeUnderlineNone:
|
||||
case AMR_SGRCodeIntensityFaint:
|
||||
case AMR_SGRCodeAllReset:
|
||||
case AMR_SGRCodeBgReset:
|
||||
case AMR_SGRCodeFgReset:
|
||||
return NO;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (NSColor*) colorForSGRCode:(AMR_SGRCode)code
|
||||
{
|
||||
if (self.ansiColors)
|
||||
{
|
||||
NSColor *preferredColor = self.ansiColors[@(code)];
|
||||
if (preferredColor)
|
||||
return preferredColor;
|
||||
}
|
||||
|
||||
switch(code)
|
||||
{
|
||||
case AMR_SGRCodeFgBlack:
|
||||
return kDefaultANSIColorFgBlack;
|
||||
case AMR_SGRCodeFgRed:
|
||||
return kDefaultANSIColorFgRed;
|
||||
case AMR_SGRCodeFgGreen:
|
||||
return kDefaultANSIColorFgGreen;
|
||||
case AMR_SGRCodeFgYellow:
|
||||
return kDefaultANSIColorFgYellow;
|
||||
case AMR_SGRCodeFgBlue:
|
||||
return kDefaultANSIColorFgBlue;
|
||||
case AMR_SGRCodeFgMagenta:
|
||||
return kDefaultANSIColorFgMagenta;
|
||||
case AMR_SGRCodeFgCyan:
|
||||
return kDefaultANSIColorFgCyan;
|
||||
case AMR_SGRCodeFgWhite:
|
||||
return kDefaultANSIColorFgWhite;
|
||||
case AMR_SGRCodeFgBrightBlack:
|
||||
return kDefaultANSIColorFgBrightBlack;
|
||||
case AMR_SGRCodeFgBrightRed:
|
||||
return kDefaultANSIColorFgBrightRed;
|
||||
case AMR_SGRCodeFgBrightGreen:
|
||||
return kDefaultANSIColorFgBrightGreen;
|
||||
case AMR_SGRCodeFgBrightYellow:
|
||||
return kDefaultANSIColorFgBrightYellow;
|
||||
case AMR_SGRCodeFgBrightBlue:
|
||||
return kDefaultANSIColorFgBrightBlue;
|
||||
case AMR_SGRCodeFgBrightMagenta:
|
||||
return kDefaultANSIColorFgBrightMagenta;
|
||||
case AMR_SGRCodeFgBrightCyan:
|
||||
return kDefaultANSIColorFgBrightCyan;
|
||||
case AMR_SGRCodeFgBrightWhite:
|
||||
return kDefaultANSIColorFgBrightWhite;
|
||||
case AMR_SGRCodeBgBlack:
|
||||
return kDefaultANSIColorBgBlack;
|
||||
case AMR_SGRCodeBgRed:
|
||||
return kDefaultANSIColorBgRed;
|
||||
case AMR_SGRCodeBgGreen:
|
||||
return kDefaultANSIColorBgGreen;
|
||||
case AMR_SGRCodeBgYellow:
|
||||
return kDefaultANSIColorBgYellow;
|
||||
case AMR_SGRCodeBgBlue:
|
||||
return kDefaultANSIColorBgBlue;
|
||||
case AMR_SGRCodeBgMagenta:
|
||||
return kDefaultANSIColorBgMagenta;
|
||||
case AMR_SGRCodeBgCyan:
|
||||
return kDefaultANSIColorBgCyan;
|
||||
case AMR_SGRCodeBgWhite:
|
||||
return kDefaultANSIColorBgWhite;
|
||||
case AMR_SGRCodeBgBrightBlack:
|
||||
return kDefaultANSIColorBgBrightBlack;
|
||||
case AMR_SGRCodeBgBrightRed:
|
||||
return kDefaultANSIColorBgBrightRed;
|
||||
case AMR_SGRCodeBgBrightGreen:
|
||||
return kDefaultANSIColorBgBrightGreen;
|
||||
case AMR_SGRCodeBgBrightYellow:
|
||||
return kDefaultANSIColorBgBrightYellow;
|
||||
case AMR_SGRCodeBgBrightBlue:
|
||||
return kDefaultANSIColorBgBrightBlue;
|
||||
case AMR_SGRCodeBgBrightMagenta:
|
||||
return kDefaultANSIColorBgBrightMagenta;
|
||||
case AMR_SGRCodeBgBrightCyan:
|
||||
return kDefaultANSIColorBgBrightCyan;
|
||||
case AMR_SGRCodeBgBrightWhite:
|
||||
return kDefaultANSIColorBgBrightWhite;
|
||||
case AMR_SGRCodeNoneOrInvalid:
|
||||
case AMR_SGRCodeItalicOn:
|
||||
case AMR_SGRCodeUnderlineNone:
|
||||
case AMR_SGRCodeIntensityFaint:
|
||||
case AMR_SGRCodeAllReset:
|
||||
case AMR_SGRCodeBgReset:
|
||||
case AMR_SGRCodeFgReset:
|
||||
case AMR_SGRCodeIntensityBold:
|
||||
case AMR_SGRCodeIntensityNormal:
|
||||
case AMR_SGRCodeUnderlineSingle:
|
||||
case AMR_SGRCodeUnderlineDouble:
|
||||
break;
|
||||
}
|
||||
|
||||
return kDefaultANSIColorFgBlack;
|
||||
}
|
||||
|
||||
|
||||
- (AMR_SGRCode) AMR_SGRCodeForColor:(NSColor*)aColor isForegroundColor:(BOOL)aForeground
|
||||
{
|
||||
if (self.ansiColors)
|
||||
{
|
||||
NSArray *codesForGivenColor = [self.ansiColors allKeysForObject:aColor];
|
||||
|
||||
if (codesForGivenColor != nil && 0 < codesForGivenColor.count)
|
||||
{
|
||||
for (NSNumber *thisCode in codesForGivenColor)
|
||||
{
|
||||
BOOL thisIsForegroundColor = (thisCode.intValue < 40);
|
||||
if (aForeground == thisIsForegroundColor)
|
||||
return thisCode.intValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aForeground)
|
||||
{
|
||||
if ([aColor isEqual:kDefaultANSIColorFgBlack])
|
||||
return AMR_SGRCodeFgBlack;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgRed])
|
||||
return AMR_SGRCodeFgRed;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgGreen])
|
||||
return AMR_SGRCodeFgGreen;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgYellow])
|
||||
return AMR_SGRCodeFgYellow;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBlue])
|
||||
return AMR_SGRCodeFgBlue;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgMagenta])
|
||||
return AMR_SGRCodeFgMagenta;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgCyan])
|
||||
return AMR_SGRCodeFgCyan;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgWhite])
|
||||
return AMR_SGRCodeFgWhite;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightBlack])
|
||||
return AMR_SGRCodeFgBrightBlack;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightRed])
|
||||
return AMR_SGRCodeFgBrightRed;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightGreen])
|
||||
return AMR_SGRCodeFgBrightGreen;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightYellow])
|
||||
return AMR_SGRCodeFgBrightYellow;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightBlue])
|
||||
return AMR_SGRCodeFgBrightBlue;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightMagenta])
|
||||
return AMR_SGRCodeFgBrightMagenta;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightCyan])
|
||||
return AMR_SGRCodeFgBrightCyan;
|
||||
else if ([aColor isEqual:kDefaultANSIColorFgBrightWhite])
|
||||
return AMR_SGRCodeFgBrightWhite;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([aColor isEqual:kDefaultANSIColorBgBlack])
|
||||
return AMR_SGRCodeBgBlack;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgRed])
|
||||
return AMR_SGRCodeBgRed;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgGreen])
|
||||
return AMR_SGRCodeBgGreen;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgYellow])
|
||||
return AMR_SGRCodeBgYellow;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBlue])
|
||||
return AMR_SGRCodeBgBlue;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgMagenta])
|
||||
return AMR_SGRCodeBgMagenta;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgCyan])
|
||||
return AMR_SGRCodeBgCyan;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgWhite])
|
||||
return AMR_SGRCodeBgWhite;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightBlack])
|
||||
return AMR_SGRCodeBgBrightBlack;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightRed])
|
||||
return AMR_SGRCodeBgBrightRed;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightGreen])
|
||||
return AMR_SGRCodeBgBrightGreen;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightYellow])
|
||||
return AMR_SGRCodeBgBrightYellow;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightBlue])
|
||||
return AMR_SGRCodeBgBrightBlue;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightMagenta])
|
||||
return AMR_SGRCodeBgBrightMagenta;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightCyan])
|
||||
return AMR_SGRCodeBgBrightCyan;
|
||||
else if ([aColor isEqual:kDefaultANSIColorBgBrightWhite])
|
||||
return AMR_SGRCodeBgBrightWhite;
|
||||
}
|
||||
|
||||
return AMR_SGRCodeNoneOrInvalid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// helper struct typedef and a few functions for
|
||||
// -closestSGRCodeForColor:isForegroundColor:
|
||||
|
||||
typedef struct {
|
||||
CGFloat hue;
|
||||
CGFloat saturation;
|
||||
CGFloat brightness;
|
||||
} AMR_HSB;
|
||||
|
||||
AMR_HSB makeHSB(CGFloat hue, CGFloat saturation, CGFloat brightness)
|
||||
{
|
||||
AMR_HSB outHSB;
|
||||
outHSB.hue = hue;
|
||||
outHSB.saturation = saturation;
|
||||
outHSB.brightness = brightness;
|
||||
return outHSB;
|
||||
}
|
||||
|
||||
AMR_HSB getHSBFromColor(NSColor *color)
|
||||
{
|
||||
CGFloat hue = 0.0;
|
||||
CGFloat saturation = 0.0;
|
||||
CGFloat brightness = 0.0;
|
||||
[[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]
|
||||
getHue:&hue
|
||||
saturation:&saturation
|
||||
brightness:&brightness
|
||||
alpha:NULL
|
||||
];
|
||||
return makeHSB(hue, saturation, brightness);
|
||||
}
|
||||
|
||||
BOOL floatsEqual(CGFloat first, CGFloat second, CGFloat maxAbsError)
|
||||
{
|
||||
return (fabs(first-second)) < maxAbsError;
|
||||
}
|
||||
|
||||
#define MAX_HUE_FLOAT_EQUALITY_ABS_ERROR 0.000001
|
||||
|
||||
- (AMR_SGRCode) closestSGRCodeForColor:(NSColor *)color isForegroundColor:(BOOL)foreground
|
||||
{
|
||||
if (color == nil)
|
||||
return AMR_SGRCodeNoneOrInvalid;
|
||||
|
||||
AMR_SGRCode closestColorSGRCode = [self AMR_SGRCodeForColor:color isForegroundColor:foreground];
|
||||
if (closestColorSGRCode != AMR_SGRCodeNoneOrInvalid)
|
||||
return closestColorSGRCode;
|
||||
|
||||
AMR_HSB givenColorHSB = getHSBFromColor(color);
|
||||
|
||||
CGFloat closestColorHueDiff = FLT_MAX;
|
||||
CGFloat closestColorSaturationDiff = FLT_MAX;
|
||||
CGFloat closestColorBrightnessDiff = FLT_MAX;
|
||||
|
||||
// (background SGR codes are +10 from foreground ones:)
|
||||
NSUInteger AMR_SGRCodeShift = (foreground)?0:10;
|
||||
NSArray *ansiFgColorCodes = @[
|
||||
@(AMR_SGRCodeFgBlack+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgRed+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgGreen+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgYellow+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBlue+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgMagenta+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgCyan+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgWhite+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightBlack+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightRed+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightGreen+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightYellow+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightBlue+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightMagenta+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightCyan+AMR_SGRCodeShift),
|
||||
@(AMR_SGRCodeFgBrightWhite+AMR_SGRCodeShift),
|
||||
];
|
||||
for (NSNumber *thisSGRCodeNumber in ansiFgColorCodes)
|
||||
{
|
||||
AMR_SGRCode thisSGRCode = thisSGRCodeNumber.intValue;
|
||||
NSColor *thisColor = [self colorForSGRCode:thisSGRCode];
|
||||
|
||||
AMR_HSB thisColorHSB = getHSBFromColor(thisColor);
|
||||
|
||||
CGFloat hueDiff = fabs(givenColorHSB.hue - thisColorHSB.hue);
|
||||
CGFloat saturationDiff = fabs(givenColorHSB.saturation - thisColorHSB.saturation);
|
||||
CGFloat brightnessDiff = fabs(givenColorHSB.brightness - thisColorHSB.brightness);
|
||||
|
||||
// comparison depends on hue, saturation and brightness
|
||||
// (strictly in that order):
|
||||
|
||||
if (!floatsEqual(hueDiff, closestColorHueDiff, MAX_HUE_FLOAT_EQUALITY_ABS_ERROR))
|
||||
{
|
||||
if (hueDiff > closestColorHueDiff)
|
||||
continue;
|
||||
closestColorSGRCode = thisSGRCode;
|
||||
closestColorHueDiff = hueDiff;
|
||||
closestColorSaturationDiff = saturationDiff;
|
||||
closestColorBrightnessDiff = brightnessDiff;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!floatsEqual(saturationDiff, closestColorSaturationDiff, MAX_HUE_FLOAT_EQUALITY_ABS_ERROR))
|
||||
{
|
||||
if (saturationDiff > closestColorSaturationDiff)
|
||||
continue;
|
||||
closestColorSGRCode = thisSGRCode;
|
||||
closestColorHueDiff = hueDiff;
|
||||
closestColorSaturationDiff = saturationDiff;
|
||||
closestColorBrightnessDiff = brightnessDiff;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!floatsEqual(brightnessDiff, closestColorBrightnessDiff, MAX_HUE_FLOAT_EQUALITY_ABS_ERROR))
|
||||
{
|
||||
if (brightnessDiff > closestColorBrightnessDiff)
|
||||
continue;
|
||||
closestColorSGRCode = thisSGRCode;
|
||||
closestColorHueDiff = hueDiff;
|
||||
closestColorSaturationDiff = saturationDiff;
|
||||
closestColorBrightnessDiff = brightnessDiff;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If hue (especially hue!), saturation and brightness diffs all
|
||||
// are equal to some other color, we need to prefer one or the
|
||||
// other so we'll select the more 'distinctive' color of the
|
||||
// two (this is *very* subjective, obviously). I basically just
|
||||
// looked at the hue chart, went through all the points between
|
||||
// our main ANSI colors and decided which side the middle point
|
||||
// would lean on. (e.g. the purple color that is exactly between
|
||||
// the blue and magenta ANSI colors looks more magenta than
|
||||
// blue to me so I put magenta higher than blue in the list
|
||||
// below.)
|
||||
//
|
||||
// subjective ordering of colors from most to least 'distinctive':
|
||||
long colorDistinctivenessOrder[6] = {
|
||||
AMR_SGRCodeFgRed+AMR_SGRCodeShift,
|
||||
AMR_SGRCodeFgMagenta+AMR_SGRCodeShift,
|
||||
AMR_SGRCodeFgBlue+AMR_SGRCodeShift,
|
||||
AMR_SGRCodeFgGreen+AMR_SGRCodeShift,
|
||||
AMR_SGRCodeFgCyan+AMR_SGRCodeShift,
|
||||
AMR_SGRCodeFgYellow+AMR_SGRCodeShift
|
||||
};
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (colorDistinctivenessOrder[i] == closestColorSGRCode)
|
||||
break;
|
||||
else if (colorDistinctivenessOrder[i] == thisSGRCode)
|
||||
{
|
||||
closestColorSGRCode = thisSGRCode;
|
||||
closestColorHueDiff = hueDiff;
|
||||
closestColorSaturationDiff = saturationDiff;
|
||||
closestColorBrightnessDiff = brightnessDiff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closestColorSGRCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -6,6 +6,7 @@
|
||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AMR_ANSIEscapeHelper.h"
|
||||
#import "TouchBarPrivateApi.h"
|
||||
#import "TouchBarSupport.h"
|
||||
#import "DeprecatedCarbonAPI.h"
|
||||
|
||||
@@ -10,11 +10,16 @@ import Cocoa
|
||||
|
||||
class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||
var tapClosure: (() -> Void)?
|
||||
var longTapClosure: (() -> Void)?
|
||||
var longTapClosure: (() -> Void)? {
|
||||
didSet {
|
||||
longClick.isEnabled = longTapClosure != nil
|
||||
}
|
||||
}
|
||||
var finishViewConfiguration: ()->() = {}
|
||||
|
||||
private var button: NSButton!
|
||||
|
||||
private var singleClick: NSClickGestureRecognizer!
|
||||
private var longClick: NSPressGestureRecognizer!
|
||||
private var singleClick: HapticClickGestureRecognizer!
|
||||
private var longClick: LongPressGestureRecognizer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, title: String) {
|
||||
attributedTitle = title.defaultTouchbarAttributedString
|
||||
@@ -22,11 +27,12 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
super.init(identifier: identifier)
|
||||
button = CustomHeightButton(title: title, target: nil, action: nil)
|
||||
|
||||
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||
longClick = LongPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||
longClick.isEnabled = false
|
||||
longClick.allowedTouchTypes = .direct
|
||||
longClick.delegate = self
|
||||
|
||||
singleClick = NSClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
||||
singleClick = HapticClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
||||
singleClick.allowedTouchTypes = .direct
|
||||
singleClick.delegate = self
|
||||
|
||||
@@ -80,6 +86,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
if let color = backgroundColor {
|
||||
cell.isBordered = true
|
||||
button.bezelColor = color
|
||||
button.bezelStyle = .rounded
|
||||
cell.backgroundColor = color
|
||||
} else {
|
||||
button.isBordered = isBordered
|
||||
@@ -94,20 +101,21 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
|
||||
view.addGestureRecognizer(longClick)
|
||||
view.addGestureRecognizer(singleClick)
|
||||
finishViewConfiguration()
|
||||
}
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
||||
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick {
|
||||
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick
|
||||
|| gestureRecognizer == longClick && otherGestureRecognizer == singleClick // need it
|
||||
{
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@objc func handleGestureSingle(gr: NSClickGestureRecognizer) {
|
||||
let hf: HapticFeedback = HapticFeedback()
|
||||
switch gr.state {
|
||||
case .ended:
|
||||
hf.tap(strong: 2)
|
||||
tapClosure?()
|
||||
break
|
||||
default:
|
||||
@@ -116,17 +124,9 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
}
|
||||
|
||||
@objc func handleGestureLong(gr: NSPressGestureRecognizer) {
|
||||
let hf: HapticFeedback = HapticFeedback()
|
||||
switch gr.state {
|
||||
case .began:
|
||||
if let closure = self.longTapClosure {
|
||||
hf.tap(strong: 2)
|
||||
closure()
|
||||
} else if let closure = self.tapClosure {
|
||||
hf.tap(strong: 6)
|
||||
closure()
|
||||
print("long click")
|
||||
}
|
||||
case .possible: // tiny hack because we're calling action manually
|
||||
(self.longTapClosure ?? self.tapClosure)?()
|
||||
break
|
||||
default:
|
||||
break
|
||||
@@ -160,6 +160,10 @@ class CustomButtonCell: NSButtonCell {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func drawingRect(forBounds rect: NSRect) -> NSRect {
|
||||
return rect // need that so content may better fit in button with very limited width
|
||||
}
|
||||
|
||||
required init(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
@@ -172,6 +176,67 @@ class CustomButtonCell: NSButtonCell {
|
||||
}
|
||||
}
|
||||
|
||||
class HapticClickGestureRecognizer: NSClickGestureRecognizer {
|
||||
override func touchesBegan(with event: NSEvent) {
|
||||
HapticFeedback.shared?.tap(strong: 2)
|
||||
super.touchesBegan(with: event)
|
||||
}
|
||||
|
||||
override func touchesEnded(with event: NSEvent) {
|
||||
HapticFeedback.shared?.tap(strong: 1)
|
||||
super.touchesEnded(with: event)
|
||||
}
|
||||
}
|
||||
|
||||
class LongPressGestureRecognizer: NSPressGestureRecognizer {
|
||||
var recognizeTimeout = 0.4
|
||||
private var timer: Timer?
|
||||
|
||||
override func touchesBegan(with event: NSEvent) {
|
||||
timerInvalidate()
|
||||
|
||||
let touches = event.touches(for: self.view!)
|
||||
if touches.count == 1 { // to prevent it for built-in two/three-finger gestures
|
||||
timer = Timer.scheduledTimer(timeInterval: recognizeTimeout, target: self, selector: #selector(self.onTimer), userInfo: nil, repeats: false)
|
||||
}
|
||||
|
||||
super.touchesBegan(with: event)
|
||||
}
|
||||
|
||||
override func touchesMoved(with event: NSEvent) {
|
||||
timerInvalidate() // to prevent it for built-in two/three-finger gestures
|
||||
super.touchesMoved(with: event)
|
||||
}
|
||||
|
||||
override func touchesCancelled(with event: NSEvent) {
|
||||
timerInvalidate()
|
||||
super.touchesCancelled(with: event)
|
||||
}
|
||||
|
||||
override func touchesEnded(with event: NSEvent) {
|
||||
timerInvalidate()
|
||||
super.touchesEnded(with: event)
|
||||
}
|
||||
|
||||
private func timerInvalidate() {
|
||||
if let timer = timer {
|
||||
timer.invalidate()
|
||||
self.timer = nil
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func onTimer() {
|
||||
if let target = self.target, let action = self.action {
|
||||
target.performSelector(onMainThread: action, with: self, waitUntilDone: false)
|
||||
HapticFeedback.shared?.tap(strong: 6)
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
timerInvalidate()
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
var defaultTouchbarAttributedString: NSAttributedString {
|
||||
let attrTitle = NSMutableAttributedString(string: self, attributes: [.foregroundColor: NSColor.white, .font: NSFont.systemFont(ofSize: 15, weight: .regular), .baselineOffset: 1])
|
||||
|
||||
+48
-14
@@ -9,9 +9,23 @@
|
||||
import IOKit
|
||||
|
||||
class HapticFeedback {
|
||||
static var shared: HapticFeedback?
|
||||
|
||||
// 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
|
||||
// which you can download from https://developer.apple.com/download/more/?=Additional%20Tools
|
||||
// Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID"
|
||||
// There should be programmatic way to get it but I can't find, no docs for macOS :(
|
||||
private let possibleDeviceIDs: [UInt64] = [
|
||||
0x200_0000_0100_0000, // MacBook Pro 2016/2017
|
||||
0x300000080500000 // MacBook Pro 2019 (possibly 2018 as well)
|
||||
]
|
||||
private var correctDeviceID: UInt64?
|
||||
private var actuatorRef: CFTypeRef?
|
||||
private var deviceID: UInt64 = 0x200_0000_0100_0000
|
||||
private var error: IOReturn = 0
|
||||
|
||||
init() {
|
||||
recreateDevice()
|
||||
}
|
||||
|
||||
// Don't know how to do strong is enum one of
|
||||
// 1 like back Click
|
||||
@@ -25,31 +39,51 @@ class HapticFeedback {
|
||||
// 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) {
|
||||
actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
||||
|
||||
guard actuatorRef != nil else {
|
||||
print("guard actuatorRef == nil")
|
||||
guard correctDeviceID != nil, actuatorRef != nil else {
|
||||
print("guard actuatorRef == nil (no haptic device found?)")
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorOpen(actuatorRef!)
|
||||
guard error == kIOReturnSuccess else {
|
||||
var result: IOReturn
|
||||
|
||||
result = MTActuatorOpen(actuatorRef!)
|
||||
guard result == kIOReturnSuccess else {
|
||||
print("guard MTActuatorOpen")
|
||||
recreateDevice()
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorActuate(actuatorRef!, strong, 0, 0.0, 0.0)
|
||||
guard error == kIOReturnSuccess else {
|
||||
result = MTActuatorActuate(actuatorRef!, strong, 0, 0, 0)
|
||||
guard result == kIOReturnSuccess else {
|
||||
print("guard MTActuatorActuate")
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorClose(actuatorRef!)
|
||||
guard error == kIOReturnSuccess else {
|
||||
result = MTActuatorClose(actuatorRef!)
|
||||
guard result == kIOReturnSuccess else {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,9 +17,9 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.20.1</string>
|
||||
<string>0.25</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>185</string>
|
||||
<string>297</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
@@ -39,7 +39,7 @@
|
||||
<key>NSHomeKitUsageDescription</key>
|
||||
<string>MTMR needs access to HomeKit for work</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2018 Anton Palgunov. All rights reserved.</string>
|
||||
<string>Copyright © 2018 - 2020 Anton Palgunov. All rights reserved.</string>
|
||||
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
|
||||
<string>Weather widget need your location for correct work</string>
|
||||
<key>NSLocationAlwaysUsageDescription</key>
|
||||
|
||||
+59
-151
@@ -3,7 +3,7 @@ import Foundation
|
||||
|
||||
extension Data {
|
||||
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)!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,99 +163,6 @@ class SupportedTypesHolder {
|
||||
)
|
||||
},
|
||||
|
||||
"weather": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval; case units; case api_key; case icon_type }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
let units = try container.decodeIfPresent(String.self, forKey: .units)
|
||||
let api_key = try container.decodeIfPresent(String.self, forKey: .api_key)
|
||||
let icon_type = try container.decodeIfPresent(String.self, forKey: .icon_type)
|
||||
let action = try ActionType(from: decoder)
|
||||
let longAction = try LongActionType(from: decoder)
|
||||
return (
|
||||
item: .weather(interval: interval ?? 1800.00, units: units ?? "metric", api_key: api_key ?? "32c4256d09a4c52b38aecddba7a078f6", icon_type: icon_type ?? "text"),
|
||||
action,
|
||||
longAction,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
|
||||
"currency": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to; case full }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
let from = try container.decodeIfPresent(String.self, forKey: .from)
|
||||
let to = try container.decodeIfPresent(String.self, forKey: .to)
|
||||
let full = try container.decodeIfPresent(Bool.self, forKey: .full)
|
||||
let action = try ActionType(from: decoder)
|
||||
let longAction = try LongActionType(from: decoder)
|
||||
return (
|
||||
item: .currency(interval: interval ?? 600.00, from: from ?? "RUB", to: to ?? "USD", full: full ?? false),
|
||||
action,
|
||||
longAction,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
|
||||
"dock": { _ in
|
||||
(
|
||||
item: .dock(),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
|
||||
"inputsource": { _ in
|
||||
(
|
||||
item: .inputsource(),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
|
||||
"volume": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case image }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
if var img = try container.decodeIfPresent(Source.self, forKey: .image) {
|
||||
return (
|
||||
item: .volume(),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [.image: .image(source: img)]
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
item: .volume(),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
"brightness": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval; case image }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
if var img = try container.decodeIfPresent(Source.self, forKey: .image) {
|
||||
return (
|
||||
item: .brightness(refreshInterval: interval ?? 0.5),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [.image: .image(source: img)]
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
item: .brightness(refreshInterval: interval ?? 0.5),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
"sleep": { _ in (
|
||||
item: .staticButton(title: "☕️"),
|
||||
action: .shellScript(executable: "/usr/bin/pmset", parameters: ["sleepnow"]),
|
||||
@@ -270,29 +177,6 @@ class SupportedTypesHolder {
|
||||
parameters: [:]
|
||||
) },
|
||||
|
||||
"music": { decoder in
|
||||
enum CodingKeys: String, CodingKey { case refreshInterval }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||
return (
|
||||
item: .music(interval: interval ?? 1800.00),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
|
||||
"group": { decoder in
|
||||
enum CodingKeys: CodingKey { case items }
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let items = try container.decode([BarItemDefinition].self, forKey: .items)
|
||||
return (
|
||||
item: .groupBar(items: items),
|
||||
action: .none,
|
||||
longAction: .none,
|
||||
parameters: [:]
|
||||
)
|
||||
},
|
||||
]
|
||||
|
||||
static let sharedInstance = SupportedTypesHolder()
|
||||
@@ -325,20 +209,23 @@ class SupportedTypesHolder {
|
||||
enum ItemType: Decodable {
|
||||
case staticButton(title: String)
|
||||
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||
case timeButton(formatTemplate: String, timeZone: String?)
|
||||
case battery()
|
||||
case dock()
|
||||
case volume()
|
||||
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
|
||||
case battery
|
||||
case dock(autoResize: Bool, filter: String?)
|
||||
case volume
|
||||
case brightness(refreshInterval: Double)
|
||||
case weather(interval: Double, units: String, api_key: String, icon_type: String)
|
||||
case yandexWeather(interval: Double)
|
||||
case currency(interval: Double, from: String, to: String, full: Bool)
|
||||
case inputsource()
|
||||
case music(interval: Double)
|
||||
case groupBar(items: [BarItemDefinition])
|
||||
case nightShift()
|
||||
case dnd()
|
||||
case inputsource
|
||||
case music(interval: Double, disableMarquee: Bool)
|
||||
case group(items: [BarItemDefinition])
|
||||
case nightShift
|
||||
case dnd
|
||||
case pomodoro(workTime: Double, restTime: Double)
|
||||
case network(flip: Bool)
|
||||
case darkMode
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case type
|
||||
@@ -353,6 +240,7 @@ enum ItemType: Decodable {
|
||||
case api_key
|
||||
case icon_type
|
||||
case formatTemplate
|
||||
case locale
|
||||
case image
|
||||
case url
|
||||
case longUrl
|
||||
@@ -360,25 +248,31 @@ enum ItemType: Decodable {
|
||||
case workTime
|
||||
case restTime
|
||||
case flip
|
||||
case autoResize
|
||||
case filter
|
||||
case disableMarquee
|
||||
}
|
||||
|
||||
enum ItemTypeRaw: String, Decodable {
|
||||
case staticButton
|
||||
case appleScriptTitledButton
|
||||
case shellScriptTitledButton
|
||||
case timeButton
|
||||
case battery
|
||||
case dock
|
||||
case volume
|
||||
case brightness
|
||||
case weather
|
||||
case yandexWeather
|
||||
case currency
|
||||
case inputsource
|
||||
case music
|
||||
case groupBar
|
||||
case group
|
||||
case nightShift
|
||||
case dnd
|
||||
case pomodoro
|
||||
case network
|
||||
case darkMode
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
@@ -389,6 +283,11 @@ enum ItemType: Decodable {
|
||||
let source = try container.decode(Source.self, forKey: .source)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||
self = .appleScriptTitledButton(source: source, refreshInterval: interval)
|
||||
|
||||
case .shellScriptTitledButton:
|
||||
let source = try container.decode(Source.self, forKey: .source)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||
self = .shellScriptTitledButton(source: source, refreshInterval: interval)
|
||||
|
||||
case .staticButton:
|
||||
let title = try container.decode(String.self, forKey: .title)
|
||||
@@ -397,16 +296,19 @@ enum ItemType: Decodable {
|
||||
case .timeButton:
|
||||
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
||||
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
|
||||
self = .timeButton(formatTemplate: template, timeZone: timeZone)
|
||||
let locale = try container.decodeIfPresent(String.self, forKey: .locale) ?? nil
|
||||
self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||
|
||||
case .battery:
|
||||
self = .battery()
|
||||
self = .battery
|
||||
|
||||
case .dock:
|
||||
self = .dock()
|
||||
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
||||
let filterRegexString = try container.decodeIfPresent(String.self, forKey: .filter)
|
||||
self = .dock(autoResize: autoResize, filter: filterRegexString)
|
||||
|
||||
case .volume:
|
||||
self = .volume()
|
||||
self = .volume
|
||||
|
||||
case .brightness:
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 0.5
|
||||
@@ -418,6 +320,10 @@ enum ItemType: Decodable {
|
||||
let api_key = try container.decodeIfPresent(String.self, forKey: .api_key) ?? "32c4256d09a4c52b38aecddba7a078f6"
|
||||
let icon_type = try container.decodeIfPresent(String.self, forKey: .icon_type) ?? "text"
|
||||
self = .weather(interval: interval, units: units, api_key: api_key, icon_type: icon_type)
|
||||
|
||||
case .yandexWeather:
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||
self = .yandexWeather(interval: interval)
|
||||
|
||||
case .currency:
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 600.0
|
||||
@@ -427,30 +333,34 @@ enum ItemType: Decodable {
|
||||
self = .currency(interval: interval, from: from, to: to, full: full)
|
||||
|
||||
case .inputsource:
|
||||
self = .inputsource()
|
||||
self = .inputsource
|
||||
|
||||
case .music:
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||
self = .music(interval: interval)
|
||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
|
||||
let disableMarquee = try container.decodeIfPresent(Bool.self, forKey: .disableMarquee) ?? false
|
||||
self = .music(interval: interval, disableMarquee: disableMarquee)
|
||||
|
||||
case .groupBar:
|
||||
case .group:
|
||||
let items = try container.decode([BarItemDefinition].self, forKey: .items)
|
||||
self = .groupBar(items: items)
|
||||
self = .group(items: items)
|
||||
|
||||
case .nightShift:
|
||||
self = .nightShift()
|
||||
self = .nightShift
|
||||
|
||||
case .dnd:
|
||||
self = .dnd()
|
||||
self = .dnd
|
||||
|
||||
case .pomodoro:
|
||||
let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) ?? 1500.0
|
||||
let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime) ?? 600.0
|
||||
self = .pomodoro(workTime: workTime, restTime: restTime)
|
||||
|
||||
|
||||
case .network:
|
||||
let flip = try container.decodeIfPresent(Bool.self, forKey: .flip) ?? false
|
||||
self = .network(flip: flip)
|
||||
|
||||
case .darkMode:
|
||||
self = .darkMode
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -692,12 +602,20 @@ extension String {
|
||||
}
|
||||
|
||||
var fileData: Data? {
|
||||
return try? Data(contentsOf: URL(fileURLWithPath: self))
|
||||
return try? Data(contentsOf: URL(fileURLWithPath: (self as NSString).expandingTildeInPath))
|
||||
}
|
||||
|
||||
var fileString: String? {
|
||||
var encoding: String.Encoding = .utf8
|
||||
return try? String(contentsOfFile: self, usedEncoding: &encoding)
|
||||
return try? String(contentsOf: URL(fileURLWithPath: (self as NSString).expandingTildeInPath), usedEncoding: &encoding)
|
||||
}
|
||||
|
||||
var fileURL: URL {
|
||||
return URL(fileURLWithPath: (self as NSString).expandingTildeInPath)
|
||||
}
|
||||
|
||||
var appleScript: NSAppleScript? {
|
||||
return NSAppleScript(source: self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,16 +635,6 @@ enum Align: String, Decodable {
|
||||
case right
|
||||
}
|
||||
|
||||
extension String {
|
||||
var fileURL: URL {
|
||||
return URL(fileURLWithPath: self)
|
||||
}
|
||||
|
||||
var appleScript: NSAppleScript? {
|
||||
return NSAppleScript(source: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension URL {
|
||||
var appleScript: NSAppleScript? {
|
||||
guard FileManager.default.fileExists(atPath: path) else { return nil }
|
||||
|
||||
@@ -3,6 +3,8 @@ import Foundation
|
||||
class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||
var twofingersPrev: CGFloat = 0.0
|
||||
var threefingersPrev: CGFloat = 0.0
|
||||
var twofingers: NSPanGestureRecognizer!
|
||||
var threefingers: NSPanGestureRecognizer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem]) {
|
||||
super.init(identifier: identifier)
|
||||
@@ -14,16 +16,23 @@ class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||
scrollView.documentView = stackView
|
||||
view = scrollView
|
||||
|
||||
let twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||
twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||
twofingers.allowedTouchTypes = .direct
|
||||
twofingers.numberOfTouchesRequired = 2
|
||||
view.addGestureRecognizer(twofingers)
|
||||
|
||||
let threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||
threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||
threefingers.allowedTouchTypes = .direct
|
||||
threefingers.numberOfTouchesRequired = 3
|
||||
view.addGestureRecognizer(threefingers)
|
||||
}
|
||||
|
||||
var gesturesEnabled = true {
|
||||
didSet {
|
||||
twofingers.isEnabled = gesturesEnabled
|
||||
threefingers.isEnabled = gesturesEnabled
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// ShellScriptTouchBarItem.swift
|
||||
// MTMR
|
||||
//
|
||||
// Created by bobr on 08/08/2019.
|
||||
// Copyright © 2019 Anton Palgunov. All rights reserved.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
class ShellScriptTouchBarItem: CustomButtonTouchBarItem {
|
||||
private let interval: TimeInterval
|
||||
private let source: String
|
||||
private var forceHideConstraint: NSLayoutConstraint!
|
||||
|
||||
init?(identifier: NSTouchBarItem.Identifier, source: SourceProtocol, interval: TimeInterval) {
|
||||
self.interval = interval
|
||||
self.source = source.string ?? "echo No \"source\""
|
||||
super.init(identifier: identifier, title: "⏳")
|
||||
|
||||
forceHideConstraint = view.widthAnchor.constraint(equalToConstant: 0)
|
||||
|
||||
DispatchQueue.shellScriptQueue.async {
|
||||
self.refreshAndSchedule()
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func refreshAndSchedule() {
|
||||
// Execute script and get result
|
||||
let scriptResult = execute(source)
|
||||
|
||||
// Apply returned text attributes (if they were returned) to our result string
|
||||
let helper = AMR_ANSIEscapeHelper.init()
|
||||
helper.defaultStringColor = NSColor.white
|
||||
helper.font = "1".defaultTouchbarAttributedString.attribute(.font, at: 0, effectiveRange: nil) as? NSFont
|
||||
let title = NSMutableAttributedString.init(attributedString: helper.attributedString(withANSIEscapedString: scriptResult) ?? NSAttributedString(string: ""))
|
||||
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
|
||||
|
||||
// Update UI
|
||||
DispatchQueue.main.async { [weak self, newBackgoundColor] in
|
||||
if (newBackgoundColor != self?.backgroundColor) { // performance optimization because of reinstallButton
|
||||
self?.backgroundColor = newBackgoundColor
|
||||
}
|
||||
self?.attributedTitle = title
|
||||
self?.forceHideConstraint.isActive = scriptResult == ""
|
||||
}
|
||||
|
||||
// Schedule next update
|
||||
DispatchQueue.shellScriptQueue.asyncAfter(deadline: .now() + interval) { [weak self] in
|
||||
self?.refreshAndSchedule()
|
||||
}
|
||||
}
|
||||
|
||||
func execute(_ command: String) -> String {
|
||||
let task = Process()
|
||||
task.launchPath = "/bin/bash"
|
||||
task.arguments = ["-c", command]
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
var output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String? ?? ""
|
||||
|
||||
if (output == "" && task.terminationStatus != 0) {
|
||||
output = "error"
|
||||
}
|
||||
|
||||
return output.replacingOccurrences(of: "\\n+$", with: "", options: .regularExpression)
|
||||
}
|
||||
}
|
||||
|
||||
extension DispatchQueue {
|
||||
static let shellScriptQueue = DispatchQueue(label: "mtmr.shellscript")
|
||||
}
|
||||
@@ -23,34 +23,40 @@ extension ItemType {
|
||||
return "com.toxblh.mtmr.staticButton."
|
||||
case .appleScriptTitledButton(source: _):
|
||||
return "com.toxblh.mtmr.appleScriptButton."
|
||||
case .timeButton(formatTemplate: _, timeZone: _):
|
||||
case .shellScriptTitledButton(source: _):
|
||||
return "com.toxblh.mtmr.shellScriptButton."
|
||||
case .timeButton(formatTemplate: _, timeZone: _, locale: _):
|
||||
return "com.toxblh.mtmr.timeButton."
|
||||
case .battery():
|
||||
case .battery:
|
||||
return "com.toxblh.mtmr.battery."
|
||||
case .dock():
|
||||
case .dock(autoResize: _, filter: _):
|
||||
return "com.toxblh.mtmr.dock"
|
||||
case .volume():
|
||||
case .volume:
|
||||
return "com.toxblh.mtmr.volume"
|
||||
case .brightness(refreshInterval: _):
|
||||
return "com.toxblh.mtmr.brightness"
|
||||
case .weather(interval: _, units: _, api_key: _, icon_type: _):
|
||||
return "com.toxblh.mtmr.weather"
|
||||
case .yandexWeather(interval: _):
|
||||
return "com.toxblh.mtmr.yandexWeather"
|
||||
case .currency(interval: _, from: _, to: _, full: _):
|
||||
return "com.toxblh.mtmr.currency"
|
||||
case .inputsource():
|
||||
case .inputsource:
|
||||
return "com.toxblh.mtmr.inputsource."
|
||||
case .music(interval: _):
|
||||
return "com.toxblh.mtmr.music."
|
||||
case .groupBar(items: _):
|
||||
case .group(items: _):
|
||||
return "com.toxblh.mtmr.groupBar."
|
||||
case .nightShift(items: _):
|
||||
case .nightShift:
|
||||
return "com.toxblh.mtmr.nightShift."
|
||||
case .dnd(items: _):
|
||||
case .dnd:
|
||||
return "com.toxblh.mtmr.dnd."
|
||||
case .pomodoro(interval: _):
|
||||
return PomodoroBarItem.identifier
|
||||
case .network(flip: _):
|
||||
return NetworkBarItem.identifier
|
||||
case .darkMode:
|
||||
return DarkModeBarItem.identifier
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,22 +78,12 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
var centerIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||
var centerItems: [NSTouchBarItem] = []
|
||||
var rightIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||
var scrollArea: NSCustomTouchBarItem?
|
||||
var scrollArea: ScrollViewItem?
|
||||
var centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||
|
||||
var showControlStripState: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
||||
}
|
||||
}
|
||||
|
||||
var blacklistAppIdentifiers: [String] = []
|
||||
var frontmostApplicationIdentifier: String? {
|
||||
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
|
||||
return frontmostId
|
||||
return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
|
||||
}
|
||||
|
||||
private override init() {
|
||||
@@ -101,10 +97,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
|
||||
}
|
||||
|
||||
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
|
||||
blacklistAppIdentifiers = blackListed
|
||||
}
|
||||
|
||||
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.didTerminateApplicationNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||
@@ -133,6 +127,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||
scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
||||
scrollArea?.gesturesEnabled = AppSettings.multitouchGestures
|
||||
|
||||
touchBar.delegate = self
|
||||
touchBar.defaultItemIdentifiers = []
|
||||
@@ -146,7 +141,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}
|
||||
|
||||
func updateActiveApp() {
|
||||
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil {
|
||||
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil {
|
||||
dismissTouchBar()
|
||||
} else {
|
||||
presentTouchBar()
|
||||
@@ -209,7 +204,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}
|
||||
|
||||
@objc private func presentTouchBar() {
|
||||
if showControlStripState {
|
||||
if AppSettings.showControlStripState {
|
||||
updateControlStripPresence()
|
||||
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||
} else {
|
||||
@@ -247,12 +242,22 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
barItem = CustomButtonTouchBarItem(identifier: identifier, title: title)
|
||||
case let .appleScriptTitledButton(source: source, refreshInterval: interval):
|
||||
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||
case let .timeButton(formatTemplate: template, timeZone: timeZone):
|
||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
|
||||
case .battery():
|
||||
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
|
||||
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||
case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale):
|
||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||
case .battery:
|
||||
barItem = BatteryBarItem(identifier: identifier)
|
||||
case .dock:
|
||||
barItem = AppScrubberTouchBarItem(identifier: identifier)
|
||||
case let .dock(autoResize: autoResize, filter: regexString):
|
||||
if let regexString = regexString {
|
||||
guard let regex = try? NSRegularExpression(pattern: regexString, options: []) else {
|
||||
barItem = CustomButtonTouchBarItem(identifier: identifier, title: "Bad regex")
|
||||
break
|
||||
}
|
||||
barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize, filter: regex)
|
||||
} else {
|
||||
barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize)
|
||||
}
|
||||
case .volume:
|
||||
if case let .image(source)? = item.additionalParameters[.image] {
|
||||
barItem = VolumeViewController(identifier: identifier, image: source.image)
|
||||
@@ -267,22 +272,26 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}
|
||||
case let .weather(interval: interval, units: units, api_key: api_key, icon_type: icon_type):
|
||||
barItem = WeatherBarItem(identifier: identifier, interval: interval, units: units, api_key: api_key, icon_type: icon_type)
|
||||
case let .yandexWeather(interval: interval):
|
||||
barItem = YandexWeatherBarItem(identifier: identifier, interval: interval)
|
||||
case let .currency(interval: interval, from: from, to: to, full: full):
|
||||
barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, full: full)
|
||||
case .inputsource():
|
||||
case .inputsource:
|
||||
barItem = InputSourceBarItem(identifier: identifier)
|
||||
case let .music(interval: interval):
|
||||
barItem = MusicBarItem(identifier: identifier, interval: interval)
|
||||
case let .groupBar(items: items):
|
||||
case let .music(interval: interval, disableMarquee: disableMarquee):
|
||||
barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee)
|
||||
case let .group(items: items):
|
||||
barItem = GroupBarItem(identifier: identifier, items: items)
|
||||
case .nightShift():
|
||||
case .nightShift:
|
||||
barItem = NightShiftBarItem(identifier: identifier)
|
||||
case .dnd():
|
||||
case .dnd:
|
||||
barItem = DnDBarItem(identifier: identifier)
|
||||
case let .pomodoro(workTime: workTime, restTime: restTime):
|
||||
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
||||
case let .network(flip: flip):
|
||||
barItem = NetworkBarItem(identifier: identifier, flip: flip)
|
||||
case .darkMode:
|
||||
barItem = DarkModeBarItem(identifier: identifier)
|
||||
}
|
||||
|
||||
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||
|
||||
@@ -7,217 +7,156 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrubberDataSource {
|
||||
private var scrubber: NSScrubber!
|
||||
|
||||
private let hf: HapticFeedback = HapticFeedback()
|
||||
|
||||
private var timer: Timer!
|
||||
private var ticks: Int = 0
|
||||
private let minTicks: Int = 5
|
||||
private let maxTicks: Int = 20
|
||||
private var lastSelected: Int = 0
|
||||
class AppScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||
private var scrollView = NSScrollView()
|
||||
private var autoResize: Bool = false
|
||||
private var widthConstraint: NSLayoutConstraint?
|
||||
private let filter: NSRegularExpression?
|
||||
|
||||
private var persistentAppIdentifiers: [String] = []
|
||||
private var runningAppsIdentifiers: [String] = []
|
||||
|
||||
private var frontmostApplicationIdentifier: String? {
|
||||
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
|
||||
return frontmostId
|
||||
return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
|
||||
}
|
||||
|
||||
private var applications: [DockItem] = []
|
||||
private var items: [DockBarItem] = []
|
||||
|
||||
override init(identifier: NSTouchBarItem.Identifier) {
|
||||
init(identifier: NSTouchBarItem.Identifier, autoResize: Bool = false, filter: NSRegularExpression? = nil) {
|
||||
self.filter = filter
|
||||
super.init(identifier: identifier)
|
||||
self.autoResize = autoResize
|
||||
view = scrollView
|
||||
|
||||
scrubber = NSScrubber()
|
||||
scrubber.delegate = self
|
||||
scrubber.dataSource = self
|
||||
scrubber.mode = .free // .fixed
|
||||
let layout = NSScrubberFlowLayout()
|
||||
layout.itemSize = NSSize(width: 36, height: 32)
|
||||
layout.itemSpacing = 2
|
||||
scrubber.scrubberLayout = layout
|
||||
scrubber.selectionBackgroundStyle = .roundedBackground
|
||||
scrubber.showsAdditionalContentIndicators = true
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(hardReloadItems), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(hardReloadItems), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(softReloadItems), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||
|
||||
view = scrubber
|
||||
|
||||
scrubber.register(NSScrubberImageItemView.self, forItemIdentifier: NSUserInterfaceItemIdentifier(rawValue: "ScrubberApplicationsItemReuseIdentifier"))
|
||||
|
||||
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.didActivateApplicationNotification, object: nil)
|
||||
|
||||
if let persistent = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.dock.persistent") {
|
||||
persistentAppIdentifiers = persistent
|
||||
}
|
||||
|
||||
updateRunningApplication()
|
||||
persistentAppIdentifiers = AppSettings.dockPersistentAppIds
|
||||
hardReloadItems()
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func activeApplicationChanged(n _: Notification) {
|
||||
updateRunningApplication()
|
||||
}
|
||||
|
||||
override func observeValue(forKeyPath _: String?, of _: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) {
|
||||
updateRunningApplication()
|
||||
}
|
||||
|
||||
func updateRunningApplication() {
|
||||
let newApplications = launchedApplications()
|
||||
|
||||
let index = newApplications.index {
|
||||
$0.bundleIdentifier == frontmostApplicationIdentifier
|
||||
}
|
||||
|
||||
applications = newApplications
|
||||
@objc func hardReloadItems() {
|
||||
applications = launchedApplications()
|
||||
applications += getDockPersistentAppsList()
|
||||
scrubber.reloadData()
|
||||
|
||||
scrubber.selectedIndex = index ?? 0
|
||||
reloadData()
|
||||
softReloadItems()
|
||||
updateSize()
|
||||
}
|
||||
|
||||
@objc func softReloadItems() {
|
||||
let frontMostAppId = self.frontmostApplicationIdentifier
|
||||
let runningAppsIds = NSWorkspace.shared.runningApplications.map { $0.bundleIdentifier }
|
||||
for barItem in items {
|
||||
let bundleId = barItem.dockItem.bundleIdentifier
|
||||
barItem.isRunning = runningAppsIds.contains(bundleId)
|
||||
barItem.isFrontmost = frontMostAppId == bundleId
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func reloadData() {
|
||||
items = applications.map { self.createAppButton(for: $0) }
|
||||
let stackView = NSStackView(views: items.compactMap { $0.view })
|
||||
stackView.spacing = 1
|
||||
stackView.orientation = .horizontal
|
||||
let visibleRect = self.scrollView.documentVisibleRect
|
||||
scrollView.documentView = stackView
|
||||
stackView.scroll(visibleRect.origin)
|
||||
}
|
||||
|
||||
public func numberOfItems(for _: NSScrubber) -> Int {
|
||||
return applications.count
|
||||
}
|
||||
|
||||
public func scrubber(_ scrubber: NSScrubber, viewForItemAt index: Int) -> NSScrubberItemView {
|
||||
let item = scrubber.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "ScrubberApplicationsItemReuseIdentifier"), owner: self) as? NSScrubberImageItemView ?? NSScrubberImageItemView()
|
||||
item.imageView.imageScaling = .scaleProportionallyDown
|
||||
|
||||
let app = applications[index]
|
||||
|
||||
if let icon = app.icon {
|
||||
item.image = icon
|
||||
item.image.size = NSSize(width: 26, height: 26)
|
||||
public func createAppButton(for app: DockItem) -> DockBarItem {
|
||||
let item = DockBarItem(app)
|
||||
item.isBordered = false
|
||||
item.tapClosure = { [weak self] in
|
||||
self?.switchToApp(app: app)
|
||||
}
|
||||
|
||||
item.removeFromSuperview()
|
||||
|
||||
let dotView = NSView(frame: .zero)
|
||||
dotView.wantsLayer = true
|
||||
if runningAppsIdentifiers.contains(app.bundleIdentifier!) {
|
||||
dotView.layer?.backgroundColor = NSColor.white.cgColor
|
||||
} else {
|
||||
dotView.layer?.backgroundColor = NSColor.black.cgColor
|
||||
item.longTapClosure = { [weak self] in
|
||||
self?.handleHalfLongPress(item: app)
|
||||
}
|
||||
dotView.layer?.cornerRadius = 1.5
|
||||
dotView.setFrameOrigin(NSPoint(x: 17, y: 1))
|
||||
dotView.frame.size = NSSize(width: 3, height: 3)
|
||||
item.addSubview(dotView)
|
||||
|
||||
item.killAppClosure = {[weak self] in
|
||||
self?.handleLongPress(item: app)
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
public func didBeginInteracting(with _: NSScrubber) {
|
||||
stopTimer()
|
||||
ticks = 0
|
||||
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(checkTimer), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
@objc private func checkTimer() {
|
||||
ticks += 1
|
||||
|
||||
if ticks == minTicks {
|
||||
hf.tap(strong: 2)
|
||||
}
|
||||
|
||||
if ticks > maxTicks {
|
||||
stopTimer()
|
||||
hf.tap(strong: 6)
|
||||
}
|
||||
}
|
||||
|
||||
private func stopTimer() {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
lastSelected = 0
|
||||
}
|
||||
|
||||
public func didCancelInteracting(with _: NSScrubber) {
|
||||
stopTimer()
|
||||
}
|
||||
|
||||
public func didFinishInteracting(with scrubber: NSScrubber) {
|
||||
stopTimer()
|
||||
|
||||
if ticks == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if ticks >= minTicks && scrubber.selectedIndex > 0 {
|
||||
longPress(selected: scrubber.selectedIndex)
|
||||
return
|
||||
}
|
||||
|
||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
||||
|
||||
public func switchToApp(app: DockItem) {
|
||||
let bundleIdentifier = app.bundleIdentifier
|
||||
if bundleIdentifier!.contains("file://") {
|
||||
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
||||
} else {
|
||||
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
||||
hf.tap(strong: 6)
|
||||
}
|
||||
updateRunningApplication()
|
||||
softReloadItems()
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
private func longPress(selected: Int) {
|
||||
let bundleIdentifier = applications[selected].bundleIdentifier
|
||||
|
||||
if ticks > maxTicks {
|
||||
if let processIdentifier = applications[selected].pid {
|
||||
if !(NSRunningApplication(processIdentifier: processIdentifier)?.terminate())! {
|
||||
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
||||
}
|
||||
|
||||
//todo
|
||||
private func handleLongPress(item: DockItem) {
|
||||
if let pid = item.pid, let app = NSRunningApplication(processIdentifier: pid) {
|
||||
if !app.terminate() {
|
||||
app.forceTerminate()
|
||||
}
|
||||
} else {
|
||||
hf.tap(strong: 6)
|
||||
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
|
||||
persistentAppIdentifiers.remove(at: index)
|
||||
} else {
|
||||
persistentAppIdentifiers.append(bundleIdentifier!)
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(persistentAppIdentifiers, forKey: "com.toxblh.mtmr.dock.persistent")
|
||||
UserDefaults.standard.synchronize()
|
||||
hardReloadItems()
|
||||
}
|
||||
ticks = 0
|
||||
updateRunningApplication()
|
||||
}
|
||||
|
||||
private func handleHalfLongPress(item: DockItem) {
|
||||
if let index = self.persistentAppIdentifiers.firstIndex(of: item.bundleIdentifier) {
|
||||
persistentAppIdentifiers.remove(at: index)
|
||||
hardReloadItems()
|
||||
} else {
|
||||
persistentAppIdentifiers.append(item.bundleIdentifier)
|
||||
}
|
||||
|
||||
AppSettings.dockPersistentAppIds = persistentAppIdentifiers
|
||||
}
|
||||
|
||||
private func launchedApplications() -> [DockItem] {
|
||||
runningAppsIdentifiers = []
|
||||
var returnable: [DockItem] = []
|
||||
for app in NSWorkspace.shared.runningApplications {
|
||||
guard app.activationPolicy == NSApplication.ActivationPolicy.regular else { continue }
|
||||
guard let bundleIdentifier = app.bundleIdentifier else { continue }
|
||||
|
||||
if let filter = self.filter,
|
||||
let name = app.localizedName,
|
||||
filter.numberOfMatches(in: name, options: [], range: NSRange(location: 0, length: name.count)) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
runningAppsIdentifiers.append(bundleIdentifier)
|
||||
|
||||
let dockItem = DockItem(bundleIdentifier: bundleIdentifier, icon: getIcon(forBundleIdentifier: bundleIdentifier), pid: app.processIdentifier)
|
||||
let dockItem = DockItem(bundleIdentifier: bundleIdentifier, icon: app.icon ?? getIcon(forBundleIdentifier: bundleIdentifier), pid: app.processIdentifier)
|
||||
returnable.append(dockItem)
|
||||
}
|
||||
return returnable
|
||||
}
|
||||
|
||||
public func getIcon(forBundleIdentifier bundleIdentifier: String? = nil, orPath path: String? = nil, orType _: String? = nil) -> NSImage {
|
||||
if bundleIdentifier != nil {
|
||||
if let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier!) {
|
||||
return NSWorkspace.shared.icon(forFile: appPath)
|
||||
}
|
||||
public func getIcon(forBundleIdentifier bundleIdentifier: String? = nil, orPath path: String? = nil) -> NSImage {
|
||||
if let bundleIdentifier = bundleIdentifier, let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier) {
|
||||
return NSWorkspace.shared.icon(forFile: appPath)
|
||||
}
|
||||
|
||||
if path != nil {
|
||||
return NSWorkspace.shared.icon(forFile: path!)
|
||||
if let path = path {
|
||||
return NSWorkspace.shared.icon(forFile: path)
|
||||
}
|
||||
|
||||
let genericIcon = NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns")
|
||||
@@ -248,3 +187,60 @@ public class DockItem: NSObject {
|
||||
self.pid = pid
|
||||
}
|
||||
}
|
||||
|
||||
private let iconWidth = 32.0
|
||||
class DockBarItem: CustomButtonTouchBarItem {
|
||||
let dotView = NSView(frame: .zero)
|
||||
let dockItem: DockItem
|
||||
fileprivate var killGestureRecognizer: LongPressGestureRecognizer!
|
||||
var killAppClosure: () -> Void = { }
|
||||
|
||||
var isRunning = false {
|
||||
didSet {
|
||||
redrawDotView()
|
||||
}
|
||||
}
|
||||
|
||||
var isFrontmost = false {
|
||||
didSet {
|
||||
redrawDotView()
|
||||
}
|
||||
}
|
||||
|
||||
init(_ app: DockItem) {
|
||||
self.dockItem = app
|
||||
super.init(identifier: .init(app.bundleIdentifier), title: "")
|
||||
dotView.wantsLayer = true
|
||||
|
||||
image = app.icon
|
||||
image?.size = NSSize(width: iconWidth, height: iconWidth)
|
||||
|
||||
killGestureRecognizer = LongPressGestureRecognizer(target: self, action: #selector(firePanGestureRecognizer))
|
||||
killGestureRecognizer.allowedTouchTypes = .direct
|
||||
killGestureRecognizer.recognizeTimeout = 1.5
|
||||
killGestureRecognizer.minimumPressDuration = 1.5
|
||||
killGestureRecognizer.isEnabled = isRunning
|
||||
|
||||
self.finishViewConfiguration = { [weak self] in
|
||||
guard let selfie = self else { return }
|
||||
selfie.dotView.layer?.cornerRadius = 1.5
|
||||
selfie.view.addSubview(selfie.dotView)
|
||||
selfie.redrawDotView()
|
||||
selfie.view.addGestureRecognizer(selfie.killGestureRecognizer)
|
||||
}
|
||||
}
|
||||
|
||||
func redrawDotView() {
|
||||
dotView.layer?.backgroundColor = isRunning ? NSColor.white.cgColor : NSColor.clear.cgColor
|
||||
dotView.frame.size = NSSize(width: isFrontmost ? iconWidth - 14 : 3, height: 3)
|
||||
dotView.setFrameOrigin(NSPoint(x: 18.0 - Double(dotView.frame.size.width) / 2.0, y: iconWidth - 5))
|
||||
}
|
||||
|
||||
@objc func firePanGestureRecognizer() {
|
||||
self.killAppClosure()
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,12 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
|
||||
let regularFont = attributedTitle.attribute(.font, at: 0, effectiveRange: nil) as? NSFont ?? NSFont.systemFont(ofSize: 15)
|
||||
let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont])
|
||||
let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont, .baselineOffset: 1])
|
||||
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
||||
attributedTitle = newTitle
|
||||
}
|
||||
|
||||
deinit {
|
||||
activity.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import Foundation
|
||||
|
||||
class DarkModeBarItem: CustomButtonTouchBarItem, Widget {
|
||||
static var name: String = "darkmode"
|
||||
static var identifier: String = "com.toxblh.mtmr.darkmode"
|
||||
|
||||
private var timer: Timer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier) {
|
||||
super.init(identifier: identifier, title: "")
|
||||
isBordered = false
|
||||
setWidth(value: 24)
|
||||
|
||||
tapClosure = { [weak self] in self?.DarkModeToggle() }
|
||||
|
||||
timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||
|
||||
refresh()
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func DarkModeToggle() {
|
||||
DarkMode.isEnabled = !DarkMode.isEnabled
|
||||
refresh()
|
||||
}
|
||||
|
||||
@objc func refresh() {
|
||||
image = DarkMode.isEnabled ? #imageLiteral(resourceName: "dark-mode-on") : #imageLiteral(resourceName: "dark-mode-off")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct DarkMode {
|
||||
private static let prefix = "tell application \"System Events\" to tell appearance preferences to"
|
||||
|
||||
static var isEnabled: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark"
|
||||
}
|
||||
set {
|
||||
toggle(force: newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static func toggle(force: Bool? = nil) {
|
||||
let value = force.map(String.init) ?? "not dark mode"
|
||||
_ = runAppleScript("\(prefix) set dark mode to \(value)")
|
||||
}
|
||||
}
|
||||
|
||||
func runAppleScript(_ source: String) -> String? {
|
||||
return NSAppleScript(source: source)?.executeAndReturnError(nil).stringValue
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = []
|
||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = leftIdentifiers + [centerScrollArea] + rightIdentifiers
|
||||
|
||||
if TouchBarController.shared.showControlStripState {
|
||||
if AppSettings.showControlStripState {
|
||||
presentSystemModal(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||
} else {
|
||||
presentSystemModal(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||
|
||||
@@ -10,21 +10,32 @@ import Cocoa
|
||||
import ScriptingBridge
|
||||
|
||||
class MusicBarItem: CustomButtonTouchBarItem {
|
||||
private enum Player: String {
|
||||
case iTunes = "com.apple.iTunes"
|
||||
case Spotify = "com.spotify.client"
|
||||
case VOX = "com.coppertino.Vox"
|
||||
case Chrome = "com.google.Chrome"
|
||||
case Safari = "com.apple.Safari"
|
||||
}
|
||||
|
||||
private let playerBundleIdentifiers = [
|
||||
Player.iTunes,
|
||||
Player.Spotify,
|
||||
Player.VOX,
|
||||
Player.Chrome,
|
||||
Player.Safari,
|
||||
]
|
||||
|
||||
private let interval: TimeInterval
|
||||
private let disableMarquee: Bool
|
||||
private var songTitle: String?
|
||||
private var timer: Timer?
|
||||
let buttonSize = NSSize(width: 21, height: 21)
|
||||
private let iconSize = NSSize(width: 21, height: 21)
|
||||
|
||||
let playerBundleIdentifiers = [
|
||||
"com.apple.iTunes",
|
||||
"com.spotify.client",
|
||||
"com.coppertino.Vox",
|
||||
"com.google.Chrome",
|
||||
"com.apple.Safari",
|
||||
]
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, disableMarquee: Bool) {
|
||||
self.interval = interval
|
||||
self.disableMarquee = disableMarquee
|
||||
|
||||
super.init(identifier: identifier, title: "⏳")
|
||||
isBordered = false
|
||||
@@ -50,21 +61,21 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
|
||||
@objc func playPause() {
|
||||
for ident in playerBundleIdentifiers {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||
if musicPlayer.isRunning {
|
||||
if musicPlayer.className == "SpotifyApplication" {
|
||||
if ident == .Spotify {
|
||||
let mp = (musicPlayer as SpotifyApplication)
|
||||
mp.playpause!()
|
||||
return
|
||||
} else if musicPlayer.className == "ITunesApplication" {
|
||||
} else if ident == .iTunes {
|
||||
let mp = (musicPlayer as iTunesApplication)
|
||||
mp.playpause!()
|
||||
return
|
||||
} else if musicPlayer.className == "VOXApplication" {
|
||||
} else if ident == .VOX {
|
||||
let mp = (musicPlayer as VoxApplication)
|
||||
mp.playpause!()
|
||||
return
|
||||
} else if musicPlayer.className == "SafariApplication" {
|
||||
} else if ident == .Safari {
|
||||
// You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use 'do JavaScript'.
|
||||
let safariApplication = musicPlayer as SafariApplication
|
||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||
@@ -84,7 +95,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (musicPlayer.className == "GoogleChromeApplication") {
|
||||
// else if (ident == .Chrome) {
|
||||
// let chromeApplication = musicPlayer as GoogleChromeApplication
|
||||
// let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
||||
// for window in chromeWindows! {
|
||||
@@ -111,24 +122,24 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
|
||||
@objc func nextTrack() {
|
||||
for ident in playerBundleIdentifiers {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||
if musicPlayer.isRunning {
|
||||
if musicPlayer.className == "SpotifyApplication" {
|
||||
if ident == .Spotify {
|
||||
let mp = (musicPlayer as SpotifyApplication)
|
||||
mp.nextTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if musicPlayer.className == "ITunesApplication" {
|
||||
} else if ident == .iTunes {
|
||||
let mp = (musicPlayer as iTunesApplication)
|
||||
mp.nextTrack!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if musicPlayer.className == "VOXApplication" {
|
||||
} else if ident == .VOX {
|
||||
let mp = (musicPlayer as VoxApplication)
|
||||
mp.next!()
|
||||
updatePlayer()
|
||||
return
|
||||
} else if musicPlayer.className == "SafariApplication" {
|
||||
} else if ident == .Safari {
|
||||
// You must enable the 'Allow JavaScript from Apple Events' option in Safari's Develop menu to use 'do JavaScript'.
|
||||
let safariApplication = musicPlayer as SafariApplication
|
||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||
@@ -169,17 +180,17 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
var iconUpdated = false
|
||||
var titleUpdated = false
|
||||
|
||||
for var ident in playerBundleIdentifiers {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
||||
for ident in playerBundleIdentifiers {
|
||||
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||
if musicPlayer.isRunning {
|
||||
var tempTitle = ""
|
||||
if musicPlayer.className == "SpotifyApplication" {
|
||||
if ident == .Spotify {
|
||||
tempTitle = (musicPlayer as SpotifyApplication).title
|
||||
} else if musicPlayer.className == "ITunesApplication" {
|
||||
} else if ident == .iTunes {
|
||||
tempTitle = (musicPlayer as iTunesApplication).title
|
||||
} else if musicPlayer.className == "VOXApplication" {
|
||||
} else if ident == .VOX {
|
||||
tempTitle = (musicPlayer as VoxApplication).title
|
||||
} else if musicPlayer.className == "SafariApplication" {
|
||||
} else if ident == .Safari {
|
||||
let safariApplication = musicPlayer as SafariApplication
|
||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||
for window in safariWindows! {
|
||||
@@ -199,10 +210,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
if tempTitle == "" {
|
||||
ident = ""
|
||||
}
|
||||
} else if musicPlayer.className == "GoogleChromeApplication" {
|
||||
} else if ident == .Chrome {
|
||||
let chromeApplication = musicPlayer as GoogleChromeApplication
|
||||
let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
||||
for window in chromeWindows! {
|
||||
@@ -222,9 +230,6 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
if tempTitle == "" {
|
||||
ident = ""
|
||||
}
|
||||
}
|
||||
|
||||
if tempTitle == self.songTitle {
|
||||
@@ -234,16 +239,22 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
|
||||
if let songTitle = self.songTitle?.ifNotEmpty {
|
||||
self.title = " " + songTitle + " "
|
||||
titleUpdated = true
|
||||
self.timer?.invalidate()
|
||||
self.timer = nil
|
||||
self.timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.marquee), userInfo: nil, repeats: true)
|
||||
|
||||
if (disableMarquee) {
|
||||
self.title = " " + songTitle
|
||||
} else {
|
||||
self.title = " " + songTitle + " "
|
||||
self.timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.marquee), userInfo: nil, repeats: true)
|
||||
}
|
||||
|
||||
titleUpdated = true
|
||||
}
|
||||
if let ident = ident.ifNotEmpty,
|
||||
let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: ident) {
|
||||
if let _ = tempTitle.ifNotEmpty,
|
||||
let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: ident.rawValue) {
|
||||
let image = NSWorkspace.shared.icon(forFile: appPath)
|
||||
image.size = self.buttonSize
|
||||
image.size = self.iconSize
|
||||
self.image = image
|
||||
iconUpdated = true
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
||||
var dSpeed: UInt64?
|
||||
var uSpeed: UInt64?
|
||||
var curr: Array<Substring>?
|
||||
var dataAvailable: NSObjectProtocol!
|
||||
var dataAvailable: NSObjectProtocol?
|
||||
|
||||
pipe = Pipe()
|
||||
bandwidthProcess = Process()
|
||||
@@ -64,19 +64,21 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
||||
}
|
||||
}
|
||||
outputHandle.waitForDataInBackgroundAndNotify()
|
||||
} else {
|
||||
} else if let dataAvailable = dataAvailable {
|
||||
NotificationCenter.default.removeObserver(dataAvailable)
|
||||
}
|
||||
}
|
||||
|
||||
var dataReady: NSObjectProtocol!
|
||||
var dataReady: NSObjectProtocol?
|
||||
dataReady = NotificationCenter.default.addObserver(
|
||||
forName: Process.didTerminateNotification,
|
||||
object: outputHandle,
|
||||
queue: nil
|
||||
) { _ -> Void in
|
||||
print("Task terminated!")
|
||||
NotificationCenter.default.removeObserver(dataReady)
|
||||
if let observer = dataReady {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
}
|
||||
|
||||
bandwidthProcess?.launch()
|
||||
|
||||
@@ -35,7 +35,7 @@ class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||
case none
|
||||
}
|
||||
|
||||
private let defaultTitle = "🍅"
|
||||
private let defaultTitle = "🍅 "
|
||||
private let workTime: TimeInterval
|
||||
private let restTime: TimeInterval
|
||||
private var typeTime: TimeTypes = .none
|
||||
|
||||
@@ -4,8 +4,11 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
|
||||
private let dateFormatter = DateFormatter()
|
||||
private var timer: Timer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil) {
|
||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil, locale: String? = nil) {
|
||||
dateFormatter.dateFormat = formatTemplate
|
||||
if let locale = locale {
|
||||
dateFormatter.locale = Locale(identifier: locale)
|
||||
}
|
||||
if let abbr = timeZone {
|
||||
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
|
||||
}
|
||||
|
||||
@@ -135,4 +135,8 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||
// print("inside didChangeAuthorization ");
|
||||
updateWeather()
|
||||
}
|
||||
|
||||
deinit {
|
||||
activity.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// YandexWeatherBarItem.swift
|
||||
// MTMR
|
||||
//
|
||||
// Created by bobrosoft on 22/07/2019.
|
||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import CoreLocation
|
||||
|
||||
class YandexWeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||
private let activity: NSBackgroundActivityScheduler
|
||||
private let unitsStr = "°C"
|
||||
private let iconsSource = [
|
||||
"Ясно": "☀️", "Малооблачно": "🌤", "Облачно с прояснениями": "⛅️", "Пасмурно": "☁️", "Небольшой дождь": "🌦", "Дождь": "🌧", "Ливень": "⛈", "Гроза": "🌩", "Дождь со снегом": "☔️", "Небольшой снег": "❄️", "Снег": "🌨", "Туман": "🌫",
|
||||
"Clear": "☀️", "Mostly clear": "🌤", "Partly cloudy": "⛅️", "Overcast": "☁️", "Light rain": "🌦", "Rain": "🌧", "Heavy rain": "⛈", "Storm": "🌩", "Sleet": "☔️", "Light snow": "❄️", "Snow": "🌨", "Fog": "🌫"
|
||||
]
|
||||
private var location: CLLocation!
|
||||
private var prevLocation: CLLocation!
|
||||
private var manager: CLLocationManager!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
||||
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||
activity.interval = interval
|
||||
|
||||
super.init(identifier: identifier, title: "⏳")
|
||||
|
||||
let status = CLLocationManager.authorizationStatus()
|
||||
if status == .restricted || status == .denied {
|
||||
print("User permission not given")
|
||||
return
|
||||
}
|
||||
|
||||
if !CLLocationManager.locationServicesEnabled() {
|
||||
print("Location services not enabled")
|
||||
return
|
||||
}
|
||||
|
||||
activity.repeats = true
|
||||
activity.qualityOfService = .utility
|
||||
activity.schedule { (completion: NSBackgroundActivityScheduler.CompletionHandler) in
|
||||
self.updateWeather()
|
||||
completion(NSBackgroundActivityScheduler.Result.finished)
|
||||
}
|
||||
updateWeather()
|
||||
|
||||
manager = CLLocationManager()
|
||||
manager.delegate = self
|
||||
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
||||
manager.startUpdatingLocation()
|
||||
|
||||
tapClosure = tapClosure ?? defaultTapAction
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
@objc func updateWeather() {
|
||||
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
|
||||
|
||||
let task = URLSession.shared.dataTask(with: urlRequest) { data, _, error in
|
||||
guard error == nil, let response = data?.utf8string else {
|
||||
return
|
||||
}
|
||||
// print(response)
|
||||
|
||||
var matches: [[String]]
|
||||
var temperature: String?
|
||||
matches = response.matchingStrings(regex: "fact__temp.*?temp__value.*?>(.*?)<")
|
||||
temperature = matches.first?.item(at: 1)
|
||||
|
||||
var icon: String?
|
||||
matches = response.matchingStrings(regex: "link__condition.*?>(.*?)<")
|
||||
icon = matches.first?.item(at: 1)
|
||||
if let _ = icon, let test = self.iconsSource[icon!] {
|
||||
icon = test
|
||||
}
|
||||
|
||||
if temperature != nil {
|
||||
DispatchQueue.main.async {
|
||||
self.setWeather(text: "\(icon ?? "?") \(temperature!)\(self.unitsStr)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
|
||||
func getWeatherUrl() -> String {
|
||||
if location != nil {
|
||||
return "https://yandex.ru/pogoda/?lat=\(location.coordinate.latitude)&lon=\(location.coordinate.longitude)?lang=ru"
|
||||
} else {
|
||||
return "https://yandex.ru/pogoda/?lang=ru" // Yandex will try to determine your location by default
|
||||
}
|
||||
}
|
||||
|
||||
func setWeather(text: String) {
|
||||
title = text
|
||||
}
|
||||
|
||||
func defaultTapAction() {
|
||||
print(getWeatherUrl())
|
||||
if let url = URL(string: getWeatherUrl()) {
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
}
|
||||
|
||||
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||
let lastLocation = locations.last!
|
||||
location = lastLocation
|
||||
if prevLocation == nil {
|
||||
updateWeather()
|
||||
}
|
||||
prevLocation = lastLocation
|
||||
}
|
||||
|
||||
func locationManager(_: CLLocationManager, didFailWithError error: Error) {
|
||||
print(error)
|
||||
}
|
||||
|
||||
func locationManager(_: CLLocationManager, didChangeAuthorization _: CLAuthorizationStatus) {
|
||||
updateWeather()
|
||||
}
|
||||
|
||||
deinit {
|
||||
activity.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func matchingStrings(regex: String) -> [[String]] {
|
||||
guard let regex = try? NSRegularExpression(pattern: regex, options: []) else { return [] }
|
||||
let nsString = self as NSString
|
||||
let results = regex.matches(in: self, options: [], range: NSMakeRange(0, nsString.length))
|
||||
return results.map { result in
|
||||
(0 ..< result.numberOfRanges).map {
|
||||
result.range(at: $0).location != NSNotFound
|
||||
? nsString.substring(with: result.range(at: $0))
|
||||
: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Array {
|
||||
func item(at index: Int) -> Element? {
|
||||
return indices.contains(index) ? self[index] : nil
|
||||
}
|
||||
}
|
||||
+74
-67
@@ -1,82 +1,89 @@
|
||||
[
|
||||
{ "type": "escape", "align": "left" },
|
||||
{ "type": "exitTouchbar", "width": 44, "align": "left" },
|
||||
{ "type": "brightnessDown", "width": 44, "align": "left" },
|
||||
{
|
||||
"type": "brightness",
|
||||
"width": 60,
|
||||
"align": "left",
|
||||
"image": {
|
||||
"base64":
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAQMAAAD58POIAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURffLOPfLNyaSVzUAAAACdFJOU/kBxOqnWgAAAbJJREFUSMfVljtyhDAQBVulQCFH4CgcDR1NR9ERFBKoeA5GfGddtkNvwFINFKP5tED22+Zxwviv6QVKfIEc/iNoF5gkpLIeYI8SUp4PsAUJiekADQntF6isQjvxCTrhAJlFqMMBeIH9BMsD7DAb2BhvYbIyNAOCZIWqYKGTpDZJFQu9EKVd44RxQRq3IrULWD62C8wSssWUZEsR0k6wcDOrJZmoBpMKI+s5qkBQCQOUJADVOECdOsDS0gDbsgHMfT4rVwHSrZQFIN5ABka8BgDgAeZ+BztBgvUEnSgVlhNsTFJjvoF5HAZorBpdYKAiSRbqNyBIUr6AjZMdPwO72R40MElS+wZUWA+wQ6LAYkFvdIhkmA+wQSDDdIAGAZ6A34H0x0fca11gBZZsIHSIfnE/5+NjCn/OuiuUB+/aunZwDeNayjXdTpDN0wlY+r1PfWu75nfj8RogN2JuCN2Y5qgMwTI0wGPUnQw6Qarx0sVNKA5Mn6VUL22lIbZoYitDbPmlvocc9Umfl2D7adz1reC3pF8av4m+DCenp/ndZuG3E7fhuC3pH2+vnz8V3MfE+bnxBTXuuIMTrLWHAAAAAElFTkSuQmCC"
|
||||
}
|
||||
"type": "escape",
|
||||
"width": 64,
|
||||
"align": "left"
|
||||
},
|
||||
{ "type": "brightnessUp", "width": 44, "align": "left" },
|
||||
// --- iTunes ---
|
||||
{
|
||||
"type": "dnd",
|
||||
"align": "left",
|
||||
"width": 38
|
||||
},
|
||||
{ "type": "brightnessDown", "width": 32, "bordered": false, "align": "left" },
|
||||
{ "type": "brightnessUp", "width": 32, "bordered": false, "align": "left" },
|
||||
|
||||
// Spotify
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"inline":
|
||||
"if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rreturn (get artist of current track) & \" – \" & (get name of current track)\relse\rreturn \"\"\rend if\rend tell\rend if\rreturn \"\"\r"
|
||||
"inline": "if application \"Spotify\" is running then\rtell application \"Spotify\"\rif player state is playing then\rreturn (get artist of current track) & \" – \" & (get name of current track)\relse\rreturn \"\"\rend if\rend tell\rend if\rreturn \"\"\r"
|
||||
},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"inline":
|
||||
"if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
||||
"inline": "if application \"Spotify\" is running then\rtell application \"Spotify\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
||||
},
|
||||
"refreshInterval": 1,
|
||||
"image": {
|
||||
"base64":
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAADAUExURUdwTOVVZCzB+3qc0gkDBgEBAgcKEwAAAA4EBP5aVU2V95iJv7V3rtBOvH5W6jaOyclScKZGX3wuQCMuUqZN7+NQYXtDvFd9/sxYni2z6UhBhyhvnIp7sf38/PXz9ePm69/k6fHv8/j29+3q7/v6+ufq7uvu8fTw8+1egOFki/dbboVj/HNy/T+j/dNtnEul81vC8Vmf3OeRqOBVofK4xZfF7sDb7PLe6LxU1KKK79PL6vrW3fh4g5Zi4bi16daa0A3Qc90AAAAddFJOUwD3/v0uOlYNG/z+/v7998OYYztt/Le2/eDqi5jEo2rNTwAABMtJREFUWMPdl1tjqjoQhauC0Hqvta26JVxUQBQFRPBS/f//as8kISBqd/twXs5KjBDyrZkEFfP09D+WoigqFxz+mlbVXncweEZVBoNuD1x+E1vtMVZoURn01J/mob52KRNuj4k5mZjJcRueFotFpfv6EwdVRfy0tSdXSranheN0/zkRSB7x42Q6udExdBy3972Fog4o/kBg4X6bhPJaeX7eTqeT6b0MJtPpdOu6n49XQgX+dOQ8vpWEvYn/2AHiL052PpoROcsOtND17ztQ3rwTuCQz9O/moKiMf6BkG/puKBzurKQ64PmbU2bDzUxk3Uql4lZcl3Vpvt9VbxLoLZwjY7E1WcNZoB0XpbELie/3Sg6KVHG2jGPs1LTCE2UXFfgIgtBgyq8d/E/pehJq1zmZGc7kAPsMX4Ec932T25uX5vUklFcHJlDU1OT4wllkvOtn9lrSbF7dCUggNEtaMOXhQZq4WkpBcksJQBCOnyjvM4P8KqQgFW9BFJka2NMKB1gw+VMxvN9smnwI1EuzpxS+g9FWYySjsTpOtnq+H162iW01m/wyXLUPzT/5HKQoSjQmU8vE6TAElvWggbhuNRpScQa002bVtJmBCz9qNusWBkJmoyHmoHajC4yybVujhR26mJVha7lDo2FrhnA4N0aq+BpE24zjgsMoEsfU0AADaKCwemiIRZA+o6N9oygyMi/EAWk0DMNgFvCmN/5IwqCV3PCGzzIwbINrzgwykVq2iorUalm2UTZotXKWqVYz5uBjzDUoxrxWyzKQWy061LZsNIJ3PAMDIcbVauwdGmxrNblgYNnCgStN54ylBSsYoAxerwwgJsCWTS0sepym0Mdp1gYBw5lmwgDXIDEoaeHLYE36BafzuQWFQ9RASM/XQPpMD5YQ2gA/AwPArQJyZWDsgo64C+/pBRkDG4s31hdmwFNAGz1mBjPukBs8qdSgLDBA1LJm1lw/14IgWAdAQ5nhax4HY/FR7qfpHQMPUChzS0c6eFmv17MZo7HZBP3MQJHTNCnzxPMgOFUteAGtMwMmfRPIijBgc+AmNK6+9zw+9Iw05YsG8aaT/7Kro7eUcoSWw3n/1W57SxgGOZCYxl+VDDabcf6LpNTf3g6IQ4XY7TbiyyUBmhqsViswWK02cE7ITIdmtxnWlcJz6f1tPyMsha+2R4UGyJPdywotwGSHOKHdm+IMYA40BRhtkXOb42DAh8crppjw8CyB4nMBlvFtD/0WSfZebkDHguLNar2JdyTXptqRrx6OmMKZkISQc4Yv9yyDXHiiEx1qXL1OAFdhBJPAAQeRQDEiRZEm+kwnu2p1XHo64yQ8j47bL1kCZ87pDKWxuW4mQJ9O9ba31xE5Y/rnA4VoTCJQwvnyBNgk+pkDi8sSJjlKRPxhX7r3Lytz0LPMi1H1Qv7VuzwuAzh4h1ukKFi/YV9+9E8THZbne2Ezxd/xsNGQ6u+wgoeH4SH9Tl367t+2Ko/acA8Oj/DhWP7X/30Zkvj4WMYlj10MOISXf7DlkPvvH6g43u0oCzDS1U5f/sHWC3d7cn3UAQf4HeHfwxXQY4yu/HTDKNXro3Gngw4vw2FnPKrXJfUXu0fqIdeFZOnXm08FTRSxcf391pW7oNGT8vRf6i9jqljwYzAm6AAAAABJRU5ErkJggg=="
|
||||
"base64": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURUdwTB3WXx3UXh3VXx7XYBkXFRpVLRyURmIaeAQAAAAEdFJOUwDDO3fSqUUkAAABbklEQVRIx61VbW6DMAztoAeYNA7ApB6gkzhAWS24wIAL0HABaK6/pHFNEhy8TXu/kPzkPD/8cTj8K7KPAqB+K5NhQPCUrABCXe7HOUYYZxgVRLiG8RfY4DUgFFtC7cffAfZTFBwBdhWEKfgEq4ocEjgj4ZQifO6/QG9kkETp1dDeVWfRKx3XYSW0LoqY5kCElXDrQkyeCCuh6WL0M4nIWQIyzqixdfKU1koFDKvyCA8NJMzU4xiD+b4kfHRpsIyKc6hBwjVptFHVY51EMAINNDFGJITKDNQcdpX74Hz0CQ3rY5qwMp4EIxrlafzrsYZ2Veb0DkRgfNCUok4Y1fqEijfyi2b8RE9beWqa48Y/uvCNMcH9btfUi+/CGLR1vhL6Zz9N/vBlaCU+7lwY/cmJ67Ryen/2tj23PLqJBodZH8vgj544vOL4pxfI5acrSFxi8hrkU9TSKr78ZpnL50A8KPJJEo+afBblwyqf5j/iGys5j6ScrST2AAAAAElFTkSuQmCC"
|
||||
}
|
||||
},
|
||||
// --- Spotify ---
|
||||
// {
|
||||
// "type": "appleScriptTitledButton",
|
||||
// "source": {
|
||||
// "inline":
|
||||
// "if application \"Spotify\" is running then\rtell application \"Spotify\"\rif player state is playing then\rreturn (get artist of current track) & \" – \" & (get name of current track)\relse\rreturn \"\"\rend if\rend tell\rend if\rreturn \"\"\r"
|
||||
// },
|
||||
// "action": "appleScript",
|
||||
// "actionAppleScript": {
|
||||
// "inline":
|
||||
// "if application \"Spotify\" is running then\rtell application \"Spotify\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
||||
// },
|
||||
// "refreshInterval": 1,
|
||||
// "image": {
|
||||
// "base64":
|
||||
// "iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURUdwTB3WXx3UXh3VXx7XYBkXFRpVLRyURmIaeAQAAAAEdFJOUwDDO3fSqUUkAAABbklEQVRIx61VbW6DMAztoAeYNA7ApB6gkzhAWS24wIAL0HABaK6/pHFNEhy8TXu/kPzkPD/8cTj8K7KPAqB+K5NhQPCUrABCXe7HOUYYZxgVRLiG8RfY4DUgFFtC7cffAfZTFBwBdhWEKfgEq4ocEjgj4ZQifO6/QG9kkETp1dDeVWfRKx3XYSW0LoqY5kCElXDrQkyeCCuh6WL0M4nIWQIyzqixdfKU1koFDKvyCA8NJMzU4xiD+b4kfHRpsIyKc6hBwjVptFHVY51EMAINNDFGJITKDNQcdpX74Hz0CQ3rY5qwMp4EIxrlafzrsYZ2Veb0DkRgfNCUok4Y1fqEijfyi2b8RE9beWqa48Y/uvCNMcH9btfUi+/CGLR1vhL6Zz9N/vBlaCU+7lwY/cmJ67Ryen/2tj23PLqJBodZH8vgj544vOL4pxfI5acrSFxi8hrkU9TSKr78ZpnL50A8KPJJEo+afBblwyqf5j/iGys5j6ScrST2AAAAAElFTkSuQmCC"
|
||||
// }
|
||||
// },
|
||||
// --- VOX ---
|
||||
// {
|
||||
// "type": "appleScriptTitledButton",
|
||||
// "source": {
|
||||
// "inline":
|
||||
// "if application \"VOX\" is running then\rtell application \"VOX\"\rif player state is 1 then\rreturn (get artist) & \" – \" & (get track)\relse\rreturn \"\"\rend if\rend tell\rend if\rreturn \"\"\r"
|
||||
// },
|
||||
// "action": "appleScript",
|
||||
// "actionAppleScript": {
|
||||
// "inline":
|
||||
// "if application \"VOX\" is running then\rtell application \"VOX\"\rif player state is 1 then\rnext\rend if\rend tell\rend if\r"
|
||||
// },
|
||||
// "refreshInterval": 1,
|
||||
// "image": {
|
||||
// "base64":
|
||||
// "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAADAUExURUdwTHd7gqeqtKClrd/k7n+Di7e7xI6TnNHX4cPI0Xp9hJibpOfs9u/1/vX7/rq/yZiborK3wEpOUxgYFlFXYiIhHycpLD9ESjI0NgsLCj09O4SKk19lcbBkALhoAHJ3gT8rAzMvJJugqKhcAL5xAOSxB4I/AJ5SAGpweXuAiZJJAG8zAeXr9WNiYM+NANqeAMd9APHACfr9/e7JPrO5w6mrsA4bKC0gCHhtTyAYBFcpAZduKK2JP/fost/Eb5SUlFFfi9AAAAASdFJOUwDJE9FgWjb+/vyHppTXtbn9mDupvZ0AAAdoSURBVFjDlZcLQ6O6FoWrtgI+Owl5EGgp2DrEgnV6wD4c7f//V3ftAE7nzOj17NGxpayPtXfSZGcw+CjOh1c3N9eIm5ur4fngv8Xp8KZE+F2U5bq8GZ5+WU5qP6jzsRdTeF7e1AEoN8Ovya/LMsg9mxZJErpIksJarwnK8nr4FblfQ52EDOH0zL1KUuvVfnn9eTVOryCPoVZQuGj/FOApMAhx9Uktzq/L2ksT3FuQhIVVVVRVRa+SogA1KbzgExPD0s/xdBOmKdOqODR95IdEaZba0LAkbfzyg0rA/pgekxZKV4cmtxXTEmFUEufNodIKYJjLkcbf9UEM90mqZJU3qeJRxDkXAv/hlbJNXkmVJjCBNP5CGPq1TZSyiWB5XomIi+woRBSJKj8YUVgFQ4E//FMfQM8s40VTyIhDpLVRNIJKaWLwSNqm4mEMl/YPwrkP/9AbER+UkxtWbbcvLrbbkBlCcDa23BABHn4bi1PSM2a1PFgZwbwJty+TybSLyeRlyxQlIuNY6FgpDKd/PB+uXP2tFHEheCtvhW3Q65dtiEyQRixMrBjG4uo4gTpNFApvU9Kr6sWp77qY3BFj8lLBBJdpykOLwaqPkgioAEnFi1RCz7Z3uJ2U37sgCBB3W5ZJLm0VJQmVIXgfgSAvQpYK1ACDx7bTOT2dlA8uWsYEl0EQ3KDUKcOECvqRCGgGpApXf9M/PNx3QQwyMZ9uGWZWiGelsFAHvQFUMEx4WAku2HZC+k6+vF/ip0U4wmSrBJcFZgss9xZuYYAlWhaGC1PhMb1++R6EaAl3lRFcFUI5C7duDlAFwpCzSogsfCH93fdWvm+jRYCASs5fwkyIinGsVrBAc2FYxwVLlKhgQG3n8+kv/WwjhNhsZvveQ5+EqrhKWOHVlMNtgyUkhHkpdPjy1CZA+pl4bkOIfWcBQ/EEC1xWWmKxsi6HussA9WUwQBV0BmbPz3y32+x2nD8/z/okpvM5LAjGeEg51JiFtQeAEqHhWUIGJq0B0m9mLjYdgSxMnQVhGHIIkcP5YNjEAGjJJDfF5AnzzRnY/9K3hP3SjSUAk0oLzaQOwyJGEb41FgWVuOIymHYZCKfPGFaxzBHEcQ5cYrXD3LHNt8E3WkdDbpBY8vMdMHsW0Jui9v26MCDAggNMAfgZoghGdIDbPMXewY0RWfHzqQMsN2QgC/MAkVcZWZi1DuYAJJlQBlVM0vx2cDZOw4QAPEt/AcTzDgkkh3w8Hh8SPZvtKIc2haefKapo2mE4G5x5nQOuLQA0jwggCcAqF1SFnZQEwEwCwGZ0P+sAXQqa69gBJvgeLCUBhMS6arSWogV0NWwB2gHG5KAggDYO0OXQATghJP4QIPsFiJHCEYB2YgBE5gBzNxEyjVHYcOxKKDfquRE6u39wFXh6dADJaccG4HLsANIIEb89PnaEvSYLG2kYAG0G+3YMnh4fDxbfe4wkAS47gAAyShsA2iSWUgsiYHfJMCF2ZKDVA9AkET4WbhgvB6OxxeoiuZZRVT/2BFjQfOemMX53qNn+e5fA42OtAOCYiYXNR4PznL4LJoLA1G8rQjjCTCmxc9+GzU4oNXvonr9avTUZPc7QdyHH0j4mgIqQVZQHq1VvAgRKf7MRKISZPWAG0ONXq1Vg6WYahMIbYz24pJ6ECYIyf7EiBBGm3/da0c6KX/ifTnv9P74iu66G3iUAI4+KoCNpeNS8rha9ifnkfmlcLO+n816+WL3mEVVcY2ew4xEtqsgBjUWEQkWsfFssWhdgPM0xoBg8iKl2JF8s3kpngCtMo3jsNljkUDAmYQFVWC9+tAgHeQ93AR/8WKw9d6MMWWFdBn0OJsJsjERZLn4QomOsWmmrpk9Kn0eYxpGiMfBG7dZ0FrcW8B2N1PoV9zkEUehn1b2hy68lxg/F0owVaXzW7Y0j6kwZuiqhUIaW8M54F9Olcq0irF0R1vAkfTdAFmwaKhjDUgfCur39n+NwF9ZrFhnMWm5YiM737L0/GHkxtYD4RKIWILz1+jf86/Vv69I4fSTRTNojAxgIdPUgCE7VjXhzhHAEJ1/nUUSl4qTHKeDyuMnCycCzjiCwyUYsWK9fofzhxIC8rtcBi2SlqPeEnu7/rekGwcutwhTHhKoYHlWvEa8u6FVN17D/Or3Ncfu/Wu5R7I2bmNECRiYYRpuaYtKiBa+0u0j9K7aguMFZZvTvVvUCFuoce5ygSmA9xlcRDR8iyzaZqVq50Coc1zBw8WezfBEfmqBGX+8QXLs1HY9tV3aMMeQSp4A6aP6qdx4aNHyMWnxBHbpwzTIW9vadkGTf/1BPdYhxsqrR7zuGoD4/6pp+iKVkaY3zWGxHHx55TuJxXZa1RSmwIyAyeoGVlf4wG9CBLD755Nx1ehHHub9e+3lBpxUh+0DuuO4ef/H5AXR0gkpg+EofjQed1ej8VsTuEk6T8cno/54cRyc2zms3Bcr+4Esvazz9C/IOYWlESNseoWtU3n5V3tYCDEA8tAce5j3enFyc/scT/Pno4qSLi9HHhf8f8eOIRf9lFswAAAAASUVORK5CYII="
|
||||
// }
|
||||
// },
|
||||
{ "type": "previous", "width": 44 },
|
||||
{ "type": "play", "width": 44 },
|
||||
{ "type": "next", "width": 44 },
|
||||
{ "type": "weather", "icon_type": "images", "units": "metric" },
|
||||
{ "type": "currency", "from": "BTC", "to": "USD" },
|
||||
{ "type": "sleep", "width": 44 },
|
||||
{ "type": "mute", "width": 40, "align": "right" },
|
||||
{ "type": "volumeDown", "width": 34, "align": "right" },
|
||||
{ "type": "volume", "width": 60, "align": "right" },
|
||||
{ "type": "volumeUp", "width": 34, "align": "right" },
|
||||
{ "type": "inputsource", "align": "right" },
|
||||
{ "type": "battery", "align": "right", "bordered": false },
|
||||
{ "type": "timeButton", "align": "right", "bordered": false }
|
||||
|
||||
// iTunes
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"inline": "if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rreturn (get artist of current track) & \" – \" & (get name of current track)\relse\rreturn \"\"\rend if\rend tell\rend if\rreturn \"\"\r"
|
||||
},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"inline": "if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
||||
},
|
||||
"longAction": "appleScript",
|
||||
"longActionAppleScript": {
|
||||
"inline": "if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rprev track\rend if\rend tell\rend if\r"
|
||||
},
|
||||
"refreshInterval": 2,
|
||||
"image": {
|
||||
"base64": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAADAUExURUdwTOVVZCzB+3qc0gkDBgEBAgcKEwAAAA4EBP5aVU2V95iJv7V3rtBOvH5W6jaOyclScKZGX3wuQCMuUqZN7+NQYXtDvFd9/sxYni2z6UhBhyhvnIp7sf38/PXz9ePm69/k6fHv8/j29+3q7/v6+ufq7uvu8fTw8+1egOFki/dbboVj/HNy/T+j/dNtnEul81vC8Vmf3OeRqOBVofK4xZfF7sDb7PLe6LxU1KKK79PL6vrW3fh4g5Zi4bi16daa0A3Qc90AAAAddFJOUwD3/v0uOlYNG/z+/v7998OYYztt/Le2/eDqi5jEo2rNTwAABMtJREFUWMPdl1tjqjoQhauC0Hqvta26JVxUQBQFRPBS/f//as8kISBqd/twXs5KjBDyrZkEFfP09D+WoigqFxz+mlbVXncweEZVBoNuD1x+E1vtMVZoURn01J/mob52KRNuj4k5mZjJcRueFotFpfv6EwdVRfy0tSdXSranheN0/zkRSB7x42Q6udExdBy3972Fog4o/kBg4X6bhPJaeX7eTqeT6b0MJtPpdOu6n49XQgX+dOQ8vpWEvYn/2AHiL052PpoROcsOtND17ztQ3rwTuCQz9O/moKiMf6BkG/puKBzurKQ64PmbU2bDzUxk3Uql4lZcl3Vpvt9VbxLoLZwjY7E1WcNZoB0XpbELie/3Sg6KVHG2jGPs1LTCE2UXFfgIgtBgyq8d/E/pehJq1zmZGc7kAPsMX4Ec932T25uX5vUklFcHJlDU1OT4wllkvOtn9lrSbF7dCUggNEtaMOXhQZq4WkpBcksJQBCOnyjvM4P8KqQgFW9BFJka2NMKB1gw+VMxvN9smnwI1EuzpxS+g9FWYySjsTpOtnq+H162iW01m/wyXLUPzT/5HKQoSjQmU8vE6TAElvWggbhuNRpScQa002bVtJmBCz9qNusWBkJmoyHmoHajC4yybVujhR26mJVha7lDo2FrhnA4N0aq+BpE24zjgsMoEsfU0AADaKCwemiIRZA+o6N9oygyMi/EAWk0DMNgFvCmN/5IwqCV3PCGzzIwbINrzgwykVq2iorUalm2UTZotXKWqVYz5uBjzDUoxrxWyzKQWy061LZsNIJ3PAMDIcbVauwdGmxrNblgYNnCgStN54ylBSsYoAxerwwgJsCWTS0sepym0Mdp1gYBw5lmwgDXIDEoaeHLYE36BafzuQWFQ9RASM/XQPpMD5YQ2gA/AwPArQJyZWDsgo64C+/pBRkDG4s31hdmwFNAGz1mBjPukBs8qdSgLDBA1LJm1lw/14IgWAdAQ5nhax4HY/FR7qfpHQMPUChzS0c6eFmv17MZo7HZBP3MQJHTNCnzxPMgOFUteAGtMwMmfRPIijBgc+AmNK6+9zw+9Iw05YsG8aaT/7Kro7eUcoSWw3n/1W57SxgGOZCYxl+VDDabcf6LpNTf3g6IQ4XY7TbiyyUBmhqsViswWK02cE7ITIdmtxnWlcJz6f1tPyMsha+2R4UGyJPdywotwGSHOKHdm+IMYA40BRhtkXOb42DAh8crppjw8CyB4nMBlvFtD/0WSfZebkDHguLNar2JdyTXptqRrx6OmMKZkISQc4Yv9yyDXHiiEx1qXL1OAFdhBJPAAQeRQDEiRZEm+kwnu2p1XHo64yQ8j47bL1kCZ87pDKWxuW4mQJ9O9ba31xE5Y/rnA4VoTCJQwvnyBNgk+pkDi8sSJjlKRPxhX7r3Lytz0LPMi1H1Qv7VuzwuAzh4h1ukKFi/YV9+9E8THZbne2Ezxd/xsNGQ6u+wgoeH4SH9Tl367t+2Ko/acA8Oj/DhWP7X/30Zkvj4WMYlj10MOISXf7DlkPvvH6g43u0oCzDS1U5f/sHWC3d7cn3UAQf4HeHfwxXQY4yu/HTDKNXro3Gngw4vw2FnPKrXJfUXu0fqIdeFZOnXm08FTRSxcf391pW7oNGT8vRf6i9jqljwYzAm6AAAAABJRU5ErkJggg=="
|
||||
}
|
||||
},
|
||||
{ "type": "displaySleep", "width": 40, "align": "right", "bordered": false },
|
||||
{
|
||||
"type": "weather",
|
||||
"align": "right",
|
||||
"icon_type": "images",
|
||||
"api_key": "ca93a0bb8cdb428552660d83249e4bc9",
|
||||
"bordered": false
|
||||
},
|
||||
{
|
||||
"type": "volumeDown",
|
||||
"bordered": false,
|
||||
"align": "right",
|
||||
"width": 28
|
||||
},
|
||||
{
|
||||
"type": "volumeUp",
|
||||
"bordered": false,
|
||||
"align": "right",
|
||||
"width": 28
|
||||
},
|
||||
{
|
||||
"type": "play",
|
||||
"align": "right",
|
||||
"width": 38
|
||||
},
|
||||
{
|
||||
"type": "battery",
|
||||
"align": "right",
|
||||
"bordered": false
|
||||
},
|
||||
{
|
||||
"type": "timeButton",
|
||||
"formatTemplate": "HH:mm",
|
||||
"align": "right",
|
||||
"bordered": false,
|
||||
"longAction": "shellScript",
|
||||
"longExecutablePath": "/usr/bin/pmset",
|
||||
"longShellArguments": ["sleepnow"]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -26,6 +26,33 @@ class AppleScriptDefinitionTests: XCTestCase {
|
||||
XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew")
|
||||
}
|
||||
|
||||
// This tests that users can pass paths to files with ~ in them
|
||||
func testUserPath() {
|
||||
let buttonNoActionFixture = """
|
||||
[ { "type": "appleScriptTitledButton", "source": { "filePath": "~/pew" } } ]
|
||||
""".data(using: .utf8)!
|
||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||
guard case .appleScriptTitledButton(let source, _)? = result?.first?.type else {
|
||||
XCTFail()
|
||||
return
|
||||
}
|
||||
let sourceStruct = source as? Source
|
||||
// gives you a string in the format of file:///Users/your_uer_name/pew
|
||||
let expandedPath = URL(fileURLWithPath: NSString("~/pew").expandingTildeInPath) as URL
|
||||
XCTAssertEqual(sourceStruct?.filePath?.fileURL, expandedPath)
|
||||
}
|
||||
|
||||
// This tests that users can pass paths to images with ~ in them
|
||||
func testUserImagePath() {
|
||||
let relativeImagePath = """
|
||||
[ { "filePath": "~/pew/image.png" } ]
|
||||
""".data(using: .utf8)!
|
||||
let result = try? JSONDecoder().decode([Source].self, from: relativeImagePath)
|
||||
// gives you a string in the format of file:///Users/your_uer_name/pew/image.png
|
||||
let expandedPath = URL(fileURLWithPath: NSString("~/pew/image.png").expandingTildeInPath) as URL
|
||||
XCTAssertEqual(result?.first?.filePath?.fileURL, expandedPath)
|
||||
}
|
||||
|
||||
func testRefreshInterval() {
|
||||
let buttonNoActionFixture = """
|
||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]
|
||||
|
||||
@@ -1,49 +1,64 @@
|
||||
<p align="center"><img src="Resources/logo.png" width="120"></p>
|
||||
# My touchbar. My rules. [](https://github.com/Toxblh/MTMR/releases) [](https://github.com/Toxblh/MTMR/blob/master/LICENSE)  
|
||||
|
||||
# My TouchBar. My rules
|
||||
<img src="Resources/logo.png" align="right"
|
||||
title="MTMR by Toxblh" width="110" height="110">
|
||||
|
||||
*The TouchBar Customization App for your MacBook Pro*
|
||||
_The TouchBar Customization App for your MacBook Pro_
|
||||
|
||||
[](https://github.com/Toxblh/MTMR/releases)
|
||||
[](https://github.com/Toxblh/MTMR/blob/master/LICENSE) [](https://github.com/Toxblh/MTMR/releases/latest)  
|
||||
My idea is to create a platform for creating plugins to customize the TouchBar. I very much like BTT and having a full custom TouchBar (my BTT preset), and I wanted to create it. It's my first Swift project for MacOS :)
|
||||
|
||||
**Share your presets [here](https://github.com/Toxblh/MTMR-presets)**
|
||||
|
||||
<p align="center">
|
||||
<img src="Resources/TouchBar-v0.8.1.png">
|
||||
<img src="./Resources/aaaaa-acc6-17fee7572ed0.png" alt="Mackbook with touchbar" width="800">
|
||||
</p>
|
||||
|
||||
**MTMR** Community:
|
||||
[<img height="24px" src="https://github.com/discourse/DiscourseMobile/raw/master/icon.png" /> Discourse](https://forum.mtmr.app)
|
||||
[<img height="24px" src="https://camo.githubusercontent.com/88f53948f291c54736bf08f5fd7b037a848dfc62/68747470733a2f2f646973636f72646170702e636f6d2f6173736574732f30376463613830613130326434313439653937333664346231363263666636662e69636f"> Discord](https://discord.gg/CmNcDuQ)
|
||||
[<img height="24px" src="https://telegram.org/img/t_logo.png" /> Telegram](https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g)
|
||||
<p align="center">
|
||||
<a href="https://discord.gg/CmNcDuQ"><img height="20px" src="https://camo.githubusercontent.com/88f53948f291c54736bf08f5fd7b037a848dfc62/68747470733a2f2f646973636f72646170702e636f6d2f6173736574732f30376463613830613130326434313439653937333664346231363263666636662e69636f"> Discord</a>
|
||||
<a href="https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g"><img height="20px" src="https://telegram.org/img/t_logo.png" /> Telegram</a>
|
||||
</p>
|
||||
|
||||
<a href="https://www.paypal.me/toxblh/10" title="Donate via Paypal"><img height="32px" 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="32px" ></a>
|
||||
<a href="https://www.patreon.com/bePatron?u=9900748"><img height="32px" 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>
|
||||
[<img src="https://d1qb2nb5cznatu.cloudfront.net/startups/i/854859-e299e139ab7f79855c0bc589f10b0ec6-medium_jpg.jpg?buster=1453074480" height="32px" /> Become a backer](https://opencollective.com/MTMR#backer)
|
||||
[<img src="https://d1qb2nb5cznatu.cloudfront.net/startups/i/854859-e299e139ab7f79855c0bc589f10b0ec6-medium_jpg.jpg?buster=1453074480" height="32px" /> Become a sponsor](https://opencollective.com/MTMR#sponsor)
|
||||
|
||||
|
||||
My idea is to create a platform for creating plugins to customize the TouchBar. I very much like BTT and having a full custom TouchBar (my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)), and I wanted to create it. It's my first Swift project for MacOS :)
|
||||
|
||||
#### Share your presets [here](https://github.com/Toxblh/MTMR-presets)
|
||||
<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>
|
||||
<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.producthunt.com/posts/my-touchbar-my-rules-mtmr">
|
||||
<img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=my-touchbar-my-rules-mtmr&theme=light" alt="My TouchBar My Rules (MTMR)" height="36px" style="max-width:100%">
|
||||
</a></p>
|
||||
|
||||
## Installation
|
||||
- Download lastest [release](https://github.com/Toxblh/MTMR/releases) from github
|
||||
|
||||
- Download lastest [release](https://github.com/Toxblh/MTMR/releases) (.dmg) from github
|
||||
- Or via Homebrew `brew cask install 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
|
||||
|
||||
## Troubleshooting
|
||||
Problems:
|
||||
- "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
|
||||
**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">
|
||||
<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">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
🍏→ System Preferences → Security and Privacy → tab Privacy → Accessibility → MTMR
|
||||
</p>
|
||||
|
||||
## Examples
|
||||
|
||||
[MTMR presets](https://github.com/Toxblh/MTMR-presets)
|
||||
|
||||
<p align="center">
|
||||
<img src="./Resources/Artboard.png" alt="Presets for touchbar" width="800">
|
||||
</p>
|
||||
|
||||
## Customization
|
||||
|
||||
MTMR preferences are stored under `~/Library/Application\ Support/MTMR/items.json`.
|
||||
|
||||
The pre-installed configuration contains less or more than you'll probably want, try to configure:
|
||||
|
||||
## Built-in button types:
|
||||
|
||||
> Buttons
|
||||
|
||||
- escape
|
||||
- exitTouchbar
|
||||
- brightnessUp
|
||||
@@ -55,27 +70,40 @@ Re-tick or check a tick for access 🍏→ System Preferences → Security and P
|
||||
- mute
|
||||
|
||||
> Native Plugins
|
||||
|
||||
- timeButton
|
||||
- battery
|
||||
- currency
|
||||
- weather
|
||||
- yandexWeather
|
||||
- inputsource
|
||||
- music (tap for pause, longTap for next)
|
||||
- dock (half-long click to open app, full-long click to kill app)
|
||||
- nightShift
|
||||
- dnd (Don't disturb)
|
||||
- darkMode
|
||||
- pomodoro
|
||||
- network
|
||||
|
||||
> Media Keys
|
||||
|
||||
- previous
|
||||
- play
|
||||
- next
|
||||
|
||||
> AppleScript plugins
|
||||
|
||||
- sleep
|
||||
- displaySleep
|
||||
|
||||
> Custom buttons
|
||||
|
||||
- staticButton
|
||||
- appleScriptTitledButton
|
||||
- shellScriptTitledButton
|
||||
|
||||
## Gestures on central part:
|
||||
|
||||
- two finger slide: change you Volume
|
||||
- three finger slide: change you Brightness
|
||||
|
||||
@@ -85,64 +113,110 @@ Re-tick or check a tick for access 🍏→ System Preferences → Security and P
|
||||
- volume
|
||||
|
||||
### You can also make custom buttons using these types
|
||||
- `staticButton`
|
||||
|
||||
#### `staticButton`
|
||||
|
||||
```json
|
||||
"type": "staticButton",
|
||||
"title": "esc",
|
||||
```
|
||||
|
||||
- `appleScriptTitledButton`
|
||||
#### `appleScriptTitledButton`
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"refreshInterval": 60, //optional
|
||||
"source": {
|
||||
"filePath": "/Users/toxblh/Library/Application Support/MTMR/iTunes.nowPlaying.scpt",
|
||||
"filePath": "~/Library/Application Support/MTMR/iTunes.nowPlaying.scpt",
|
||||
// or
|
||||
"inline": "tell application \"Finder\"\rmake new Finder window\rset target of front window to path to home folder as string\ractivate\rend tell",
|
||||
"inline": "tell application \"Finder\"\rif not (exists window 1) then\rmake new Finder window\rset target of front window to path to home folder as string\rend if\ractivate\rend tell",
|
||||
// or
|
||||
"base64": "StringInbase64"
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `timeButton`
|
||||
#### `shellScriptTitledButton`
|
||||
> Note: script may return also colors using escape sequences (read more here https://misc.flogisoft.com/bash/tip_colors_and_formatting)
|
||||
> Only "16 Colors" mode supported atm. If background color returned, button will pick it up as own background color.
|
||||
|
||||
Example of "CPU load" button which also changes color based on load value.
|
||||
```js
|
||||
"type": "timeButton",
|
||||
"formatTemplate": "HH:mm" //optional
|
||||
{
|
||||
"type": "shellScriptTitledButton",
|
||||
"width": 80,
|
||||
"refreshInterval": 2,
|
||||
"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}'"
|
||||
},
|
||||
"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",
|
||||
"image": {
|
||||
// Or you can specify a filePath here.
|
||||
// Images will be resized to 24x24.
|
||||
// "filePath": "~/myproject/myimage.jpg" // or "/fixed/path/to/the.png"
|
||||
"base64":
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA/1BMVEUAAADaACbYACfYACfjABzXACjYACfXACjYACfYACfYACfYACfdACLYACfXACjYACfVACv/AADXACjYACfYACfXACjYACfXACjaACXYACfYACfVACvYACfYACfZACbZACbYACfYACfZACb/AADYACfYACfVACrXACjVACu/AEDYACfYACfYACfXACjXACjYACfXACjYACfYACfYACfXACjYACfXACjYACfYACfZACbYACfYACfMADPYACfYACfYACfYACfYACfZACbXACjYACfYACfRAC7XACjYACfZACbWACnXACjXACjYACfTACzZACb/AADYACfYACfYACcAAAA+zneGAAAAU3RSTlMAItK+CVPjh3xUxPwPiGDQGAMtSKmN3Vk+wPQG/e26oIJBnwJCdiuAHgTmw+6BX+IgfaqLUvKOW8VKnagK+vBwYrhlc/urCznvhSyUbOEXPAFjGh/ektAAAAABYktHRACIBR1IAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4ggWETQWgEDcSgAAAqVJREFUWMPtl4ly2jAQhsUNNlcw5r4SICEHLSQhCQRyX73T/u//LpUlLIyxbMAznWmn/0ywo5U+27tr7ZoQuwLBUJidRKIxPhKLRtgxHAoGiLfiQIKdKFCTxjGpQmEDCSC+BiAFpNlJBsgaxyyQYQNpIPUf8AcAOzktD+iaoQJQNI5FoMAGdCCv5XZclpfKFXiqUi5Jllf1mvdyQzW96gigd4h6o+mhRp1O0x3vvwa1VSWeqrZU1Jyeogy01ggSVQsoO/i/gjq9/u6u+2LDXq2jshqLHNCgdsCVwO0NILdi0oDmuoAmoImhQDzFRPNnb36L7U43NVfc2EH2D9h5t9OePyIF5IU9uIhvkyN7iiXmQUIOj8x/lB6f0bTaQ3ZA+9iaNCH2Lpg6btsBIRJOpJl0E9ABTvof5kqEGeCjMaN/AnRMgM5XJcI2J1J1gf6S48Tb2Ae6JkAjdgmAeJ1XAOJ1Xg8wGJ6elXwAzkeGjy62BgxG3MuXnoCIkmEq8EQyAUPgajyhPxJAga9SIiRqzwMOuAbGZDrDjQRgKkpiqiPgFphM74B7d4BKy2cyy1RcBvSodUb/HiSAIl+VlEfh8cm4wvPL9nnw+gbc+kkkUVioO95etwe8PBuP8vQoBzg7UQAe5t7syZwoCaMA3AN30wlzh3MYJYkkADeYTckYuJYlkiSVBeCKZtSY/gxlqezlxEt+pdFg6zBesPXn1ih8Aj5vkAels9PhYCkPsl++kg0AQu4dyuqmugIQm+qS5Nv6N+D7wm7d1skPc4xu666Fhd6BxU6r+jub8tNaWNxK29EhsdpR/sVn7FlLm0txPdgni+JrFNd3p+K67MQtyrsp3w2G7xbHd5Plv83z3Wj6b3V9N9ssFv7afaa//ZPn3wD4/vje8PP/N7TebS0hgZhEAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTA4LTIyVDE3OjUyOjIyKzAyOjAwc2qUYAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0wOC0yMlQxNzo1MjoyMiswMjowMAI3LNwAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC"
|
||||
},
|
||||
"bordered": false
|
||||
}
|
||||
```
|
||||
|
||||
## Groups
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "group",
|
||||
"align": "center",
|
||||
"bordered": true,
|
||||
"title": "stats",
|
||||
"items": [
|
||||
{ "type": "play" }, { "type": "mute" }, ...]
|
||||
"type": "group",
|
||||
"align": "center",
|
||||
"bordered": true,
|
||||
"title": "stats",
|
||||
"items": [
|
||||
{ "type": "play" },
|
||||
{ "type": "mute" },
|
||||
...
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
To close a group, use the button:
|
||||
|
||||
```
|
||||
{
|
||||
"type": "close",
|
||||
"width": 64
|
||||
"type": "close",
|
||||
"width": 64
|
||||
},
|
||||
```
|
||||
|
||||
## Native plugins
|
||||
|
||||
#### `timeButton`
|
||||
|
||||
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
||||
|
||||
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
|
||||
|
||||
> locale examples: https://gist.github.com/jacobbubu/1836273
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "timeButton",
|
||||
"formatTemplate": "dd HH:mm",
|
||||
"locale": "en_GB",
|
||||
"timeZone": "UTC"
|
||||
}
|
||||
```
|
||||
|
||||
#### `weather`
|
||||
> Provider: https://openweathermap.org Need allowance location service
|
||||
|
||||
> Provider: https://openweathermap.org \
|
||||
> Note: you need to register on 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: you need to allow using "Location Services" in your Mac OS "Security & Privacy" settings for MTMR
|
||||
|
||||
```js
|
||||
"type": "weather",
|
||||
"refreshInterval": 600, // in seconds
|
||||
@@ -151,8 +225,20 @@ To close a group, use the button:
|
||||
"api_key": "" // you can get the key on openweather
|
||||
```
|
||||
|
||||
#### `yandexWeather` (experimental)
|
||||
|
||||
> 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
|
||||
|
||||
```js
|
||||
"type": "yandexWeather",
|
||||
"refreshInterval": 600 // in seconds
|
||||
```
|
||||
|
||||
#### `currency`
|
||||
|
||||
> Provider: https://coinbase.com
|
||||
|
||||
```js
|
||||
"type": "currency",
|
||||
"refreshInterval": 600, // in seconds
|
||||
@@ -163,58 +249,82 @@ To close a group, use the button:
|
||||
```
|
||||
|
||||
#### `music`
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "music",
|
||||
"align": "center",
|
||||
"width": 80,
|
||||
"bordered": false,
|
||||
"refreshInterval": 2, // in seconds
|
||||
"width": 80, // Optional
|
||||
"bordered": false, // Optional
|
||||
"refreshInterval": 2, // in seconds. Optional. Default 5 seconds
|
||||
"disableMarquee": true // to disable marquee effect. Optional. Default false
|
||||
},
|
||||
```
|
||||
|
||||
#### `pomodoro`
|
||||
|
||||
> Pomodoro plugin. One click to start the work timer, longclick to start the rest timer. Click in progress for reset.
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "pomodoro",
|
||||
"workTime": 1200, // set time work in seconds. Default 1500 (25 min)
|
||||
"restTime": 600, // set time rest in seconds. Default 300 (5 min)
|
||||
"restTime": 600 // set time rest in seconds. Default 300 (5 min)
|
||||
},
|
||||
```
|
||||
|
||||
#### `network`
|
||||
|
||||
> Network plugin. The plugin to show usage a network
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "network",
|
||||
"flip": true
|
||||
},
|
||||
```
|
||||
|
||||
#### `dock`
|
||||
|
||||
> Dock plugin
|
||||
|
||||
```js
|
||||
{
|
||||
"type": "dock",
|
||||
"filter": "(^Xcode$)|(Safari)|(.*player)",
|
||||
"autoResize": true
|
||||
},
|
||||
```
|
||||
|
||||
## Actions:
|
||||
|
||||
- `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
|
||||
|
||||
```json
|
||||
"action": "hidKey",
|
||||
"keycode": 53,
|
||||
```
|
||||
|
||||
- `keyPress`
|
||||
|
||||
```json
|
||||
"action": "keyPress",
|
||||
"keycode": 1,
|
||||
```
|
||||
|
||||
- `appleScript`
|
||||
|
||||
```js
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"inline": "tell application \"Finder\"\rmake new Finder window\rset target of front window to path to home folder as string\ractivate\rend tell"
|
||||
"inline": "tell application \"Finder\"\rif not (exists window 1) then\rmake new Finder window\rset target of front window to path to home folder as string\rend if\ractivate\rend tell",
|
||||
// "filePath" or "base64" will work as well
|
||||
},
|
||||
```
|
||||
|
||||
- `shellScript`
|
||||
|
||||
```js
|
||||
"action": "shellScript",
|
||||
"executablePath": "/usr/bin/pmset",
|
||||
@@ -223,13 +333,16 @@ To close a group, use the button:
|
||||
```
|
||||
|
||||
- `openUrl`
|
||||
|
||||
```js
|
||||
"action": "openUrl",
|
||||
"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,
|
||||
@@ -245,79 +358,25 @@ If you want to longPress for some operations, it is similar to the configuration
|
||||
## Additional parameters:
|
||||
|
||||
- `width` restrict how much room a particular button will take
|
||||
|
||||
```json
|
||||
"width": 34
|
||||
```
|
||||
|
||||
- `align` can stick the item to the side. default is center
|
||||
|
||||
```js
|
||||
"align": "left" // "left", "right" or "center"
|
||||
```
|
||||
|
||||
- `bordered` you can do button without border
|
||||
|
||||
```js
|
||||
"bordered": "false" // "true" or "false"
|
||||
```
|
||||
|
||||
## Example configuration:
|
||||
```json
|
||||
[
|
||||
{ "type": "escape", "width": 110 },
|
||||
{ "type": "exitTouchbar", "align": "left" },
|
||||
{
|
||||
"type": "brightnessUp",
|
||||
"align": "left",
|
||||
"width": 36
|
||||
},
|
||||
{
|
||||
"type": "staticButton",
|
||||
"align": "left",
|
||||
"title": "🔆",
|
||||
"action": "keyPress",
|
||||
"keycode": 113,
|
||||
"width": 36
|
||||
},
|
||||
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"filePath": "/Users/toxblh/Library/Application Support/MTMR/iTunes.nowPlaying.scpt"
|
||||
},
|
||||
"refreshInterval": 1
|
||||
},
|
||||
{
|
||||
"type": "staticButton",
|
||||
"align": "left",
|
||||
"image": { "base64" : "%base64Finder%"},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"inline": "tell application \"Finder\"\rmake new Finder window\rset target of front window to path to home folder as string\ractivate\rend tell"
|
||||
},
|
||||
"width": 36
|
||||
},
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"inline": "if application \"Safari\" is running then\r\ttell application \"Safari\"\r\t\trepeat with t in tabs of windows\r\t\t\ttell t\r\t\t\t\tif URL starts with \"https:\/\/music.yandex.ru\" and name does not end with \"на Яндекс.Музыке\" then\r\t\t\t\t\treturn name of t as text\r\t\t\t\tend if\r\t\t\tend tell\r\t\tend repeat\r\tend tell\rend if\rreturn \"\""
|
||||
},
|
||||
"refreshInterval": 1
|
||||
},
|
||||
{ "type": "previous", "width": 36, "align": "right" },
|
||||
{ "type": "play", "width": 36, "align": "right" },
|
||||
{ "type": "next", "width": 36, "align": "right" },
|
||||
{ "type": "sleep", "width": 36 , "align": "right"},
|
||||
{ "type": "displaySleep", "align": "right" },
|
||||
{ "type": "weather", "refreshInterval": 1800, "width": 70, "align": "right" },
|
||||
{ "type": "volumeDown", "width": 36 , "align": "right"},
|
||||
{ "type": "volumeUp", "width": 36 , "align": "right"},
|
||||
{ "type": "battery", "refreshInterval": 60 , "align": "right"},
|
||||
{ "type": "appleScriptTitledButton", "refreshInterval": 1800, "source": { "filePath": "/Users/redetection/Library/Application Support/MTMR/Weather.scpt"} , "align": "right"},
|
||||
{ "type": "timeButton", "formatTemplate": "HH:mm", "width": 64, "align": "right" }
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
### Roadmap
|
||||
|
||||
- [x] Create the first prototype with TouchBar in Storyboard
|
||||
- [x] Put in stripe menu on startup the application
|
||||
- [x] Find how to simulate real buttons like brightness, volume, night shift and etc.
|
||||
@@ -339,6 +398,7 @@ If you want to longPress for some operations, it is similar to the configuration
|
||||
- [ ] Import config from BTT
|
||||
|
||||
Settings:
|
||||
|
||||
- [ ] Interface for plugins and export like presets
|
||||
- [x] Startup at login
|
||||
- [ ] Show on/off in Dock
|
||||
@@ -346,20 +406,8 @@ Settings:
|
||||
- [ ] On/off Haptic Feedback
|
||||
|
||||
Maybe:
|
||||
- [ ] Refactoring the application on packages (AppleScript, JavaScript? and Swift?)
|
||||
|
||||
### Author's presets
|
||||
[@Toxblh preset](Resources/toxblh.json)
|
||||
|
||||
[@ReDetection preset](Resources/ReDetection.json)
|
||||
|
||||
### User's presets
|
||||
[@luongvo209 preset](Resources/luongvo209.json)
|
||||

|
||||
|
||||
[aadi_vs_anand preset](Resources/aadi_vs_anand.json)
|
||||

|
||||

|
||||
- [ ] Refactoring the application into packages (AppleScript, JavaScript? and Swift?)
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 259 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 257 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 583 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
+10
-10
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"type": "exitTouchbar",
|
||||
"image": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/Resources/logo.png"
|
||||
"filePath": "~/git/selfProjects/MTMR/Resources/logo.png"
|
||||
},
|
||||
"width": 36, "align": "left" },
|
||||
{ "type": "brightnessDown", "width": 36, "align": "left" },
|
||||
@@ -12,46 +12,46 @@
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"filePath":
|
||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.nowPlaying.scpt"
|
||||
"~/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.nowPlaying.scpt"
|
||||
},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.next.scpt"
|
||||
"filePath": "~/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.next.scpt"
|
||||
},
|
||||
"refreshInterval": 1,
|
||||
"image": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/iTunes.png"
|
||||
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/iTunes.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"filePath":
|
||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.nowPlaying.scpt"
|
||||
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.nowPlaying.scpt"
|
||||
},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"filePath":
|
||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.next.scpt"
|
||||
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.next.scpt"
|
||||
},
|
||||
"refreshInterval": 1,
|
||||
"image": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/Spotify.png"
|
||||
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/Spotify.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "appleScriptTitledButton",
|
||||
"source": {
|
||||
"filePath":
|
||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.nowPlaying.scpt"
|
||||
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.nowPlaying.scpt"
|
||||
},
|
||||
"action": "appleScript",
|
||||
"actionAppleScript": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.next.scpt"
|
||||
"filePath": "~/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.next.scpt"
|
||||
},
|
||||
"refreshInterval": 1,
|
||||
"image": {
|
||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/Vox.png"
|
||||
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/Vox.png"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user