Compare commits
265 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd99e9d73d | ||
|
|
58beb5a213 | ||
|
|
7da9ca2c68 | ||
|
|
88a4ce82db | ||
|
|
d39b4c0c31 | ||
|
|
5e609c2446 | ||
|
|
14301c4dbd | ||
|
|
a879498e4c | ||
|
|
36bf749a46 | ||
|
|
ac0e44db4d | ||
|
|
26ad83be70 | ||
|
|
d199bbd852 | ||
|
|
352bf4887c | ||
|
|
211ca4be32 | ||
|
|
d270a7bbcd | ||
|
|
44732e8ad6 | ||
|
|
8c57342070 | ||
|
|
3add660d72 | ||
|
|
eb617ff31b | ||
| 3e82676008 | |||
| a2ad47c7ba | |||
| bbe901a572 | |||
| 54eaa3fd9f | |||
|
|
6660bb2d8f | ||
|
|
7a1800252c | ||
|
|
588e6ae09b | ||
|
|
87141e381b | ||
|
|
14282b86a9 | ||
|
|
810cdeed36 | ||
|
|
a65613acaf | ||
|
|
aa69d5f592 | ||
|
|
2f00c9ffb3 | ||
|
|
1def53878d | ||
| 3e5fa14494 | |||
|
|
2e2f556daf | ||
| 1e1ae2af61 | |||
| bc11728c2e | |||
| 445584bb1b | |||
| b6721f0274 | |||
| 75df82a567 | |||
| a1f64028cc | |||
| 3fc75ca8f0 | |||
| 6d266394a4 | |||
|
|
52758f947d | ||
|
|
502f989417 | ||
|
|
f61550e510 | ||
|
|
a0fc0b33c5 | ||
|
|
42ce95b72e | ||
|
|
642f0807bb | ||
|
|
dbb2f16222 | ||
|
|
3864591777 | ||
|
|
7e0db70fab | ||
|
|
40c684f528 | ||
|
|
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 | |||
| 744ea067db | |||
| 8064ab759c | |||
| 556c28df85 | |||
|
|
e68f930efa | ||
|
|
647ac0ba20 | ||
|
|
780a8ba81e | ||
|
|
71f5030fa6 | ||
|
|
f435c0b530 | ||
| e278482807 | |||
| 51d246bf7f | |||
| c1cd402241 | |||
| c496156cf2 | |||
|
|
154ea09e98 | ||
|
|
3b493fd5be | ||
| b718b1c9dd | |||
| acc248a579 | |||
| 59581ffdc8 | |||
| 238b15b6a4 | |||
| 732fd5c5b5 | |||
| f4b8e1f39a | |||
|
|
e988951ff9 | ||
| 807290ff0c | |||
| 0775ea0412 | |||
| 1d1d666986 | |||
| 560d8ed508 | |||
|
|
06d6f06adf | ||
| 0fafe3912e | |||
|
|
319241d4d4 | ||
|
|
61d5e8f77e | ||
|
|
e62530d7ab | ||
|
|
43675027d5 | ||
|
|
b70c040111 | ||
| e795f77ba1 | |||
| 37b0462bc1 | |||
|
|
d2d33dee3b | ||
|
|
c0fc40b1c9 | ||
|
|
47a2027443 | ||
|
|
b3c1d6b323 | ||
|
|
a15cc6506f | ||
| 35a6ceae07 | |||
| be1c439867 | |||
| 9f84b38084 | |||
| 86954a7981 | |||
| 8554dfeb5e | |||
| bd2cd6d0b7 | |||
|
|
06ecdfe016 | ||
|
|
85d54e4f53 | ||
| b368a21f62 | |||
| 644b15ffcd | |||
| b0b10074f8 | |||
| 2023ab29f3 | |||
| 9a265887cf | |||
| 62e87c53f5 | |||
| dbab502d14 | |||
| ae79e8b90e | |||
| d7eddb8484 | |||
| 457fa9481e | |||
| 69e8e6eefd |
6
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
issuehunt: Toxblh
|
||||||
|
patreon: toxblh
|
||||||
|
ko_fi: toxblh
|
||||||
|
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WUAAG2HH58WE4
|
||||||
22
.github/workflows/build-test.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
name: Build-and-test
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
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]}
|
||||||
41
.github/workflows/publish.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
name: Publish unsign version
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build-and-release:
|
||||||
|
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]}
|
||||||
|
|
||||||
|
- name: Create DMG
|
||||||
|
run: |
|
||||||
|
cd Release
|
||||||
|
create-dmg MTMR.app || true
|
||||||
|
|
||||||
|
- name: GitHub Release
|
||||||
|
uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
|
with:
|
||||||
|
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
prerelease: false
|
||||||
|
files: Release/MTMR*.dmg
|
||||||
2
.gitignore
vendored
@ -69,3 +69,5 @@ fastlane/report.xml
|
|||||||
fastlane/Preview.html
|
fastlane/Preview.html
|
||||||
fastlane/screenshots
|
fastlane/screenshots
|
||||||
fastlane/test_output
|
fastlane/test_output
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
language: swift
|
|
||||||
xcode_project: MTMR.xcodeproj
|
|
||||||
xcode_scheme: UnitTests
|
|
||||||
osx_image: xcode9.3
|
|
||||||
install: gem install xcpretty
|
|
||||||
script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}"
|
|
||||||
@ -18,6 +18,14 @@
|
|||||||
36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */; };
|
36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */; };
|
||||||
36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */; };
|
36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */; };
|
||||||
36C2ECE0207CB1B0003CDA33 /* defaultPreset.json in Resources */ = {isa = PBXBuildFile; fileRef = 36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */; };
|
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 */; };
|
||||||
|
4CF222EB26CC00470025BDA7 /* CPUBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */; };
|
||||||
|
4CF222ED26CC43D50025BDA7 /* CPU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CF222EC26CC43D40025BDA7 /* CPU.swift */; };
|
||||||
|
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */; };
|
||||||
|
5DC6CA02241F92CB005CD5E8 /* Music.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */; };
|
||||||
|
5DC6CA03241F92CB005CD5E8 /* Music.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = 5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */; };
|
||||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60173D3D20C0031B002C305F /* LaunchAtLoginController.m */; };
|
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60173D3D20C0031B002C305F /* LaunchAtLoginController.m */; };
|
||||||
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */; };
|
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */; };
|
||||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */; };
|
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */; };
|
||||||
@ -29,17 +37,24 @@
|
|||||||
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */; };
|
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */; };
|
||||||
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */; };
|
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */; };
|
||||||
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0008E542080286C003AD4DD /* SupportHelpers.swift */; };
|
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0008E542080286C003AD4DD /* SupportHelpers.swift */; };
|
||||||
|
B002E642216C0E38002774BA /* CoreDisplay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B002E641216C0E38002774BA /* CoreDisplay.framework */; };
|
||||||
|
B00D181D2152F4A5000806F4 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B00D181C2152F4A5000806F4 /* Sparkle.framework */; };
|
||||||
|
B00D181F2152F521000806F4 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B00D181C2152F4A5000806F4 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
B04B7BB72087398C00C835D0 /* BatteryBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */; };
|
B04B7BB72087398C00C835D0 /* BatteryBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */; };
|
||||||
B05600D32083E9BB00EB218D /* CustomSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B05600D22083E9BB00EB218D /* CustomSlider.swift */; };
|
B05600D32083E9BB00EB218D /* CustomSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B05600D22083E9BB00EB218D /* CustomSlider.swift */; };
|
||||||
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D621205E03F5006E6B86 /* TouchBarController.swift */; };
|
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D621205E03F5006E6B86 /* TouchBarController.swift */; };
|
||||||
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */; };
|
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */; };
|
||||||
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B059D62C205F11E8006E6B86 /* DFRFoundation.framework */; };
|
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B059D62C205F11E8006E6B86 /* DFRFoundation.framework */; };
|
||||||
|
B0679BC1215AE73F000FC6B4 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = B0679BC0215AE73F000FC6B4 /* dsa_pub.pem */; };
|
||||||
|
B08126EF217BD0B900A98970 /* PomodoroBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08126EE217BD0B900A98970 /* PomodoroBarItem.swift */; };
|
||||||
|
B08126F1217BE19000A98970 /* WidgetProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08126F0217BE19000A98970 /* WidgetProtocol.swift */; };
|
||||||
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08173262135F02B005D4908 /* NightShiftBarItem.swift */; };
|
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08173262135F02B005D4908 /* NightShiftBarItem.swift */; };
|
||||||
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B08173292135F354005D4908 /* CoreBrightness.framework */; };
|
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B08173292135F354005D4908 /* CoreBrightness.framework */; };
|
||||||
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B081732B213739FE005D4908 /* DnDBarItem.swift */; };
|
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B081732B213739FE005D4908 /* DnDBarItem.swift */; };
|
||||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B252205C7D8000BC04DC /* AppDelegate.swift */; };
|
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B252205C7D8000BC04DC /* AppDelegate.swift */; };
|
||||||
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B082B256205C7D8000BC04DC /* Assets.xcassets */; };
|
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B082B256205C7D8000BC04DC /* Assets.xcassets */; };
|
||||||
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B082B258205C7D8000BC04DC /* Main.storyboard */; };
|
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B082B258205C7D8000BC04DC /* Main.storyboard */; };
|
||||||
|
B0846A752220C968000288A7 /* NetworkBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0846A742220C968000288A7 /* NetworkBarItem.swift */; };
|
||||||
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */; };
|
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */; };
|
||||||
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */; };
|
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */; };
|
||||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
||||||
@ -54,9 +69,26 @@
|
|||||||
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */; };
|
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 */; };
|
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */; };
|
||||||
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */; };
|
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 */; };
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||||
|
BAF5AB5724317B4300B04904 /* BasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5624317B4300B04904 /* BasicView.swift */; };
|
||||||
|
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAF5AB5824317CAF00B04904 /* SwipeItem.swift */; };
|
||||||
|
F29F6A2524BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
B00D181E2152F507000806F4 /* CopyFiles */ = {
|
||||||
|
isa = PBXCopyFilesBuildPhase;
|
||||||
|
buildActionMask = 12;
|
||||||
|
dstPath = "";
|
||||||
|
dstSubfolderSpec = 10;
|
||||||
|
files = (
|
||||||
|
B00D181F2152F521000806F4 /* Sparkle.framework in CopyFiles */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
36300E85209FD16700B31C71 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = SOURCE_ROOT; };
|
36300E85209FD16700B31C71 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = SOURCE_ROOT; };
|
||||||
36300E8E20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScriptDefinitionTests.swift; sourceTree = "<group>"; };
|
36300E8E20A2CF3400B31C71 /* AppleScriptDefinitionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScriptDefinitionTests.swift; sourceTree = "<group>"; };
|
||||||
@ -70,6 +102,15 @@
|
|||||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsParsing.swift; sourceTree = "<group>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
||||||
|
4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPUBarItem.swift; sourceTree = "<group>"; };
|
||||||
|
4CF222EC26CC43D40025BDA7 /* CPU.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CPU.swift; sourceTree = "<group>"; };
|
||||||
|
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YandexWeatherBarItem.swift; sourceTree = "<group>"; };
|
||||||
|
5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.nowPlaying.scpt; sourceTree = "<group>"; };
|
||||||
|
5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Music.next.scpt; sourceTree = "<group>"; };
|
||||||
60173D3C20C0031B002C305F /* LaunchAtLoginController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; 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>"; };
|
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>"; };
|
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrightnessViewController.swift; sourceTree = "<group>"; };
|
||||||
@ -83,6 +124,8 @@
|
|||||||
60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicBarItem.swift; sourceTree = "<group>"; };
|
60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicBarItem.swift; sourceTree = "<group>"; };
|
||||||
60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceBarItem.swift; sourceTree = "<group>"; };
|
60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputSourceBarItem.swift; sourceTree = "<group>"; };
|
||||||
B0008E542080286C003AD4DD /* SupportHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportHelpers.swift; sourceTree = "<group>"; };
|
B0008E542080286C003AD4DD /* SupportHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportHelpers.swift; sourceTree = "<group>"; };
|
||||||
|
B002E641216C0E38002774BA /* CoreDisplay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreDisplay.framework; path = ../../../../../System/Library/Frameworks/CoreDisplay.framework; sourceTree = "<group>"; };
|
||||||
|
B00D181C2152F4A5000806F4 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Sparkle.framework; sourceTree = "<group>"; };
|
||||||
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryBarItem.swift; sourceTree = "<group>"; };
|
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryBarItem.swift; sourceTree = "<group>"; };
|
||||||
B05600D22083E9BB00EB218D /* CustomSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSlider.swift; sourceTree = "<group>"; };
|
B05600D22083E9BB00EB218D /* CustomSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSlider.swift; sourceTree = "<group>"; };
|
||||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarController.swift; sourceTree = "<group>"; };
|
B059D621205E03F5006E6B86 /* TouchBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarController.swift; sourceTree = "<group>"; };
|
||||||
@ -90,6 +133,9 @@
|
|||||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarPrivateApi.h; sourceTree = "<group>"; };
|
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarPrivateApi.h; sourceTree = "<group>"; };
|
||||||
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TouchBarPrivateApi-Bridging.h"; sourceTree = "<group>"; };
|
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TouchBarPrivateApi-Bridging.h"; sourceTree = "<group>"; };
|
||||||
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
|
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
|
||||||
|
B0679BC0215AE73F000FC6B4 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
|
||||||
|
B08126EE217BD0B900A98970 /* PomodoroBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PomodoroBarItem.swift; sourceTree = "<group>"; };
|
||||||
|
B08126F0217BE19000A98970 /* WidgetProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetProtocol.swift; sourceTree = "<group>"; };
|
||||||
B08173262135F02B005D4908 /* NightShiftBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightShiftBarItem.swift; sourceTree = "<group>"; };
|
B08173262135F02B005D4908 /* NightShiftBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightShiftBarItem.swift; sourceTree = "<group>"; };
|
||||||
B08173282135F128005D4908 /* CBBlueLightClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBBlueLightClient.h; sourceTree = "<group>"; };
|
B08173282135F128005D4908 /* CBBlueLightClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBBlueLightClient.h; sourceTree = "<group>"; };
|
||||||
B08173292135F354005D4908 /* CoreBrightness.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBrightness.framework; path = ../../../../../System/Library/PrivateFrameworks/CoreBrightness.framework; sourceTree = "<group>"; };
|
B08173292135F354005D4908 /* CoreBrightness.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBrightness.framework; path = ../../../../../System/Library/PrivateFrameworks/CoreBrightness.framework; sourceTree = "<group>"; };
|
||||||
@ -102,6 +148,7 @@
|
|||||||
B082B25C205C7D8000BC04DC /* MTMR.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MTMR.entitlements; sourceTree = "<group>"; };
|
B082B25C205C7D8000BC04DC /* MTMR.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MTMR.entitlements; sourceTree = "<group>"; };
|
||||||
B082B261205C7D8000BC04DC /* MTMRTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MTMRTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
B082B261205C7D8000BC04DC /* MTMRTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MTMRTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
B082B267205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
B082B267205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
|
B0846A742220C968000288A7 /* NetworkBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkBarItem.swift; sourceTree = "<group>"; };
|
||||||
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticFeedback.swift; sourceTree = "<group>"; };
|
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HapticFeedback.swift; sourceTree = "<group>"; };
|
||||||
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MultitouchSupport.framework; path = ../../../../../System/Library/PrivateFrameworks/MultitouchSupport.framework; sourceTree = "<group>"; };
|
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MultitouchSupport.framework; path = ../../../../../System/Library/PrivateFrameworks/MultitouchSupport.framework; sourceTree = "<group>"; };
|
||||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
||||||
@ -116,8 +163,12 @@
|
|||||||
B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.nowPlaying.scpt; sourceTree = "<group>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||||
|
BAF5AB5624317B4300B04904 /* BasicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicView.swift; sourceTree = "<group>"; };
|
||||||
|
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeItem.swift; sourceTree = "<group>"; };
|
||||||
|
F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpNextScrubberTouchBarItem.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -125,9 +176,11 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
B002E642216C0E38002774BA /* CoreDisplay.framework in Frameworks */,
|
||||||
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */,
|
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */,
|
||||||
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */,
|
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */,
|
||||||
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */,
|
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */,
|
||||||
|
B00D181D2152F4A5000806F4 /* Sparkle.framework in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -144,6 +197,8 @@
|
|||||||
B059D62B205F11E8006E6B86 /* Frameworks */ = {
|
B059D62B205F11E8006E6B86 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
B002E641216C0E38002774BA /* CoreDisplay.framework */,
|
||||||
|
B00D181C2152F4A5000806F4 /* Sparkle.framework */,
|
||||||
B08173292135F354005D4908 /* CoreBrightness.framework */,
|
B08173292135F354005D4908 /* CoreBrightness.framework */,
|
||||||
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */,
|
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */,
|
||||||
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */,
|
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */,
|
||||||
@ -181,13 +236,19 @@
|
|||||||
B082B256205C7D8000BC04DC /* Assets.xcassets */,
|
B082B256205C7D8000BC04DC /* Assets.xcassets */,
|
||||||
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
||||||
B082B25B205C7D8000BC04DC /* Info.plist */,
|
B082B25B205C7D8000BC04DC /* Info.plist */,
|
||||||
|
B0679BC0215AE73F000FC6B4 /* dsa_pub.pem */,
|
||||||
B082B25C205C7D8000BC04DC /* MTMR.entitlements */,
|
B082B25C205C7D8000BC04DC /* MTMR.entitlements */,
|
||||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */,
|
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */,
|
||||||
B082B252205C7D8000BC04DC /* AppDelegate.swift */,
|
B082B252205C7D8000BC04DC /* AppDelegate.swift */,
|
||||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||||
|
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */,
|
||||||
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
||||||
|
4CF222EC26CC43D40025BDA7 /* CPU.swift */,
|
||||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||||
|
BAF5AB5824317CAF00B04904 /* SwipeItem.swift */,
|
||||||
|
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */,
|
||||||
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
B059D621205E03F5006E6B86 /* TouchBarController.swift */,
|
||||||
|
BAF5AB5624317B4300B04904 /* BasicView.swift */,
|
||||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */,
|
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */,
|
||||||
B0008E542080286C003AD4DD /* SupportHelpers.swift */,
|
B0008E542080286C003AD4DD /* SupportHelpers.swift */,
|
||||||
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */,
|
B09EB1E3207C082000D5C1E0 /* HapticFeedback.swift */,
|
||||||
@ -214,6 +275,8 @@
|
|||||||
B0B17426207D6AFE0004B740 /* AppleScripts */ = {
|
B0B17426207D6AFE0004B740 /* AppleScripts */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
5DC6CA01241F92CB005CD5E8 /* Music.next.scpt */,
|
||||||
|
5DC6CA00241F92CB005CD5E8 /* Music.nowPlaying.scpt */,
|
||||||
B0B1742A207D6B580004B740 /* Battery.scpt */,
|
B0B1742A207D6B580004B740 /* Battery.scpt */,
|
||||||
B0B17429207D6B580004B740 /* Finder.scpt */,
|
B0B17429207D6B580004B740 /* Finder.scpt */,
|
||||||
B0B1742C207D6B590004B740 /* iTunes.next.scpt */,
|
B0B1742C207D6B590004B740 /* iTunes.next.scpt */,
|
||||||
@ -231,6 +294,8 @@
|
|||||||
B0B1743B207D6ED40004B740 /* CBridge */ = {
|
B0B1743B207D6ED40004B740 /* CBridge */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
4CC9FEDA22FDEA65001512EB /* AMR_ANSIEscapeHelper.h */,
|
||||||
|
4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */,
|
||||||
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */,
|
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */,
|
||||||
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */,
|
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */,
|
||||||
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||||
@ -247,18 +312,25 @@
|
|||||||
B0B88A07208CD12000A2C160 /* Widgets */ = {
|
B0B88A07208CD12000A2C160 /* Widgets */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
|
||||||
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */,
|
|
||||||
6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */,
|
|
||||||
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */,
|
|
||||||
607EEA4A2087835F009DA5F0 /* WeatherBarItem.swift */,
|
|
||||||
607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */,
|
|
||||||
6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */,
|
6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */,
|
||||||
|
B04B7BB62087398C00C835D0 /* BatteryBarItem.swift */,
|
||||||
|
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */,
|
||||||
|
4CF222EA26CC00470025BDA7 /* CPUBarItem.swift */,
|
||||||
|
607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */,
|
||||||
|
B081732B213739FE005D4908 /* DnDBarItem.swift */,
|
||||||
|
60669B4220AD8FA80074E817 /* GroupBarItem.swift */,
|
||||||
60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */,
|
60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */,
|
||||||
60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */,
|
60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */,
|
||||||
60669B4220AD8FA80074E817 /* GroupBarItem.swift */,
|
B0846A742220C968000288A7 /* NetworkBarItem.swift */,
|
||||||
B08173262135F02B005D4908 /* NightShiftBarItem.swift */,
|
B08173262135F02B005D4908 /* NightShiftBarItem.swift */,
|
||||||
B081732B213739FE005D4908 /* DnDBarItem.swift */,
|
B08126EE217BD0B900A98970 /* PomodoroBarItem.swift */,
|
||||||
|
36C2ECD6207B6DAE003CDA33 /* TimeTouchBarItem.swift */,
|
||||||
|
6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */,
|
||||||
|
607EEA4A2087835F009DA5F0 /* WeatherBarItem.swift */,
|
||||||
|
4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */,
|
||||||
|
B08126F0217BE19000A98970 /* WidgetProtocol.swift */,
|
||||||
|
B0F54A792295AC7D00B4C509 /* DarkModeBarItem.swift */,
|
||||||
|
F29F6A2424BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift */,
|
||||||
);
|
);
|
||||||
path = Widgets;
|
path = Widgets;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -273,6 +345,8 @@
|
|||||||
B082B24B205C7D8000BC04DC /* Sources */,
|
B082B24B205C7D8000BC04DC /* Sources */,
|
||||||
B082B24C205C7D8000BC04DC /* Frameworks */,
|
B082B24C205C7D8000BC04DC /* Frameworks */,
|
||||||
B082B24D205C7D8000BC04DC /* Resources */,
|
B082B24D205C7D8000BC04DC /* Resources */,
|
||||||
|
B00D181E2152F507000806F4 /* CopyFiles */,
|
||||||
|
B0679BBF215AE085000FC6B4 /* ShellScript */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
@ -307,11 +381,12 @@
|
|||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 0920;
|
LastSwiftUpdateCheck = 0920;
|
||||||
LastUpgradeCheck = 0930;
|
LastUpgradeCheck = 1010;
|
||||||
ORGANIZATIONNAME = "Anton Palgunov";
|
ORGANIZATIONNAME = "Anton Palgunov";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
B082B24E205C7D8000BC04DC = {
|
B082B24E205C7D8000BC04DC = {
|
||||||
CreatedOnToolsVersion = 9.2;
|
CreatedOnToolsVersion = 9.2;
|
||||||
|
LastSwiftMigration = 1020;
|
||||||
ProvisioningStyle = Manual;
|
ProvisioningStyle = Manual;
|
||||||
SystemCapabilities = {
|
SystemCapabilities = {
|
||||||
com.apple.Sandbox = {
|
com.apple.Sandbox = {
|
||||||
@ -321,6 +396,7 @@
|
|||||||
};
|
};
|
||||||
B082B260205C7D8000BC04DC = {
|
B082B260205C7D8000BC04DC = {
|
||||||
CreatedOnToolsVersion = 9.2;
|
CreatedOnToolsVersion = 9.2;
|
||||||
|
LastSwiftMigration = 1020;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -352,9 +428,12 @@
|
|||||||
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */,
|
B0B1743A207D6B590004B740 /* iTunes.nowPlaying.scpt in Resources */,
|
||||||
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
||||||
B0B17437207D6B590004B740 /* Spotify.nowPlaying.scpt in Resources */,
|
B0B17437207D6B590004B740 /* Spotify.nowPlaying.scpt in Resources */,
|
||||||
|
5DC6CA02241F92CB005CD5E8 /* Music.nowPlaying.scpt in Resources */,
|
||||||
|
5DC6CA03241F92CB005CD5E8 /* Music.next.scpt in Resources */,
|
||||||
B0B17436207D6B590004B740 /* iTunes.next.scpt in Resources */,
|
B0B17436207D6B590004B740 /* iTunes.next.scpt in Resources */,
|
||||||
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
||||||
B0B17435207D6B590004B740 /* Spotify.next.scpt in Resources */,
|
B0B17435207D6B590004B740 /* Spotify.next.scpt in Resources */,
|
||||||
|
B0679BC1215AE73F000FC6B4 /* dsa_pub.pem in Resources */,
|
||||||
B0B17433207D6B590004B740 /* Finder.scpt in Resources */,
|
B0B17433207D6B590004B740 /* Finder.scpt in Resources */,
|
||||||
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */,
|
B0B17439207D6B590004B740 /* Vox.nowPlaying.scpt in Resources */,
|
||||||
B0B17438207D6B590004B740 /* Vox.next.scpt in Resources */,
|
B0B17438207D6B590004B740 /* Vox.next.scpt in Resources */,
|
||||||
@ -373,6 +452,26 @@
|
|||||||
};
|
};
|
||||||
/* End PBXResourcesBuildPhase section */
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXShellScriptBuildPhase section */
|
||||||
|
B0679BBF215AE085000FC6B4 /* ShellScript */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputFileListPaths = (
|
||||||
|
);
|
||||||
|
inputPaths = (
|
||||||
|
);
|
||||||
|
outputFileListPaths = (
|
||||||
|
);
|
||||||
|
outputPaths = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\")\nbuildNumber=$(($buildNumber + 1))\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\n";
|
||||||
|
};
|
||||||
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
B082B24B205C7D8000BC04DC /* Sources */ = {
|
B082B24B205C7D8000BC04DC /* Sources */ = {
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
@ -381,20 +480,32 @@
|
|||||||
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */,
|
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */,
|
||||||
B05600D32083E9BB00EB218D /* CustomSlider.swift in Sources */,
|
B05600D32083E9BB00EB218D /* CustomSlider.swift in Sources */,
|
||||||
36C2ECD9207B74B4003CDA33 /* AppleScriptTouchBarItem.swift in Sources */,
|
36C2ECD9207B74B4003CDA33 /* AppleScriptTouchBarItem.swift in Sources */,
|
||||||
|
BAF5AB5724317B4300B04904 /* BasicView.swift in Sources */,
|
||||||
|
B0846A752220C968000288A7 /* NetworkBarItem.swift in Sources */,
|
||||||
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
||||||
|
B08126F1217BE19000A98970 /* WidgetProtocol.swift in Sources */,
|
||||||
|
4CF222EB26CC00470025BDA7 /* CPUBarItem.swift in Sources */,
|
||||||
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */,
|
B0008E552080286C003AD4DD /* SupportHelpers.swift in Sources */,
|
||||||
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */,
|
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */,
|
||||||
|
BAF5AB5924317CAF00B04904 /* SwipeItem.swift in Sources */,
|
||||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||||
|
B0F54A7A2295AC7D00B4C509 /* DarkModeBarItem.swift in Sources */,
|
||||||
|
B08126EF217BD0B900A98970 /* PomodoroBarItem.swift in Sources */,
|
||||||
|
4CF222ED26CC43D50025BDA7 /* CPU.swift in Sources */,
|
||||||
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */,
|
B081732C213739FE005D4908 /* DnDBarItem.swift in Sources */,
|
||||||
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
||||||
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
||||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */,
|
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */,
|
||||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
||||||
|
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */,
|
||||||
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
||||||
|
F29F6A2524BC7148004FF8E4 /* UpNextScrubberTouchBarItem.swift in Sources */,
|
||||||
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
|
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
|
||||||
|
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */,
|
||||||
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
||||||
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */,
|
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */,
|
||||||
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */,
|
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */,
|
||||||
|
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */,
|
||||||
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */,
|
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */,
|
||||||
36A778BE20A6C27100B38714 /* GeneralExtensions.swift in Sources */,
|
36A778BE20A6C27100B38714 /* GeneralExtensions.swift in Sources */,
|
||||||
60669B4320AD8FA80074E817 /* GroupBarItem.swift in Sources */,
|
60669B4320AD8FA80074E817 /* GroupBarItem.swift in Sources */,
|
||||||
@ -402,6 +513,7 @@
|
|||||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
||||||
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */,
|
36C2ECD7207B6DAE003CDA33 /* TimeTouchBarItem.swift in Sources */,
|
||||||
607EEA4D2087A8DA009DA5F0 /* CurrencyBarItem.swift in Sources */,
|
607EEA4D2087A8DA009DA5F0 /* CurrencyBarItem.swift in Sources */,
|
||||||
|
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */,
|
||||||
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */,
|
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */,
|
||||||
368EDDE720812A1D00E10953 /* ScrollViewItem.swift in Sources */,
|
368EDDE720812A1D00E10953 /* ScrollViewItem.swift in Sources */,
|
||||||
B04B7BB72087398C00C835D0 /* BatteryBarItem.swift in Sources */,
|
B04B7BB72087398C00C835D0 /* BatteryBarItem.swift in Sources */,
|
||||||
@ -552,14 +664,15 @@
|
|||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
|
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
|
||||||
|
"$(PROJECT_DIR)",
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = MTMR/Info.plist;
|
INFOPLIST_FILE = MTMR/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
@ -567,20 +680,22 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
|
CODE_SIGN_IDENTITY = "Developer ID Application";
|
||||||
CODE_SIGN_STYLE = Manual;
|
CODE_SIGN_STYLE = Manual;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
||||||
FRAMEWORK_SEARCH_PATHS = (
|
FRAMEWORK_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
|
"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks",
|
||||||
|
"$(PROJECT_DIR)",
|
||||||
);
|
);
|
||||||
INFOPLIST_FILE = MTMR/Info.plist;
|
INFOPLIST_FILE = MTMR/Info.plist;
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMR;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
@ -593,7 +708,7 @@
|
|||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
@ -608,7 +723,7 @@
|
|||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 4.0;
|
SWIFT_VERSION = 5.0;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict/>
|
||||||
<key>BuildSystemType</key>
|
|
||||||
<string>Latest</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0920"
|
LastUpgradeVersion = "1010"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
@ -26,7 +26,6 @@
|
|||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
<Testables>
|
<Testables>
|
||||||
<TestableReference
|
<TestableReference
|
||||||
@ -56,7 +55,6 @@
|
|||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "0920"
|
LastUpgradeVersion = "1010"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
@ -10,9 +10,8 @@
|
|||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
codeCoverageEnabled = "YES"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||||
codeCoverageEnabled = "YES">
|
|
||||||
<Testables>
|
<Testables>
|
||||||
<TestableReference
|
<TestableReference
|
||||||
skipped = "NO">
|
skipped = "NO">
|
||||||
@ -32,7 +31,6 @@
|
|||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
language = ""
|
|
||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
|||||||
@ -7,14 +7,22 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
import Sparkle
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
|
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
|
||||||
|
var isBlockedApp: Bool = false
|
||||||
|
|
||||||
private var fileSystemSource: DispatchSourceFileSystemObject?
|
private var fileSystemSource: DispatchSourceFileSystemObject?
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_: Notification) {
|
||||||
let _ = AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
|
// Configure Sparkle
|
||||||
|
SUUpdater.shared().automaticallyDownloadsUpdates = false
|
||||||
|
SUUpdater.shared().automaticallyChecksForUpdates = true
|
||||||
|
SUUpdater.shared().checkForUpdatesInBackground()
|
||||||
|
|
||||||
|
AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true] as NSDictionary)
|
||||||
|
|
||||||
TouchBarController.shared.setupControlStripPresence()
|
TouchBarController.shared.setupControlStripPresence()
|
||||||
|
|
||||||
@ -24,13 +32,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
createMenu()
|
createMenu()
|
||||||
|
|
||||||
reloadOnDefaultConfigChanged()
|
reloadOnDefaultConfigChanged()
|
||||||
|
|
||||||
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||||
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||||
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(updateIsBlockedApp), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ aNotification: Notification) {
|
func applicationWillTerminate(_: Notification) {}
|
||||||
|
|
||||||
|
@objc func updateIsBlockedApp() {
|
||||||
|
if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||||
|
isBlockedApp = AppSettings.blacklistedAppIds.firstIndex(of: frontmostAppId) != nil
|
||||||
|
} else {
|
||||||
|
isBlockedApp = false
|
||||||
|
}
|
||||||
|
createMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func openPreferences(_ sender: Any?) {
|
@objc func openPreferences(_: Any?) {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR")
|
let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!.appending("/MTMR")
|
||||||
let presetPath = appSupportDirectory.appending("/items.json")
|
let presetPath = appSupportDirectory.appending("/items.json")
|
||||||
@ -39,30 +58,39 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
task.launch()
|
task.launch()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func toggleControlStrip(_ sender: Any?) {
|
@objc func toggleControlStrip(_ item: NSMenuItem) {
|
||||||
TouchBarController.shared.controlStripState = !TouchBarController.shared.controlStripState
|
item.state = item.state == .on ? .off : .on
|
||||||
createMenu()
|
AppSettings.showControlStripState = item.state == .off
|
||||||
TouchBarController.shared.resetControlStrip()
|
TouchBarController.shared.resetControlStrip()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func toggleBlackListedApp(_ sender: Any?) {
|
@objc func toggleBlackListedApp(_: Any?) {
|
||||||
let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier
|
if let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||||
if appIdentifier != nil {
|
if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier) {
|
||||||
if let index = TouchBarController.shared.blacklistAppIdentifiers.index(of: appIdentifier!) {
|
|
||||||
TouchBarController.shared.blacklistAppIdentifiers.remove(at: index)
|
TouchBarController.shared.blacklistAppIdentifiers.remove(at: index)
|
||||||
} else {
|
} else {
|
||||||
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!)
|
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps")
|
AppSettings.blacklistedAppIds = TouchBarController.shared.blacklistAppIdentifiers
|
||||||
UserDefaults.standard.synchronize()
|
|
||||||
|
|
||||||
TouchBarController.shared.updateActiveApp()
|
TouchBarController.shared.updateActiveApp()
|
||||||
|
updateIsBlockedApp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func openPreset(_ sender: Any?) {
|
@objc func toggleHapticFeedback(_ item: NSMenuItem) {
|
||||||
let dialog = NSOpenPanel();
|
item.state = item.state == .on ? .off : .on
|
||||||
|
AppSettings.hapticFeedbackState = item.state == .on
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func toggleMultitouch(_ item: NSMenuItem) {
|
||||||
|
item.state = item.state == .on ? .off : .on
|
||||||
|
AppSettings.multitouchGestures = item.state == .on
|
||||||
|
TouchBarController.shared.basicView?.legacyGesturesEnabled = item.state == .on
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func openPreset(_: Any?) {
|
||||||
|
let dialog = NSOpenPanel()
|
||||||
|
|
||||||
dialog.title = "Choose a items.json file"
|
dialog.title = "Choose a items.json file"
|
||||||
dialog.showsResizeIndicator = true
|
dialog.showsResizeIndicator = true
|
||||||
@ -78,7 +106,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func toggleStartAtLogin(_ sender: Any?) {
|
@objc func toggleStartAtLogin(_: Any?) {
|
||||||
LaunchAtLoginController().setLaunchAtLogin(!LaunchAtLoginController().launchAtLogin, for: NSURL.fileURL(withPath: Bundle.main.bundlePath))
|
LaunchAtLoginController().setLaunchAtLogin(!LaunchAtLoginController().launchAtLogin, for: NSURL.fileURL(withPath: Bundle.main.bundlePath))
|
||||||
createMenu()
|
createMenu()
|
||||||
}
|
}
|
||||||
@ -89,19 +117,32 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
let startAtLogin = NSMenuItem(title: "Start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L")
|
let startAtLogin = NSMenuItem(title: "Start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L")
|
||||||
startAtLogin.state = LaunchAtLoginController().launchAtLogin ? .on : .off
|
startAtLogin.state = LaunchAtLoginController().launchAtLogin ? .on : .off
|
||||||
|
|
||||||
|
let toggleBlackList = NSMenuItem(title: "Toggle current app in blacklist", action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
|
||||||
|
toggleBlackList.state = isBlockedApp ? .on : .off
|
||||||
|
|
||||||
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
||||||
hideControlStrip.state = TouchBarController.shared.controlStripState ? .on : .off
|
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: "")
|
let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
|
||||||
settingSeparator.isEnabled = false
|
settingSeparator.isEnabled = false
|
||||||
|
|
||||||
menu.addItem(withTitle: "Preferences", action: #selector(openPreferences(_:)), keyEquivalent: ",")
|
menu.addItem(withTitle: "Preferences", action: #selector(openPreferences(_:)), keyEquivalent: ",")
|
||||||
menu.addItem(withTitle: "Open preset", action: #selector(openPreset(_:)), keyEquivalent: "O")
|
menu.addItem(withTitle: "Open preset", action: #selector(openPreset(_:)), keyEquivalent: "O")
|
||||||
|
menu.addItem(withTitle: "Check for Updates...", action: #selector(SUUpdater.checkForUpdates(_:)), keyEquivalent: "").target = SUUpdater.shared()
|
||||||
|
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
menu.addItem(settingSeparator)
|
menu.addItem(settingSeparator)
|
||||||
|
menu.addItem(hapticFeedback)
|
||||||
menu.addItem(hideControlStrip)
|
menu.addItem(hideControlStrip)
|
||||||
menu.addItem(withTitle: "Toggle current app in blacklist" , action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
|
menu.addItem(toggleBlackList)
|
||||||
menu.addItem(startAtLogin)
|
menu.addItem(startAtLogin)
|
||||||
|
menu.addItem(multitouchGestures)
|
||||||
menu.addItem(NSMenuItem.separator())
|
menu.addItem(NSMenuItem.separator())
|
||||||
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||||
statusItem.menu = menu
|
statusItem.menu = menu
|
||||||
@ -112,20 +153,19 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
let fd = open(file.path, O_EVTONLY)
|
let fd = open(file.path, O_EVTONLY)
|
||||||
|
|
||||||
self.fileSystemSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: fd, eventMask: .write, queue: DispatchQueue(label: "DefaultConfigChanged"))
|
fileSystemSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: fd, eventMask: .write, queue: DispatchQueue(label: "DefaultConfigChanged"))
|
||||||
|
|
||||||
self.fileSystemSource?.setEventHandler(handler: {
|
fileSystemSource?.setEventHandler(handler: {
|
||||||
print("Config changed, reloading...")
|
print("Config changed, reloading...")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
TouchBarController.shared.reloadPreset(path: file.path)
|
TouchBarController.shared.reloadPreset(path: file.path)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
self.fileSystemSource?.setCancelHandler(handler: {
|
fileSystemSource?.setCancelHandler(handler: {
|
||||||
close(fd)
|
close(fd)
|
||||||
})
|
})
|
||||||
|
|
||||||
self.fileSystemSource?.resume()
|
fileSystemSource?.resume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
MTMR/AppSettings.swift
Normal file
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,18 +4,26 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
private var script: NSAppleScript!
|
private var script: NSAppleScript!
|
||||||
private let interval: TimeInterval
|
private let interval: TimeInterval
|
||||||
private var forceHideConstraint: NSLayoutConstraint!
|
private var forceHideConstraint: NSLayoutConstraint!
|
||||||
|
private let alternativeImages: [String: SourceProtocol]
|
||||||
|
|
||||||
init?(identifier: NSTouchBarItem.Identifier, source: SourceProtocol, interval: TimeInterval) {
|
init?(identifier: NSTouchBarItem.Identifier, source: SourceProtocol, interval: TimeInterval, alternativeImages: [String: SourceProtocol]) {
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
self.alternativeImages = alternativeImages
|
||||||
super.init(identifier: identifier, title: "⏳")
|
super.init(identifier: identifier, title: "⏳")
|
||||||
self.forceHideConstraint = self.view.widthAnchor.constraint(equalToConstant: 0)
|
forceHideConstraint = view.widthAnchor.constraint(equalToConstant: 0)
|
||||||
|
title = "scheduled"
|
||||||
|
DispatchQueue.appleScriptQueue.async {
|
||||||
guard let script = source.appleScript else {
|
guard let script = source.appleScript else {
|
||||||
|
DispatchQueue.main.async {
|
||||||
self.title = "no script"
|
self.title = "no script"
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.script = script
|
self.script = script
|
||||||
|
DispatchQueue.main.async {
|
||||||
self.isBordered = false
|
self.isBordered = false
|
||||||
DispatchQueue.appleScriptQueue.async {
|
}
|
||||||
|
|
||||||
var error: NSDictionary?
|
var error: NSDictionary?
|
||||||
guard script.compileAndReturnError(&error) else {
|
guard script.compileAndReturnError(&error) else {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -30,15 +38,15 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshAndSchedule() {
|
func refreshAndSchedule() {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
print("refresh happened (interval \(self.interval)), self \(self.identifier.rawValue))")
|
print("refresh happened (interval \(interval)), self \(identifier.rawValue))")
|
||||||
#endif
|
#endif
|
||||||
let scriptResult = self.execute()
|
let scriptResult = execute()
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.title = scriptResult
|
self.title = scriptResult
|
||||||
self.forceHideConstraint.isActive = scriptResult == ""
|
self.forceHideConstraint.isActive = scriptResult == ""
|
||||||
@ -46,11 +54,21 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
print("did set new script result title \(scriptResult)")
|
print("did set new script result title \(scriptResult)")
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
DispatchQueue.appleScriptQueue.asyncAfter(deadline: .now() + self.interval) { [weak self] in
|
DispatchQueue.appleScriptQueue.asyncAfter(deadline: .now() + interval) { [weak self] in
|
||||||
self?.refreshAndSchedule()
|
self?.refreshAndSchedule()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateIcon(iconLabel: String) {
|
||||||
|
if alternativeImages[iconLabel] != nil {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.image = self.alternativeImages[iconLabel]!.image
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Cannot find icon with label \"\(iconLabel)\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func execute() -> String {
|
func execute() -> String {
|
||||||
var error: NSDictionary?
|
var error: NSDictionary?
|
||||||
let output = script.executeAndReturnError(&error)
|
let output = script.executeAndReturnError(&error)
|
||||||
@ -58,9 +76,20 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
print(error)
|
print(error)
|
||||||
return "error"
|
return "error"
|
||||||
}
|
}
|
||||||
|
if output.descriptorType == typeAEList {
|
||||||
|
let arr = Array(1...output.numberOfItems).compactMap({ output.atIndex($0)!.stringValue ?? "" })
|
||||||
|
|
||||||
|
if arr.count <= 0 {
|
||||||
|
return ""
|
||||||
|
} else if arr.count == 1 {
|
||||||
|
return arr[0]
|
||||||
|
} else {
|
||||||
|
updateIcon(iconLabel: arr[1])
|
||||||
|
return arr[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
return output.stringValue ?? ""
|
return output.stringValue ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DispatchQueue {
|
extension DispatchQueue {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
tell application "Finder"
|
tell application "Finder"
|
||||||
|
if not (exists window 1) then
|
||||||
make new Finder window
|
make new Finder window
|
||||||
set target of front window to path to home folder as string
|
set target of front window to path to home folder as string
|
||||||
|
end if
|
||||||
activate
|
activate
|
||||||
end tell
|
end tell
|
||||||
|
|||||||
7
MTMR/AppleScripts/Music.next.scpt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
if application "Music" is running then
|
||||||
|
tell application "Music"
|
||||||
|
if player state is playing then
|
||||||
|
next track
|
||||||
|
end if
|
||||||
|
end tell
|
||||||
|
end if
|
||||||
10
MTMR/AppleScripts/Music.nowPlaying.scpt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
if application "Music" is running then
|
||||||
|
tell application "Music"
|
||||||
|
if player state is playing then
|
||||||
|
return (get artist of current track) & " – " & (get name of current track)
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end if
|
||||||
|
end tell
|
||||||
|
end if
|
||||||
|
return ""
|
||||||
@ -2,6 +2,10 @@ if application "iTunes" is running then
|
|||||||
tell application "iTunes" to playpause
|
tell application "iTunes" to playpause
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
if application "Music" is running then
|
||||||
|
tell application "Music" to playpause
|
||||||
|
end if
|
||||||
|
|
||||||
if application "Spotify" is running then
|
if application "Spotify" is running then
|
||||||
tell application "Spotify" to playpause
|
tell application "Spotify" to playpause
|
||||||
end if
|
end if
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 667 B |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 2.7 KiB |
21
MTMR/Assets.xcassets/cpu.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "cpu.png",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
MTMR/Assets.xcassets/cpu.imageset/cpu.png
vendored
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
24
MTMR/Assets.xcassets/dark-mode-off.imageset/Contents.json
vendored
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
MTMR/Assets.xcassets/dark-mode-off.imageset/sun-icon-256.png
vendored
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
MTMR/Assets.xcassets/dark-mode-on.imageset/39857.png
vendored
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
24
MTMR/Assets.xcassets/dark-mode-on.imageset/Contents.json
vendored
Normal file
@ -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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13771" 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>
|
<dependencies>
|
||||||
<deployment identifier="macosx"/>
|
<deployment identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<scenes>
|
<scenes>
|
||||||
<!--Application-->
|
<!--Application-->
|
||||||
@ -619,7 +619,7 @@
|
|||||||
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
|
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
|
||||||
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
|
||||||
<connections>
|
<connections>
|
||||||
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
|
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
|
||||||
</connections>
|
</connections>
|
||||||
</menuItem>
|
</menuItem>
|
||||||
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
|
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
|
||||||
@ -676,6 +676,7 @@
|
|||||||
</application>
|
</application>
|
||||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="MTMR" customModuleProvider="target"/>
|
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="MTMR" customModuleProvider="target"/>
|
||||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||||
|
<customObject id="VW7-73-dHf" customClass="SUUpdater"/>
|
||||||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
<point key="canvasLocation" x="75" y="0.0"/>
|
<point key="canvasLocation" x="75" y="0.0"/>
|
||||||
|
|||||||
107
MTMR/BasicView.swift
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
//
|
||||||
|
// BasicView.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Fedor Zaitsev on 3/29/20.
|
||||||
|
// Copyright © 2020 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
|
class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||||
|
var twofingers: NSPanGestureRecognizer!
|
||||||
|
var threefingers: NSPanGestureRecognizer!
|
||||||
|
var fourfingers: NSPanGestureRecognizer!
|
||||||
|
var swipeItems: [SwipeItem] = []
|
||||||
|
var prevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
||||||
|
|
||||||
|
// legacy gesture positions
|
||||||
|
// by legacy I mean gestures to increse/decrease volume/brigtness which can be checked from app menu
|
||||||
|
var legacyPrevPositions: [Int: CGFloat] = [2:0, 3:0, 4:0]
|
||||||
|
var legacyGesturesEnabled = false
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem], swipeItems: [SwipeItem]) {
|
||||||
|
super.init(identifier: identifier)
|
||||||
|
self.swipeItems = swipeItems
|
||||||
|
let views = items.compactMap { $0.view }
|
||||||
|
let stackView = NSStackView(views: views)
|
||||||
|
stackView.spacing = 8
|
||||||
|
stackView.orientation = .horizontal
|
||||||
|
view = stackView
|
||||||
|
|
||||||
|
twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||||
|
twofingers.numberOfTouchesRequired = 2
|
||||||
|
twofingers.allowedTouchTypes = .direct
|
||||||
|
view.addGestureRecognizer(twofingers)
|
||||||
|
|
||||||
|
threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||||
|
threefingers.numberOfTouchesRequired = 3
|
||||||
|
threefingers.allowedTouchTypes = .direct
|
||||||
|
view.addGestureRecognizer(threefingers)
|
||||||
|
|
||||||
|
fourfingers = NSPanGestureRecognizer(target: self, action: #selector(fourfingersHandler(_:)))
|
||||||
|
fourfingers.numberOfTouchesRequired = 4
|
||||||
|
fourfingers.allowedTouchTypes = .direct
|
||||||
|
view.addGestureRecognizer(fourfingers)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func gestureHandler(position: CGFloat, fingers: Int, state: NSGestureRecognizer.State) {
|
||||||
|
switch state {
|
||||||
|
case .began:
|
||||||
|
prevPositions[fingers] = position
|
||||||
|
legacyPrevPositions[fingers] = position
|
||||||
|
case .changed:
|
||||||
|
if self.legacyGesturesEnabled {
|
||||||
|
if fingers == 2 {
|
||||||
|
let prevPos = legacyPrevPositions[fingers]!
|
||||||
|
if ((position - prevPos) > 10) || ((prevPos - position) > 10) {
|
||||||
|
if position > prevPos {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_SOUND_UP)
|
||||||
|
} else if position < prevPos {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_SOUND_DOWN)
|
||||||
|
}
|
||||||
|
legacyPrevPositions[fingers] = position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if fingers == 3 {
|
||||||
|
let prevPos = legacyPrevPositions[fingers]!
|
||||||
|
if ((position - prevPos) > 15) || ((prevPos - position) > 15) {
|
||||||
|
if position > prevPos {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_BRIGHTNESS_UP)
|
||||||
|
} else if position < prevPos {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_BRIGHTNESS_DOWN)
|
||||||
|
}
|
||||||
|
legacyPrevPositions[fingers] = position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case .ended:
|
||||||
|
print("gesture ended \(position - prevPositions[fingers]!) \(fingers)")
|
||||||
|
for item in swipeItems {
|
||||||
|
item.processEvent(offset: position - prevPositions[fingers]!, fingers: fingers)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func twofingersHandler(_ sender: NSGestureRecognizer?) {
|
||||||
|
let position = (sender?.location(in: sender?.view).x)!
|
||||||
|
self.gestureHandler(position: position, fingers: 2, state: sender!.state)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func threefingersHandler(_ sender: NSGestureRecognizer?) {
|
||||||
|
let position = (sender?.location(in: sender?.view).x)!
|
||||||
|
self.gestureHandler(position: position, fingers: 3, state: sender!.state)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func fourfingersHandler(_ sender: NSGestureRecognizer?) {
|
||||||
|
let position = (sender?.location(in: sender?.view).x)!
|
||||||
|
self.gestureHandler(position: position, fingers: 4, state: sender!.state)
|
||||||
|
}
|
||||||
|
}
|
||||||
326
MTMR/CBridge/AMR_ANSIEscapeHelper.h
Normal file
@ -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
|
||||||
996
MTMR/CBridge/AMR_ANSIEscapeHelper.m
Normal file
@ -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.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import "AMR_ANSIEscapeHelper.h"
|
||||||
#import "TouchBarPrivateApi.h"
|
#import "TouchBarPrivateApi.h"
|
||||||
#import "TouchBarSupport.h"
|
#import "TouchBarSupport.h"
|
||||||
#import "DeprecatedCarbonAPI.h"
|
#import "DeprecatedCarbonAPI.h"
|
||||||
@ -20,4 +21,7 @@ CF_EXPORT IOReturn MTActuatorClose(CFTypeRef actuatorRef);
|
|||||||
CF_EXPORT IOReturn MTActuatorActuate(CFTypeRef actuatorRef, SInt32 actuationID, UInt32 arg1, Float32 arg2, Float32 arg3);
|
CF_EXPORT IOReturn MTActuatorActuate(CFTypeRef actuatorRef, SInt32 actuationID, UInt32 arg1, Float32 arg2, Float32 arg3);
|
||||||
CF_EXPORT bool MTActuatorIsOpen(CFTypeRef actuatorRef);
|
CF_EXPORT bool MTActuatorIsOpen(CFTypeRef actuatorRef);
|
||||||
|
|
||||||
|
CF_EXPORT void CoreDisplay_Display_SetUserBrightness(int CGDirectDisplayID, double level);
|
||||||
|
CF_EXPORT double CoreDisplay_Display_GetUserBrightness(int CGDirectDisplayID);
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
191
MTMR/CPU.swift
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
//
|
||||||
|
// CPU.swift
|
||||||
|
// Pods
|
||||||
|
//
|
||||||
|
// Created by zixun on 2016/12/5.
|
||||||
|
// https://github.com/zixun/SystemEye
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
private let HOST_CPU_LOAD_INFO_COUNT : mach_msg_type_number_t =
|
||||||
|
UInt32(MemoryLayout<host_cpu_load_info_data_t>.size / MemoryLayout<integer_t>.size)
|
||||||
|
|
||||||
|
/// CPU Class
|
||||||
|
public class CPU: NSObject {
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: OPEN PROPERTY
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// /// Number of physical cores on this machine.
|
||||||
|
// public static var physicalCores: Int {
|
||||||
|
// get {
|
||||||
|
// return Int(System.hostBasicInfo.physical_cpu)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /// Number of logical cores on this machine. Will be equal to physicalCores
|
||||||
|
// /// unless it has hyper-threading, in which case it will be double.
|
||||||
|
// public static var logicalCores: Int {
|
||||||
|
// get {
|
||||||
|
// return Int(System.hostBasicInfo.logical_cpu)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: OPEN FUNCTIONS
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// Get CPU usage of hole system (system, user, idle, nice). Determined by the delta between
|
||||||
|
/// the current and last call.
|
||||||
|
public static func systemUsage() -> (system: Double,
|
||||||
|
user: Double,
|
||||||
|
idle: Double,
|
||||||
|
nice: Double) {
|
||||||
|
let load = self.hostCPULoadInfo
|
||||||
|
|
||||||
|
let userDiff = Double(load.cpu_ticks.0 - loadPrevious.cpu_ticks.0)
|
||||||
|
let sysDiff = Double(load.cpu_ticks.1 - loadPrevious.cpu_ticks.1)
|
||||||
|
let idleDiff = Double(load.cpu_ticks.2 - loadPrevious.cpu_ticks.2)
|
||||||
|
let niceDiff = Double(load.cpu_ticks.3 - loadPrevious.cpu_ticks.3)
|
||||||
|
|
||||||
|
let totalTicks = sysDiff + userDiff + niceDiff + idleDiff
|
||||||
|
|
||||||
|
let sys = sysDiff / totalTicks * 100.0
|
||||||
|
let user = userDiff / totalTicks * 100.0
|
||||||
|
let idle = idleDiff / totalTicks * 100.0
|
||||||
|
let nice = niceDiff / totalTicks * 100.0
|
||||||
|
|
||||||
|
loadPrevious = load
|
||||||
|
|
||||||
|
return (sys, user, idle, nice)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Get CPU usage of application,get from all thread
|
||||||
|
open class func applicationUsage() -> Double {
|
||||||
|
let threads = self.threadBasicInfos()
|
||||||
|
var result : Double = 0.0
|
||||||
|
threads.forEach { (thread:thread_basic_info) in
|
||||||
|
if self.flag(thread) {
|
||||||
|
result += Double.init(thread.cpu_usage) / Double.init(TH_USAGE_SCALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: PRIVATE PROPERTY
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/// previous load of cpu
|
||||||
|
private static var loadPrevious = host_cpu_load_info()
|
||||||
|
|
||||||
|
static var hostCPULoadInfo: host_cpu_load_info {
|
||||||
|
get {
|
||||||
|
var size = HOST_CPU_LOAD_INFO_COUNT
|
||||||
|
var hostInfo = host_cpu_load_info()
|
||||||
|
let result = withUnsafeMutablePointer(to: &hostInfo) {
|
||||||
|
$0.withMemoryRebound(to: integer_t.self, capacity: Int(size)) {
|
||||||
|
host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, $0, &size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
if result != KERN_SUCCESS {
|
||||||
|
fatalError("ERROR - \(#file):\(#function) - kern_result_t = "
|
||||||
|
+ "\(result)")
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return hostInfo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// MARK: PRIVATE FUNCTION
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private class func flag(_ thread:thread_basic_info) -> Bool {
|
||||||
|
let foo = thread.flags & TH_FLAGS_IDLE
|
||||||
|
let number = NSNumber.init(value: foo)
|
||||||
|
return !Bool.init(truncating: number)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class func threadActPointers() -> [thread_act_t] {
|
||||||
|
var threads_act = [thread_act_t]()
|
||||||
|
|
||||||
|
var threads_array: thread_act_array_t? = nil
|
||||||
|
var count = mach_msg_type_number_t()
|
||||||
|
|
||||||
|
let result = task_threads(mach_task_self_, &(threads_array), &count)
|
||||||
|
|
||||||
|
guard result == KERN_SUCCESS else {
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let array = threads_array else {
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..<count {
|
||||||
|
threads_act.append(array[Int(i)])
|
||||||
|
}
|
||||||
|
|
||||||
|
let krsize = count * UInt32.init(MemoryLayout<thread_t>.size)
|
||||||
|
_ = vm_deallocate(mach_task_self_, vm_address_t(array.pointee), vm_size_t(krsize));
|
||||||
|
return threads_act
|
||||||
|
}
|
||||||
|
|
||||||
|
private class func threadBasicInfos() -> [thread_basic_info] {
|
||||||
|
var result = [thread_basic_info]()
|
||||||
|
|
||||||
|
let thinfo : thread_info_t = thread_info_t.allocate(capacity: Int(THREAD_INFO_MAX))
|
||||||
|
let thread_info_count = UnsafeMutablePointer<mach_msg_type_number_t>.allocate(capacity: 128)
|
||||||
|
var basic_info_th: thread_basic_info_t? = nil
|
||||||
|
|
||||||
|
for act_t in self.threadActPointers() {
|
||||||
|
thread_info_count.pointee = UInt32(THREAD_INFO_MAX);
|
||||||
|
let kr = thread_info(act_t ,thread_flavor_t(THREAD_BASIC_INFO),thinfo, thread_info_count);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
return [thread_basic_info]();
|
||||||
|
}
|
||||||
|
basic_info_th = withUnsafePointer(to: &thinfo.pointee, { (ptr) -> thread_basic_info_t in
|
||||||
|
let int8Ptr = unsafeBitCast(ptr, to: thread_basic_info_t.self)
|
||||||
|
return int8Ptr
|
||||||
|
})
|
||||||
|
if basic_info_th != nil {
|
||||||
|
result.append(basic_info_th!.pointee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: this function is used for get cpu usage of all thread,and this is in developing
|
||||||
|
private class func threadIdentifierInfos() -> [thread_identifier_info] {
|
||||||
|
var result = [thread_identifier_info]()
|
||||||
|
let thinfo : thread_info_t = thread_info_t.allocate(capacity: Int(THREAD_INFO_MAX))
|
||||||
|
let thread_info_count = UnsafeMutablePointer<mach_msg_type_number_t>.allocate(capacity: 128)
|
||||||
|
var identifier_info_th: thread_identifier_info_t? = nil
|
||||||
|
|
||||||
|
for act_t in self.threadActPointers() {
|
||||||
|
thread_info_count.pointee = UInt32(THREAD_INFO_MAX);
|
||||||
|
let kr = thread_info(act_t ,thread_flavor_t(THREAD_IDENTIFIER_INFO),thinfo, thread_info_count);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
return [thread_identifier_info]();
|
||||||
|
}
|
||||||
|
identifier_info_th = withUnsafePointer(to: &thinfo.pointee, { (ptr) -> thread_identifier_info_t in
|
||||||
|
let int8Ptr = unsafeBitCast(ptr, to: thread_identifier_info_t.self)
|
||||||
|
return int8Ptr
|
||||||
|
})
|
||||||
|
if identifier_info_th != nil {
|
||||||
|
result.append(identifier_info_th!.pointee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,33 +8,60 @@
|
|||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
struct ItemAction {
|
||||||
var tapClosure: (() -> ())?
|
typealias TriggerClosure = (() -> Void)?
|
||||||
var longTapClosure: (() -> ())?
|
|
||||||
private var button: NSButton!
|
|
||||||
|
|
||||||
private var singleClick: NSClickGestureRecognizer!
|
let trigger: Action.Trigger
|
||||||
private var longClick: NSPressGestureRecognizer!
|
let closure: TriggerClosure
|
||||||
|
|
||||||
|
init(trigger: Action.Trigger, _ closure: TriggerClosure) {
|
||||||
|
self.trigger = trigger
|
||||||
|
self.closure = closure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||||
|
|
||||||
|
var actions: [ItemAction] = [] {
|
||||||
|
didSet {
|
||||||
|
multiClick.isDoubleClickEnabled = actions.filter({ $0.trigger == .doubleTap }).count > 0
|
||||||
|
multiClick.isTripleClickEnabled = actions.filter({ $0.trigger == .tripleTap }).count > 0
|
||||||
|
longClick.isEnabled = actions.filter({ $0.trigger == .longTap }).count > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var finishViewConfiguration: ()->() = {}
|
||||||
|
|
||||||
|
private var button: NSButton!
|
||||||
|
private var longClick: LongPressGestureRecognizer!
|
||||||
|
private var multiClick: MultiClickGestureRecognizer!
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, title: String) {
|
init(identifier: NSTouchBarItem.Identifier, title: String) {
|
||||||
self.attributedTitle = title.defaultTouchbarAttributedString
|
attributedTitle = title.defaultTouchbarAttributedString
|
||||||
|
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
button = CustomHeightButton(title: title, target: nil, action: nil)
|
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.allowedTouchTypes = .direct
|
||||||
longClick.delegate = self
|
longClick.delegate = self
|
||||||
|
|
||||||
singleClick = NSClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
multiClick = MultiClickGestureRecognizer(
|
||||||
singleClick.allowedTouchTypes = .direct
|
target: self,
|
||||||
singleClick.delegate = self
|
action: #selector(handleGestureSingleTap),
|
||||||
|
doubleAction: #selector(handleGestureDoubleTap),
|
||||||
|
tripleAction: #selector(handleGestureTripleTap)
|
||||||
|
)
|
||||||
|
multiClick.allowedTouchTypes = .direct
|
||||||
|
multiClick.delegate = self
|
||||||
|
multiClick.isDoubleClickEnabled = false
|
||||||
|
multiClick.isTripleClickEnabled = false
|
||||||
|
|
||||||
reinstallButton()
|
reinstallButton()
|
||||||
button.attributedTitle = attributedTitle
|
button.attributedTitle = attributedTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,17 +79,17 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
|
|
||||||
var title: String {
|
var title: String {
|
||||||
get {
|
get {
|
||||||
return self.attributedTitle.string
|
return attributedTitle.string
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
self.attributedTitle = newValue.defaultTouchbarAttributedString
|
attributedTitle = newValue.defaultTouchbarAttributedString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var attributedTitle: NSAttributedString {
|
var attributedTitle: NSAttributedString {
|
||||||
didSet {
|
didSet {
|
||||||
self.button?.imagePosition = attributedTitle.length > 0 ? .imageLeading : .imageOnly
|
button?.imagePosition = attributedTitle.length > 0 ? .imageLeading : .imageOnly
|
||||||
self.button?.attributedTitle = attributedTitle
|
button?.attributedTitle = attributedTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +107,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
if let color = backgroundColor {
|
if let color = backgroundColor {
|
||||||
cell.isBordered = true
|
cell.isBordered = true
|
||||||
button.bezelColor = color
|
button.bezelColor = color
|
||||||
|
button.bezelStyle = .rounded
|
||||||
cell.backgroundColor = color
|
cell.backgroundColor = color
|
||||||
} else {
|
} else {
|
||||||
button.isBordered = isBordered
|
button.isBordered = isBordered
|
||||||
@ -88,61 +116,61 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
button.imageScaling = .scaleProportionallyDown
|
button.imageScaling = .scaleProportionallyDown
|
||||||
button.imageHugsTitle = true
|
button.imageHugsTitle = true
|
||||||
button.attributedTitle = title
|
button.attributedTitle = title
|
||||||
self.button?.imagePosition = title.length > 0 ? .imageLeading : .imageOnly
|
button?.imagePosition = title.length > 0 ? .imageLeading : .imageOnly
|
||||||
button.image = image
|
button.image = image
|
||||||
self.view = button
|
view = button
|
||||||
|
|
||||||
self.view.addGestureRecognizer(longClick)
|
view.addGestureRecognizer(longClick)
|
||||||
self.view.addGestureRecognizer(singleClick)
|
// view.addGestureRecognizer(singleClick)
|
||||||
|
view.addGestureRecognizer(multiClick)
|
||||||
|
finishViewConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
||||||
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick {
|
if gestureRecognizer == multiClick && otherGestureRecognizer == longClick
|
||||||
|
|| gestureRecognizer == longClick && otherGestureRecognizer == multiClick // need it
|
||||||
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleGestureSingle(gr: NSClickGestureRecognizer) {
|
func callActions(for trigger: Action.Trigger) {
|
||||||
let hf: HapticFeedback = HapticFeedback()
|
let itemActions = self.actions.filter { $0.trigger == trigger }
|
||||||
switch gr.state {
|
for itemAction in itemActions {
|
||||||
case .ended:
|
itemAction.closure?()
|
||||||
hf.tap(strong: 2)
|
|
||||||
self.tapClosure?()
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureSingleTap() {
|
||||||
|
callActions(for: .singleTap)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureDoubleTap() {
|
||||||
|
callActions(for: .doubleTap)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleGestureTripleTap() {
|
||||||
|
callActions(for: .tripleTap)
|
||||||
|
}
|
||||||
|
|
||||||
@objc func handleGestureLong(gr: NSPressGestureRecognizer) {
|
@objc func handleGestureLong(gr: NSPressGestureRecognizer) {
|
||||||
let hf: HapticFeedback = HapticFeedback()
|
|
||||||
switch gr.state {
|
switch gr.state {
|
||||||
case .began:
|
case .possible: // tiny hack because we're calling action manually
|
||||||
if let closure = self.longTapClosure {
|
callActions(for: .longTap)
|
||||||
hf.tap(strong: 2)
|
|
||||||
closure()
|
|
||||||
} else if let closure = self.tapClosure {
|
|
||||||
hf.tap(strong: 6)
|
|
||||||
closure()
|
|
||||||
print("long click")
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomHeightButton: NSButton {
|
class CustomHeightButton: NSButton {
|
||||||
|
|
||||||
override var intrinsicContentSize: NSSize {
|
override var intrinsicContentSize: NSSize {
|
||||||
var size = super.intrinsicContentSize
|
var size = super.intrinsicContentSize
|
||||||
size.height = 30
|
size.height = 30
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomButtonCell: NSButtonCell {
|
class CustomButtonCell: NSButtonCell {
|
||||||
@ -155,32 +183,158 @@ class CustomButtonCell: NSButtonCell {
|
|||||||
|
|
||||||
override func highlight(_ flag: Bool, withFrame cellFrame: NSRect, in controlView: NSView) {
|
override func highlight(_ flag: Bool, withFrame cellFrame: NSRect, in controlView: NSView) {
|
||||||
super.highlight(flag, withFrame: cellFrame, in: controlView)
|
super.highlight(flag, withFrame: cellFrame, in: controlView)
|
||||||
if !self.isBordered {
|
if !isBordered {
|
||||||
if flag {
|
if flag {
|
||||||
self.setAttributedTitle(self.attributedTitle, withColor: .lightGray)
|
setAttributedTitle(attributedTitle, withColor: .lightGray)
|
||||||
} else if let parentItem = self.parentItem {
|
} else if let parentItem = self.parentItem {
|
||||||
self.attributedTitle = parentItem.attributedTitle
|
attributedTitle = parentItem.attributedTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init(coder: NSCoder) {
|
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")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAttributedTitle(_ title: NSAttributedString, withColor color: NSColor) {
|
func setAttributedTitle(_ title: NSAttributedString, withColor color: NSColor) {
|
||||||
let attrTitle = NSMutableAttributedString(attributedString: title)
|
let attrTitle = NSMutableAttributedString(attributedString: title)
|
||||||
attrTitle.addAttributes([.foregroundColor: color], range: NSRange(location: 0, length: attrTitle.length))
|
attrTitle.addAttributes([.foregroundColor: color], range: NSRange(location: 0, length: attrTitle.length))
|
||||||
self.attributedTitle = attrTitle
|
attributedTitle = attrTitle
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Thanks to https://stackoverflow.com/a/49843893
|
||||||
|
final class MultiClickGestureRecognizer: NSClickGestureRecognizer {
|
||||||
|
|
||||||
|
private let _action: Selector
|
||||||
|
private let _doubleAction: Selector
|
||||||
|
private let _tripleAction: Selector
|
||||||
|
private var _clickCount: Int = 0
|
||||||
|
|
||||||
|
public var isDoubleClickEnabled = true
|
||||||
|
public var isTripleClickEnabled = true
|
||||||
|
|
||||||
|
override var action: Selector? {
|
||||||
|
get {
|
||||||
|
return nil /// prevent base class from performing any actions
|
||||||
|
} set {
|
||||||
|
if newValue != nil { // if they are trying to assign an actual action
|
||||||
|
fatalError("Only use init(target:action:doubleAction) for assigning actions")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
required init(target: AnyObject, action: Selector, doubleAction: Selector, tripleAction: Selector) {
|
||||||
|
_action = action
|
||||||
|
_doubleAction = doubleAction
|
||||||
|
_tripleAction = tripleAction
|
||||||
|
super.init(target: target, action: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(target:action:doubleAction:tripleAction) is only support atm")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func touchesBegan(with event: NSEvent) {
|
||||||
|
HapticFeedback.instance.tap(type: .click)
|
||||||
|
super.touchesBegan(with: event)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func touchesEnded(with event: NSEvent) {
|
||||||
|
HapticFeedback.instance.tap(type: .back)
|
||||||
|
super.touchesEnded(with: event)
|
||||||
|
_clickCount += 1
|
||||||
|
|
||||||
|
var delayThreshold: TimeInterval // fine tune this as needed
|
||||||
|
|
||||||
|
guard isDoubleClickEnabled || isTripleClickEnabled else {
|
||||||
|
_ = target?.perform(_action)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isTripleClickEnabled) {
|
||||||
|
delayThreshold = 0.4
|
||||||
|
perform(#selector(_resetAndPerformActionIfNecessary), with: nil, afterDelay: delayThreshold)
|
||||||
|
if _clickCount == 3 {
|
||||||
|
_ = target?.perform(_tripleAction)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delayThreshold = 0.3
|
||||||
|
perform(#selector(_resetAndPerformActionIfNecessary), with: nil, afterDelay: delayThreshold)
|
||||||
|
if _clickCount == 2 {
|
||||||
|
_ = target?.perform(_doubleAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func _resetAndPerformActionIfNecessary() {
|
||||||
|
if _clickCount == 1 {
|
||||||
|
_ = target?.perform(_action)
|
||||||
|
}
|
||||||
|
if isTripleClickEnabled && _clickCount == 2 {
|
||||||
|
_ = target?.perform(_doubleAction)
|
||||||
|
}
|
||||||
|
_clickCount = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.instance.tap(type: .strong)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
timerInvalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
var defaultTouchbarAttributedString: NSAttributedString {
|
var defaultTouchbarAttributedString: NSAttributedString {
|
||||||
let attrTitle = NSMutableAttributedString(string: self, attributes: [.foregroundColor: NSColor.white, .font: NSFont.systemFont(ofSize: 15, weight: .regular), .baselineOffset: 1])
|
let attrTitle = NSMutableAttributedString(string: self, attributes: [.foregroundColor: NSColor.white, .font: NSFont.systemFont(ofSize: 15, weight: .regular), .baselineOffset: 1])
|
||||||
attrTitle.setAlignment(.center, range: NSRange(location: 0, length: self.count))
|
attrTitle.setAlignment(.center, range: NSRange(location: 0, length: count))
|
||||||
return attrTitle
|
return attrTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,20 +22,20 @@ class CustomSliderCell: NSSliderCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init(knob: NSImage?) {
|
init(knob: NSImage?) {
|
||||||
knobImage = knob;
|
knobImage = knob
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func drawKnob(_ knobRect: NSRect) {
|
override func drawKnob(_ knobRect: NSRect) {
|
||||||
if (knobImage == nil) {
|
if knobImage == nil {
|
||||||
super.drawKnob(knobRect)
|
super.drawKnob(knobRect)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentKnobRect = knobRect;
|
_currentKnobRect = knobRect
|
||||||
drawBar(inside: _barRect, flipped: true)
|
drawBar(inside: _barRect, flipped: true)
|
||||||
|
|
||||||
let x = (knobRect.origin.x * (_barRect.size.width - (knobImage.size.width - knobRect.size.width)) / _barRect.size.width)+1;
|
let x = (knobRect.origin.x * (_barRect.size.width - (knobImage.size.width - knobRect.size.width)) / _barRect.size.width) + 1
|
||||||
let y = knobRect.origin.y + 3
|
let y = knobRect.origin.y + 3
|
||||||
|
|
||||||
knobImage.draw(
|
knobImage.draw(
|
||||||
@ -46,7 +46,7 @@ class CustomSliderCell: NSSliderCell {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func drawBar(inside aRect: NSRect, flipped: Bool) {
|
override func drawBar(inside aRect: NSRect, flipped _: Bool) {
|
||||||
_barRect = aRect
|
_barRect = aRect
|
||||||
|
|
||||||
let barRadius = CGFloat(2)
|
let barRadius = CGFloat(2)
|
||||||
@ -60,7 +60,7 @@ class CustomSliderCell: NSSliderCell {
|
|||||||
|
|
||||||
var activeRect = bgRect
|
var activeRect = bgRect
|
||||||
|
|
||||||
activeRect.size.width = CGFloat((Double(bgRect.size.width) / (self.maxValue - self.minValue)) * self.doubleValue)
|
activeRect.size.width = CGFloat((Double(bgRect.size.width) / (maxValue - minValue)) * doubleValue)
|
||||||
let active = NSBezierPath(roundedRect: activeRect, xRadius: barRadius, yRadius: barRadius)
|
let active = NSBezierPath(roundedRect: activeRect, xRadius: barRadius, yRadius: barRadius)
|
||||||
NSColor.darkGray.setFill()
|
NSColor.darkGray.setFill()
|
||||||
active.fill()
|
active.fill()
|
||||||
@ -68,7 +68,6 @@ class CustomSliderCell: NSSliderCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CustomSlider: NSSlider {
|
class CustomSlider: NSSlider {
|
||||||
|
|
||||||
var currentValue: CGFloat = 0
|
var currentValue: CGFloat = 0
|
||||||
|
|
||||||
override func setNeedsDisplay(_ invalidRect: NSRect) {
|
override func setNeedsDisplay(_ invalidRect: NSRect) {
|
||||||
@ -77,7 +76,7 @@ class CustomSlider:NSSlider {
|
|||||||
|
|
||||||
override func awakeFromNib() {
|
override func awakeFromNib() {
|
||||||
super.awakeFromNib()
|
super.awakeFromNib()
|
||||||
if ((self.cell?.isKind(of: CustomSliderCell.self)) == false) {
|
if (cell?.isKind(of: CustomSliderCell.self)) == false {
|
||||||
let cell: CustomSliderCell = CustomSliderCell()
|
let cell: CustomSliderCell = CustomSliderCell()
|
||||||
self.cell = cell
|
self.cell = cell
|
||||||
}
|
}
|
||||||
@ -85,7 +84,7 @@ class CustomSlider:NSSlider {
|
|||||||
|
|
||||||
convenience init(knob: NSImage) {
|
convenience init(knob: NSImage) {
|
||||||
self.init()
|
self.init()
|
||||||
self.cell = CustomSliderCell(knob: knob)
|
cell = CustomSliderCell(knob: knob)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
|||||||
@ -11,9 +11,7 @@ import Foundation
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
|
||||||
var ifNotEmpty: String? {
|
var ifNotEmpty: String? {
|
||||||
return self.count > 0 ? self : nil
|
return count > 0 ? self : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,49 +9,92 @@
|
|||||||
import IOKit
|
import IOKit
|
||||||
|
|
||||||
class HapticFeedback {
|
class HapticFeedback {
|
||||||
private var actuatorRef: CFTypeRef?
|
|
||||||
private var deviceID: UInt64 = 0x200000001000000
|
|
||||||
private var error: IOReturn = 0
|
|
||||||
|
|
||||||
// Don't know how to do strong is enum one of
|
// Here we have list of possible IDs for Haptic Generator Device. They are not constant
|
||||||
// 1 like back Click
|
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg
|
||||||
// 2 like Click
|
// which you can download from https://developer.apple.com/download/more/?=Additional%20Tools
|
||||||
// 3 week
|
// Open IORegistryExplorer app, search for "AppleMultitouchDevice" and get "Multitouch ID"
|
||||||
// 4 medium
|
// or "AppleMultitouchTrackpadHIDEventDriver" and get "mt-device-id"
|
||||||
// 5 week medium
|
// There should be programmatic way to get it but I can't find, no docs for macOS :(
|
||||||
// 6 strong
|
private let possibleDeviceIDs: [UInt64] = [
|
||||||
// 15 nothing
|
0x200_0000_0100_0000, // MacBook Pro 2016/2017
|
||||||
// 16 nothing
|
0x300_0000_8050_0000, // MacBook Pro 2019/2018
|
||||||
|
0x200_0000_0000_0024, // MacBook Pro (13-inch, M1, 2020)
|
||||||
|
0x200_0000_0000_0023 // MacBook Pro M1 13-Inch 2020 with 1tb
|
||||||
|
// 0x300000080500000,
|
||||||
|
]
|
||||||
|
|
||||||
// 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`
|
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
|
||||||
|
enum HapticType: Int32, CaseIterable {
|
||||||
|
case back = 1
|
||||||
|
case click = 2
|
||||||
|
case weak = 3
|
||||||
|
case medium = 4
|
||||||
|
case weakMedium = 5
|
||||||
|
case strong = 6
|
||||||
|
case reserved1 = 15
|
||||||
|
case reserved2 = 16
|
||||||
|
}
|
||||||
|
|
||||||
func tap(strong:Int32) -> Void {
|
private var actuatorRef: CFTypeRef?
|
||||||
actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
|
||||||
|
|
||||||
guard actuatorRef != nil else {
|
static var instance = HapticFeedback()
|
||||||
print("guard actuatorRef == nil")
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
self.recreateDevice()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func recreateDevice() {
|
||||||
|
if let actuatorRef = self.actuatorRef {
|
||||||
|
MTActuatorClose(actuatorRef)
|
||||||
|
self.actuatorRef = nil // just in case %)
|
||||||
|
}
|
||||||
|
|
||||||
|
guard self.actuatorRef == nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorOpen(actuatorRef!)
|
// Let's find our Haptic device
|
||||||
guard error == kIOReturnSuccess else {
|
self.possibleDeviceIDs.forEach {(deviceID) in
|
||||||
|
let actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
||||||
|
|
||||||
|
if actuatorRef != nil {
|
||||||
|
self.actuatorRef = actuatorRef
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Tap action
|
||||||
|
|
||||||
|
private func getActuatorIfPosible() -> CFTypeRef? {
|
||||||
|
guard AppSettings.hapticFeedbackState else { return nil }
|
||||||
|
guard let actuatorRef = self.actuatorRef else {
|
||||||
|
print("guard actuatorRef == nil (no haptic device found?)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard MTActuatorOpen(actuatorRef) == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorOpen")
|
print("guard MTActuatorOpen")
|
||||||
return
|
self.recreateDevice()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorActuate(actuatorRef!, strong, 0, 0.0, 0.0)
|
return actuatorRef
|
||||||
guard error == kIOReturnSuccess else {
|
}
|
||||||
|
|
||||||
|
func tap(type: HapticType) {
|
||||||
|
guard let actuator = getActuatorIfPosible() else { return }
|
||||||
|
|
||||||
|
guard MTActuatorActuate(actuator, type.rawValue, 0, 0, 0) == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorActuate")
|
print("guard MTActuatorActuate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorClose(actuatorRef!)
|
guard MTActuatorClose(actuator) == kIOReturnSuccess else {
|
||||||
guard error == kIOReturnSuccess else {
|
|
||||||
print("guard MTActuatorClose")
|
print("guard MTActuatorClose")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,15 +17,31 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.18</string>
|
<string>0.27</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>448</string>
|
||||||
|
<key>LSApplicationCategoryType</key>
|
||||||
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSAppleEventsUsageDescription</key>
|
||||||
|
<string>AppleEvents needed for correct work AppleScript</string>
|
||||||
|
<key>NSAppleMusicUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Media for work</string>
|
||||||
|
<key>NSBluetoothPeripheralUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Bluetooth for work</string>
|
||||||
|
<key>NSCalendarsUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Calendar for work</string>
|
||||||
|
<key>NSCameraUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Camera for work</string>
|
||||||
|
<key>NSHomeKitUsageDescription</key>
|
||||||
|
<string>MTMR needs access to HomeKit for work</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<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>
|
<key>NSLocationAlwaysUsageDescription</key>
|
||||||
<string>Weather widget need your location for correct work</string>
|
<string>Weather widget need your location for correct work</string>
|
||||||
<key>NSLocationUsageDescription</key>
|
<key>NSLocationUsageDescription</key>
|
||||||
@ -34,7 +50,19 @@
|
|||||||
<string>Weather widget need your location for correct work</string>
|
<string>Weather widget need your location for correct work</string>
|
||||||
<key>NSMainStoryboardFile</key>
|
<key>NSMainStoryboardFile</key>
|
||||||
<string>Main</string>
|
<string>Main</string>
|
||||||
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Photo for work</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
|
<key>NSRemindersUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Reminders for work</string>
|
||||||
|
<key>NSSystemAdministrationUsageDescription</key>
|
||||||
|
<string>MTMR needs access to Administation for work</string>
|
||||||
|
<key>SUFeedURL</key>
|
||||||
|
<string>https://mtmr.app/appcast.xml</string>
|
||||||
|
<key>SUPublicDSAKeyFile</key>
|
||||||
|
<string>dsa_pub.pem</string>
|
||||||
|
<key>kTCCServiceMediaLibrary</key>
|
||||||
|
<string>MTMR needs access to Music for work</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@ -1,237 +1,283 @@
|
|||||||
import Foundation
|
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import Foundation
|
||||||
|
|
||||||
extension Data {
|
extension Data {
|
||||||
func barItemDefinitions() -> [BarItemDefinition]? {
|
func barItemDefinitions() -> [BarItemDefinition]? {
|
||||||
return try? JSONDecoder().decode([BarItemDefinition].self, from: self.utf8string!.stripComments().data(using: .utf8)!)
|
return try! JSONDecoder().decode([BarItemDefinition].self, from: utf8string!.stripComments().data(using: .utf8)!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BarItemDefinition: Decodable {
|
struct BarItemDefinition: Decodable {
|
||||||
let type: ItemType
|
let type: ItemType
|
||||||
let action: ActionType
|
let actions: [Action]
|
||||||
let longAction: LongActionType
|
let legacyAction: LegacyActionType
|
||||||
|
let legacyLongAction: LegacyLongActionType
|
||||||
let additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
let additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case type
|
case type
|
||||||
|
case actions
|
||||||
}
|
}
|
||||||
|
|
||||||
init(type: ItemType, action: ActionType, longAction: LongActionType, additionalParameters: [GeneralParameters.CodingKeys:GeneralParameter]) {
|
init(type: ItemType, actions: [Action], action: LegacyActionType, legacyLongAction: LegacyLongActionType, additionalParameters: [GeneralParameters.CodingKeys: GeneralParameter]) {
|
||||||
self.type = type
|
self.type = type
|
||||||
self.action = action
|
self.actions = actions
|
||||||
self.longAction = longAction
|
self.legacyAction = action
|
||||||
|
self.legacyLongAction = legacyLongAction
|
||||||
self.additionalParameters = additionalParameters
|
self.additionalParameters = additionalParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
let type = try container.decode(String.self, forKey: .type)
|
let type = try container.decode(String.self, forKey: .type)
|
||||||
let parametersDecoder = SupportedTypesHolder.sharedInstance.lookup(by: type)
|
let actions = try container.decodeIfPresent([Action].self, forKey: .actions)
|
||||||
|
let parametersDecoder = SupportedTypesHolder.sharedInstance.lookup(by: type, actions: actions ?? [])
|
||||||
var additionalParameters = try GeneralParameters(from: decoder).parameters
|
var additionalParameters = try GeneralParameters(from: decoder).parameters
|
||||||
|
|
||||||
if let result = try? parametersDecoder(decoder),
|
if let result = try? parametersDecoder(decoder),
|
||||||
case let (itemType, action, longAction, parameters) = result {
|
case let (itemType, actions, action, longAction, parameters) = result {
|
||||||
parameters.forEach { additionalParameters[$0] = $1 }
|
parameters.forEach { additionalParameters[$0] = $1 }
|
||||||
self.init(type: itemType, action: action, longAction: longAction, additionalParameters: additionalParameters)
|
self.init(type: itemType, actions: actions, action: action, legacyLongAction: longAction, additionalParameters: additionalParameters)
|
||||||
} else {
|
} else {
|
||||||
self.init(type: .staticButton(title: "unknown"), action: .none, longAction: .none, additionalParameters: additionalParameters)
|
self.init(type: .staticButton(title: "unknown"), actions: [], action: .none, legacyLongAction: .none, additionalParameters: additionalParameters)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
typealias ParametersDecoder = (Decoder) throws -> (
|
||||||
|
item: ItemType,
|
||||||
|
actions: [Action],
|
||||||
|
legacyAction: LegacyActionType,
|
||||||
|
legacyLongAction: LegacyLongActionType,
|
||||||
|
parameters: [GeneralParameters.CodingKeys: GeneralParameter]
|
||||||
|
)
|
||||||
|
|
||||||
class SupportedTypesHolder {
|
class SupportedTypesHolder {
|
||||||
typealias ParametersDecoder = (Decoder) throws ->(item: ItemType, action: ActionType, longAction: LongActionType, parameters: [GeneralParameters.CodingKeys: GeneralParameter])
|
|
||||||
private var supportedTypes: [String: ParametersDecoder] = [
|
private var supportedTypes: [String: ParametersDecoder] = [
|
||||||
"escape": { _ in return (item: .staticButton(title: "esc"), action: .keyPress(keycode: 53), longAction: .none, parameters: [.align: .align(.left)]) },
|
"escape": { _ in (
|
||||||
|
item: .staticButton(title: "esc"),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .keyPress(keycode: 53))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.align: .align(.left)]
|
||||||
|
) },
|
||||||
|
|
||||||
"delete": { _ in return (item: .staticButton(title: "del"), action: .keyPress(keycode: 117), longAction: .none, parameters: [:])},
|
"delete": { _ in (
|
||||||
|
item: .staticButton(title: "del"),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .keyPress(keycode: 117))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [:]
|
||||||
|
) },
|
||||||
|
|
||||||
"brightnessUp": { _ in
|
"brightnessUp": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessUp"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessUp"))
|
||||||
return (item: .staticButton(title: ""), action: .keyPress(keycode: 144), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_BRIGHTNESS_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"brightnessDown": { _ in
|
"brightnessDown": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessDown"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "brightnessDown"))
|
||||||
return (item: .staticButton(title: ""), action: .keyPress(keycode: 145), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_BRIGHTNESS_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"illuminationUp": { _ in
|
"illuminationUp": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_up"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_up"))
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_UP), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"illuminationDown": { _ in
|
"illuminationDown": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_down"))
|
let imageParameter = GeneralParameter.image(source: #imageLiteral(resourceName: "ill_down"))
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_DOWN), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_ILLUMINATION_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"volumeDown": { _ in
|
"volumeDown": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarVolumeDownTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeDownTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_SOUND_DOWN), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_SOUND_DOWN))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"volumeUp": { _ in
|
"volumeUp": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarVolumeUpTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarVolumeUpTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_SOUND_UP), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_SOUND_UP))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"mute": { _ in
|
"mute": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarAudioOutputMuteTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarAudioOutputMuteTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_MUTE), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_MUTE))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"previous": { _ in
|
"previous": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarRewindTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarRewindTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_PREVIOUS), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_PREVIOUS))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"play": { _ in
|
"play": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarPlayPauseTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarPlayPauseTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_PLAY), longAction: .none, parameters: [.image: imageParameter])
|
return (
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_PLAY))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"next": { _ in
|
"next": { _ in
|
||||||
let imageParameter = GeneralParameter.image(source: NSImage(named: .touchBarFastForwardTemplate)!)
|
let imageParameter = GeneralParameter.image(source: NSImage(named: NSImage.touchBarFastForwardTemplateName)!)
|
||||||
return (item: .staticButton(title: ""), action: .hidKey(keycode: NX_KEYTYPE_NEXT), longAction: .none, parameters: [.image: imageParameter])
|
|
||||||
},
|
|
||||||
|
|
||||||
"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: action, longAction: longAction, parameters: [:])
|
|
||||||
},
|
|
||||||
|
|
||||||
"currency": { decoder in
|
|
||||||
enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to }
|
|
||||||
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 action = try ActionType(from: decoder)
|
|
||||||
let longAction = try LongActionType(from: decoder)
|
|
||||||
return (item: .currency(interval: interval ?? 600.00, from: from ?? "RUB", to: to ?? "USD"), action: action, longAction: longAction, parameters: [:])
|
|
||||||
},
|
|
||||||
|
|
||||||
"dock": { decoder in
|
|
||||||
return (item: .dock(), action: .none, longAction: .none, parameters: [:])
|
|
||||||
},
|
|
||||||
|
|
||||||
"inputsource": { decoder in
|
|
||||||
return (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 return (item: .staticButton(title: "☕️"), action: .shellScript(executable: "/usr/bin/pmset", parameters: ["sleepnow"]), longAction: .none, parameters: [:]) },
|
|
||||||
|
|
||||||
"displaySleep": { _ in return (item: .staticButton(title: "☕️"), action: .shellScript(executable: "/usr/bin/pmset", parameters: ["displaysleepnow"]), longAction: .none, 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 (
|
return (
|
||||||
item: .music(interval: interval ?? 1800.00),
|
item: .staticButton(title: ""),
|
||||||
action: .none,
|
actions: [
|
||||||
longAction: .none,
|
Action(trigger: .singleTap, value: .hidKey(keycode: NX_KEYTYPE_NEXT))
|
||||||
parameters: [:]
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.image: imageParameter]
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
"group": { decoder in
|
"sleep": { _ in (
|
||||||
enum CodingKeys: CodingKey { case items }
|
item: .staticButton(title: "☕️"),
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
actions: [
|
||||||
let items = try container.decode([BarItemDefinition].self, forKey: .items)
|
Action(trigger: .singleTap, value: .shellScript(executable: "/usr/bin/pmset", parameters: ["sleepnow"]))
|
||||||
return (
|
],
|
||||||
item: .groupBar(items: items),
|
legacyAction: .none,
|
||||||
action: .none,
|
legacyLongAction: .none,
|
||||||
longAction: .none,
|
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
)
|
) },
|
||||||
},
|
|
||||||
|
|
||||||
"nightShift": {_ in
|
"displaySleep": { _ in (
|
||||||
return (
|
item: .staticButton(title: "☕️"),
|
||||||
item: .nightShift(),
|
actions: [
|
||||||
action: .none,
|
Action(trigger: .singleTap, value: .shellScript(executable: "/usr/bin/pmset", parameters: ["displaysleepnow"]))
|
||||||
longAction: .none,
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
parameters: [:]
|
parameters: [:]
|
||||||
)
|
) },
|
||||||
},
|
|
||||||
|
|
||||||
"dnd": { _ in
|
|
||||||
return (
|
|
||||||
item: .dnd(),
|
|
||||||
action: .none,
|
|
||||||
longAction: .none,
|
|
||||||
parameters: [:]
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
static let sharedInstance = SupportedTypesHolder()
|
static let sharedInstance = SupportedTypesHolder()
|
||||||
|
|
||||||
func lookup(by type: String) -> ParametersDecoder {
|
func lookup(by type: String, actions: [Action]) -> ParametersDecoder {
|
||||||
return supportedTypes[type] ?? { decoder in
|
return supportedTypes[type] ?? { decoder in (
|
||||||
return (item: try ItemType(from: decoder), action: try ActionType(from: decoder), longAction: try LongActionType(from: decoder), parameters: [:])
|
item: try ItemType(from: decoder),
|
||||||
}
|
actions: actions,
|
||||||
|
legacyAction: try LegacyActionType(from: decoder),
|
||||||
|
legacyLongAction: try LegacyLongActionType(from: decoder),
|
||||||
|
parameters: [:]
|
||||||
|
) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func register(typename: String, decoder: @escaping ParametersDecoder) {
|
func register(typename: String, decoder: @escaping ParametersDecoder) {
|
||||||
supportedTypes[typename] = decoder
|
supportedTypes[typename] = decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
func register(typename: String, item: ItemType, action: ActionType, longAction: LongActionType) {
|
func register(typename: String, item: ItemType, actions: [Action], legacyAction: LegacyActionType, legacyLongAction: LegacyLongActionType) {
|
||||||
register(typename: typename) { _ in
|
register(typename: typename) { _ in
|
||||||
return (item: item, action: action, longAction: longAction, parameters: [:])
|
(
|
||||||
|
item: item,
|
||||||
|
actions,
|
||||||
|
legacyAction,
|
||||||
|
legacyLongAction,
|
||||||
|
parameters: [:]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ItemType: Decodable {
|
enum ItemType: Decodable {
|
||||||
case staticButton(title: String)
|
case staticButton(title: String)
|
||||||
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double, alternativeImages: [String: SourceProtocol])
|
||||||
case timeButton(formatTemplate: String)
|
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
|
||||||
case battery()
|
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
|
||||||
case dock()
|
case battery
|
||||||
case volume()
|
case cpu(refreshInterval: Double)
|
||||||
|
case dock(autoResize: Bool, filter: String?)
|
||||||
|
case volume
|
||||||
case brightness(refreshInterval: Double)
|
case brightness(refreshInterval: Double)
|
||||||
case weather(interval: Double, units: String, api_key: String, icon_type: String)
|
case weather(interval: Double, units: String, api_key: String, icon_type: String)
|
||||||
case currency(interval: Double, from: String, to: String)
|
case yandexWeather(interval: Double)
|
||||||
case inputsource()
|
case currency(interval: Double, from: String, to: String, full: Bool)
|
||||||
case music(interval: Double)
|
case inputsource
|
||||||
case groupBar(items: [BarItemDefinition])
|
case music(interval: Double, disableMarquee: Bool)
|
||||||
case nightShift()
|
case group(items: [BarItemDefinition])
|
||||||
case dnd()
|
case nightShift
|
||||||
|
case dnd
|
||||||
|
case pomodoro(workTime: Double, restTime: Double)
|
||||||
|
case network(flip: Bool, units: String)
|
||||||
|
case darkMode
|
||||||
|
case swipe(direction: String, fingers: Int, minOffset: Float, sourceApple: SourceProtocol?, sourceBash: SourceProtocol?)
|
||||||
|
case upnext(from: Double, to: Double, maxToShow: Int, autoResize: Bool)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case type
|
case type
|
||||||
@ -240,42 +286,71 @@ enum ItemType: Decodable {
|
|||||||
case refreshInterval
|
case refreshInterval
|
||||||
case from
|
case from
|
||||||
case to
|
case to
|
||||||
|
case full
|
||||||
|
case timeZone
|
||||||
case units
|
case units
|
||||||
case api_key
|
case api_key
|
||||||
case icon_type
|
case icon_type
|
||||||
case formatTemplate
|
case formatTemplate
|
||||||
|
case locale
|
||||||
case image
|
case image
|
||||||
case url
|
case url
|
||||||
case longUrl
|
case longUrl
|
||||||
case items
|
case items
|
||||||
|
case workTime
|
||||||
|
case restTime
|
||||||
|
case flip
|
||||||
|
case autoResize
|
||||||
|
case filter
|
||||||
|
case disableMarquee
|
||||||
|
case alternativeImages
|
||||||
|
case sourceApple
|
||||||
|
case sourceBash
|
||||||
|
case direction
|
||||||
|
case fingers
|
||||||
|
case minOffset
|
||||||
|
case maxToShow
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ItemTypeRaw: String, Decodable {
|
enum ItemTypeRaw: String, Decodable {
|
||||||
case staticButton
|
case staticButton
|
||||||
case appleScriptTitledButton
|
case appleScriptTitledButton
|
||||||
|
case shellScriptTitledButton
|
||||||
case timeButton
|
case timeButton
|
||||||
case battery
|
case battery
|
||||||
|
case cpu
|
||||||
case dock
|
case dock
|
||||||
case volume
|
case volume
|
||||||
case brightness
|
case brightness
|
||||||
case weather
|
case weather
|
||||||
|
case yandexWeather
|
||||||
case currency
|
case currency
|
||||||
case inputsource
|
case inputsource
|
||||||
case music
|
case music
|
||||||
case groupBar
|
case group
|
||||||
case nightShift
|
case nightShift
|
||||||
case dnd
|
case dnd
|
||||||
|
case pomodoro
|
||||||
|
case network
|
||||||
|
case darkMode
|
||||||
|
case swipe
|
||||||
|
case upnext
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
let type = try container.decode(ItemTypeRaw.self, forKey: .type)
|
let type = try container.decode(ItemTypeRaw.self, forKey: .type)
|
||||||
switch type {
|
switch type {
|
||||||
|
|
||||||
case .appleScriptTitledButton:
|
case .appleScriptTitledButton:
|
||||||
let source = try container.decode(Source.self, forKey: .source)
|
let source = try container.decode(Source.self, forKey: .source)
|
||||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
||||||
self = .appleScriptTitledButton(source: source, refreshInterval: interval)
|
let alternativeImages = try container.decodeIfPresent([String: Source].self, forKey: .alternativeImages) ?? [:]
|
||||||
|
self = .appleScriptTitledButton(source: source, refreshInterval: interval, alternativeImages: alternativeImages)
|
||||||
|
|
||||||
|
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:
|
case .staticButton:
|
||||||
let title = try container.decode(String.self, forKey: .title)
|
let title = try container.decode(String.self, forKey: .title)
|
||||||
@ -283,16 +358,24 @@ enum ItemType: Decodable {
|
|||||||
|
|
||||||
case .timeButton:
|
case .timeButton:
|
||||||
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
|
||||||
self = .timeButton(formatTemplate: template)
|
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
|
||||||
|
let locale = try container.decodeIfPresent(String.self, forKey: .locale) ?? nil
|
||||||
|
self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale)
|
||||||
|
|
||||||
case .battery:
|
case .battery:
|
||||||
self = .battery()
|
self = .battery
|
||||||
|
|
||||||
|
case .cpu:
|
||||||
|
let refreshInterval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
|
||||||
|
self = .cpu(refreshInterval: refreshInterval)
|
||||||
|
|
||||||
case .dock:
|
case .dock:
|
||||||
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:
|
case .volume:
|
||||||
self = .volume()
|
self = .volume
|
||||||
|
|
||||||
case .brightness:
|
case .brightness:
|
||||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 0.5
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 0.5
|
||||||
@ -305,39 +388,161 @@ enum ItemType: Decodable {
|
|||||||
let icon_type = try container.decodeIfPresent(String.self, forKey: .icon_type) ?? "text"
|
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)
|
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:
|
case .currency:
|
||||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 600.0
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 600.0
|
||||||
let from = try container.decodeIfPresent(String.self, forKey: .from) ?? "RUB"
|
let from = try container.decodeIfPresent(String.self, forKey: .from) ?? "RUB"
|
||||||
let to = try container.decodeIfPresent(String.self, forKey: .to) ?? "USD"
|
let to = try container.decodeIfPresent(String.self, forKey: .to) ?? "USD"
|
||||||
self = .currency(interval: interval, from: from, to: to)
|
let full = try container.decodeIfPresent(Bool.self, forKey: .full) ?? false
|
||||||
|
self = .currency(interval: interval, from: from, to: to, full: full)
|
||||||
|
|
||||||
case .inputsource:
|
case .inputsource:
|
||||||
self = .inputsource()
|
self = .inputsource
|
||||||
|
|
||||||
case .music:
|
case .music:
|
||||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 1800.0
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
|
||||||
self = .music(interval: interval)
|
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)
|
let items = try container.decode([BarItemDefinition].self, forKey: .items)
|
||||||
self = .groupBar(items: items)
|
self = .group(items: items)
|
||||||
|
|
||||||
case .nightShift:
|
case .nightShift:
|
||||||
self = .nightShift()
|
self = .nightShift
|
||||||
|
|
||||||
case .dnd:
|
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
|
||||||
|
let units = try container.decodeIfPresent(String.self, forKey: .units) ?? "dynamic"
|
||||||
|
self = .network(flip: flip, units: units)
|
||||||
|
|
||||||
|
case .darkMode:
|
||||||
|
self = .darkMode
|
||||||
|
|
||||||
|
case .swipe:
|
||||||
|
let sourceApple = try container.decodeIfPresent(Source.self, forKey: .sourceApple)
|
||||||
|
let sourceBash = try container.decodeIfPresent(Source.self, forKey: .sourceBash)
|
||||||
|
let direction = try container.decode(String.self, forKey: .direction)
|
||||||
|
let fingers = try container.decode(Int.self, forKey: .fingers)
|
||||||
|
let minOffset = try container.decodeIfPresent(Float.self, forKey: .minOffset) ?? 0.0
|
||||||
|
self = .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
||||||
|
|
||||||
|
case .upnext:
|
||||||
|
let from = try container.decodeIfPresent(Double.self, forKey: .from) ?? 0 // Lower bounds of period of time in hours to search for events
|
||||||
|
let to = try container.decodeIfPresent(Double.self, forKey: .to) ?? 12 // Upper bounds of period of time in hours to search for events
|
||||||
|
let maxToShow = try container.decodeIfPresent(Int.self, forKey: .maxToShow) ?? 3 // 1 indexed array. Get the 1st, 2nd, 3rd event to display multiple notifications
|
||||||
|
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
|
||||||
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 60.0
|
||||||
|
self = .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ActionType: Decodable {
|
struct FailableDecodable<Base : Decodable> : Decodable {
|
||||||
|
|
||||||
|
let base: Base?
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.singleValueContainer()
|
||||||
|
self.base = try? container.decode(Base.self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Action: Decodable {
|
||||||
|
enum Trigger: String, Decodable {
|
||||||
|
case singleTap
|
||||||
|
case doubleTap
|
||||||
|
case tripleTap
|
||||||
|
case longTap
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Value {
|
||||||
case none
|
case none
|
||||||
case hidKey(keycode: Int32)
|
case hidKey(keycode: Int32)
|
||||||
case keyPress(keycode: Int)
|
case keyPress(keycode: Int)
|
||||||
case appleScript(source: SourceProtocol)
|
case appleScript(source: SourceProtocol)
|
||||||
case shellScript(executable: String, parameters: [String])
|
case shellScript(executable: String, parameters: [String])
|
||||||
case custom(closure: ()->())
|
case custom(closure: () -> Void)
|
||||||
|
case openUrl(url: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum ActionTypeRaw: String, Decodable {
|
||||||
|
case hidKey
|
||||||
|
case keyPress
|
||||||
|
case appleScript
|
||||||
|
case shellScript
|
||||||
|
case openUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case trigger
|
||||||
|
case action
|
||||||
|
case keycode
|
||||||
|
case actionAppleScript
|
||||||
|
case executablePath
|
||||||
|
case shellArguments
|
||||||
|
case url
|
||||||
|
}
|
||||||
|
|
||||||
|
let trigger: Trigger
|
||||||
|
let value: Value
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
|
trigger = try container.decode(Trigger.self, forKey: .trigger)
|
||||||
|
let type = try container.decodeIfPresent(ActionTypeRaw.self, forKey: .action)
|
||||||
|
|
||||||
|
switch type {
|
||||||
|
case .some(.hidKey):
|
||||||
|
let keycode = try container.decode(Int32.self, forKey: .keycode)
|
||||||
|
value = .hidKey(keycode: keycode)
|
||||||
|
|
||||||
|
case .some(.keyPress):
|
||||||
|
let keycode = try container.decode(Int.self, forKey: .keycode)
|
||||||
|
value = .keyPress(keycode: keycode)
|
||||||
|
|
||||||
|
case .some(.appleScript):
|
||||||
|
let source = try container.decode(Source.self, forKey: .actionAppleScript)
|
||||||
|
value = .appleScript(source: source)
|
||||||
|
|
||||||
|
case .some(.shellScript):
|
||||||
|
let executable = try container.decode(String.self, forKey: .executablePath)
|
||||||
|
let parameters = try container.decodeIfPresent([String].self, forKey: .shellArguments) ?? []
|
||||||
|
value = .shellScript(executable: executable, parameters: parameters)
|
||||||
|
|
||||||
|
case .some(.openUrl):
|
||||||
|
let url = try container.decode(String.self, forKey: .url)
|
||||||
|
value = .openUrl(url: url)
|
||||||
|
case .none:
|
||||||
|
value = .none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(trigger: Trigger, value: Value) {
|
||||||
|
self.trigger = trigger
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LegacyActionType: Decodable {
|
||||||
|
case none
|
||||||
|
case hidKey(keycode: Int32)
|
||||||
|
case keyPress(keycode: Int)
|
||||||
|
case appleScript(source: SourceProtocol)
|
||||||
|
case shellScript(executable: String, parameters: [String])
|
||||||
|
case custom(closure: () -> Void)
|
||||||
case openUrl(url: String)
|
case openUrl(url: String)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -389,14 +594,13 @@ enum ActionType: Decodable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LegacyLongActionType: Decodable {
|
||||||
enum LongActionType: Decodable {
|
|
||||||
case none
|
case none
|
||||||
case hidKey(keycode: Int32)
|
case hidKey(keycode: Int32)
|
||||||
case keyPress(keycode: Int)
|
case keyPress(keycode: Int)
|
||||||
case appleScript(source: SourceProtocol)
|
case appleScript(source: SourceProtocol)
|
||||||
case shellScript(executable: String, parameters: [String])
|
case shellScript(executable: String, parameters: [String])
|
||||||
case custom(closure: ()->())
|
case custom(closure: () -> Void)
|
||||||
case openUrl(url: String)
|
case openUrl(url: String)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
@ -448,7 +652,6 @@ enum LongActionType: Decodable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum GeneralParameter {
|
enum GeneralParameter {
|
||||||
case width(_: CGFloat)
|
case width(_: CGFloat)
|
||||||
case image(source: SourceProtocol)
|
case image(source: SourceProtocol)
|
||||||
@ -456,6 +659,7 @@ enum GeneralParameter {
|
|||||||
case bordered(_: Bool)
|
case bordered(_: Bool)
|
||||||
case background(_: NSColor)
|
case background(_: NSColor)
|
||||||
case title(_: String)
|
case title(_: String)
|
||||||
|
case matchAppId(_: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GeneralParameters: Decodable {
|
struct GeneralParameters: Decodable {
|
||||||
@ -468,6 +672,7 @@ struct GeneralParameters: Decodable {
|
|||||||
case bordered
|
case bordered
|
||||||
case background
|
case background
|
||||||
case title
|
case title
|
||||||
|
case matchAppId
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
@ -497,6 +702,10 @@ struct GeneralParameters: Decodable {
|
|||||||
result[.title] = .title(title)
|
result[.title] = .title(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let matchAppId = try container.decodeIfPresent(String.self, forKey: .matchAppId) {
|
||||||
|
result[.matchAppId] = .matchAppId(matchAppId)
|
||||||
|
}
|
||||||
|
|
||||||
parameters = result
|
parameters = result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,7 +741,7 @@ struct Source: Decodable, SourceProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var appleScript: NSAppleScript? {
|
var appleScript: NSAppleScript? {
|
||||||
return filePath?.fileURL.appleScript ?? self.string?.appleScript
|
return filePath?.fileURL.appleScript ?? string?.appleScript
|
||||||
}
|
}
|
||||||
|
|
||||||
private init(filePath: String?, base64: String?, inline: String?) {
|
private init(filePath: String?, base64: String?, inline: String?) {
|
||||||
@ -570,14 +779,21 @@ extension String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileData: Data? {
|
var fileData: Data? {
|
||||||
return try? Data(contentsOf: URL(fileURLWithPath: self))
|
return try? Data(contentsOf: URL(fileURLWithPath: (self as NSString).expandingTildeInPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileString: String? {
|
var fileString: String? {
|
||||||
var encoding: String.Encoding = .utf8
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Data {
|
extension Data {
|
||||||
@ -596,19 +812,9 @@ enum Align: String, Decodable {
|
|||||||
case right
|
case right
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
|
||||||
var fileURL: URL {
|
|
||||||
return URL(fileURLWithPath: self)
|
|
||||||
}
|
|
||||||
|
|
||||||
var appleScript: NSAppleScript? {
|
|
||||||
return NSAppleScript(source: self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension URL {
|
extension URL {
|
||||||
var appleScript: NSAppleScript? {
|
var appleScript: NSAppleScript? {
|
||||||
guard FileManager.default.fileExists(atPath: self.path) else { return nil }
|
guard FileManager.default.fileExists(atPath: path) else { return nil }
|
||||||
return NSAppleScript(contentsOf: self, error: nil)
|
return NSAppleScript(contentsOf: self, error: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
class ScrollViewItem: NSCustomTouchBarItem/*, NSGestureRecognizerDelegate*/ {
|
||||||
var twofingersPrev: CGFloat = 0.0
|
|
||||||
var threefingersPrev: CGFloat = 0.0
|
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem]) {
|
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem]) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
@ -12,64 +10,11 @@ class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
|||||||
stackView.orientation = .horizontal
|
stackView.orientation = .horizontal
|
||||||
let scrollView = NSScrollView(frame: CGRect(origin: .zero, size: stackView.fittingSize))
|
let scrollView = NSScrollView(frame: CGRect(origin: .zero, size: stackView.fittingSize))
|
||||||
scrollView.documentView = stackView
|
scrollView.documentView = stackView
|
||||||
self.view = scrollView
|
view = scrollView
|
||||||
|
|
||||||
let twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
|
||||||
twofingers.allowedTouchTypes = .direct
|
|
||||||
twofingers.numberOfTouchesRequired = 2
|
|
||||||
self.view.addGestureRecognizer(twofingers)
|
|
||||||
|
|
||||||
let threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
|
||||||
threefingers.allowedTouchTypes = .direct
|
|
||||||
threefingers.numberOfTouchesRequired = 3
|
|
||||||
self.view.addGestureRecognizer(threefingers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func twofingersHandler(_ sender: NSGestureRecognizer?) { // Volume
|
|
||||||
let position = (sender?.location(in: sender?.view).x)!
|
|
||||||
|
|
||||||
switch sender!.state {
|
|
||||||
case .began:
|
|
||||||
twofingersPrev = position
|
|
||||||
case .changed:
|
|
||||||
if (((position-twofingersPrev) > 10) || ((twofingersPrev-position) > 10)) {
|
|
||||||
if position > twofingersPrev {
|
|
||||||
HIDPostAuxKey(NX_KEYTYPE_SOUND_UP)
|
|
||||||
} else if position < twofingersPrev {
|
|
||||||
HIDPostAuxKey(NX_KEYTYPE_SOUND_DOWN)
|
|
||||||
}
|
|
||||||
twofingersPrev = position
|
|
||||||
}
|
|
||||||
case .ended:
|
|
||||||
twofingersPrev = 0.0
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func threefingersHandler(_ sender: NSGestureRecognizer?) { // Brightness
|
|
||||||
let position = (sender?.location(in: sender?.view).x)!
|
|
||||||
|
|
||||||
switch sender!.state {
|
|
||||||
case .began:
|
|
||||||
threefingersPrev = position
|
|
||||||
case .changed:
|
|
||||||
if (((position-threefingersPrev) > 15) || ((threefingersPrev-position) > 15)) {
|
|
||||||
if position > threefingersPrev {
|
|
||||||
GenericKeyPress(keyCode: CGKeyCode(144)).send()
|
|
||||||
} else if position < threefingersPrev {
|
|
||||||
GenericKeyPress(keyCode: CGKeyCode(145)).send()
|
|
||||||
}
|
|
||||||
threefingersPrev = position
|
|
||||||
}
|
|
||||||
case .ended:
|
|
||||||
threefingersPrev = 0.0
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
113
MTMR/ShellScriptTouchBarItem.swift
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
//
|
||||||
|
// 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!
|
||||||
|
|
||||||
|
struct ScriptResult: Decodable {
|
||||||
|
var title: String?
|
||||||
|
var image: Source?
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
var rawTitle: String, image: NSImage?
|
||||||
|
var json: Bool
|
||||||
|
|
||||||
|
do {
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
let result = try decoder.decode(ScriptResult.self, from: scriptResult.data(using: .utf8)!)
|
||||||
|
json = true
|
||||||
|
rawTitle = result.title ?? ""
|
||||||
|
image = result.image?.image
|
||||||
|
} catch {
|
||||||
|
json = false
|
||||||
|
rawTitle = scriptResult
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply returned text attributes (if they were returned) to our result string
|
||||||
|
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: rawTitle) ?? 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
|
||||||
|
if json {
|
||||||
|
self?.image = image
|
||||||
|
}
|
||||||
|
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()
|
||||||
|
if let shell = getenv("SHELL") {
|
||||||
|
task.launchPath = String.init(cString: shell)
|
||||||
|
} else {
|
||||||
|
task.launchPath = "/bin/bash"
|
||||||
|
}
|
||||||
|
task.arguments = ["-c", command]
|
||||||
|
|
||||||
|
let pipe = Pipe()
|
||||||
|
task.standardOutput = pipe
|
||||||
|
|
||||||
|
// kill process if it is over update interval
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + interval) { [weak task] in
|
||||||
|
task?.terminate()
|
||||||
|
}
|
||||||
|
|
||||||
|
task.launch()
|
||||||
|
|
||||||
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
var output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as String? ?? ""
|
||||||
|
|
||||||
|
//always wait until task end or you can catch "task still running" error while accessing task.terminationStatus variable
|
||||||
|
task.waitUntilExit()
|
||||||
|
if (output == "" && task.terminationStatus != 0) {
|
||||||
|
output = "error"
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.replacingOccurrences(of: "\\n+$", with: "", options: .regularExpression)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension DispatchQueue {
|
||||||
|
static let shellScriptQueue = DispatchQueue(label: "mtmr.shellscript")
|
||||||
|
}
|
||||||
@ -6,17 +6,17 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import AppKit
|
import AppKit
|
||||||
|
import Foundation
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
func trim() -> String {
|
func trim() -> String {
|
||||||
return self.trimmingCharacters(in: NSCharacterSet.whitespaces)
|
return trimmingCharacters(in: NSCharacterSet.whitespaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripComments() -> String {
|
func stripComments() -> String {
|
||||||
// ((\s|,)\/\*[\s\S]*?\*\/)|(( |, ")\/\/.*)
|
// ((\s|,)\/\*[\s\S]*?\*\/)|(( |, ")\/\/.*)
|
||||||
return self.replacingOccurrences(of: "((\\s|,)\\/\\*[\\s\\S]*?\\*\\/)|(( |, \\\")\\/\\/.*)", with: "", options: .regularExpression)
|
return replacingOccurrences(of: "((\\s|,)\\/\\*[\\s\\S]*?\\*\\/)|(( |, \\\")\\/\\/.*)", with: "", options: .regularExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hexColor: NSColor? {
|
var hexColor: NSColor? {
|
||||||
@ -41,19 +41,18 @@ extension String {
|
|||||||
extension NSImage {
|
extension NSImage {
|
||||||
func resize(maxSize: NSSize) -> NSImage {
|
func resize(maxSize: NSSize) -> NSImage {
|
||||||
var ratio: Float = 0.0
|
var ratio: Float = 0.0
|
||||||
let imageWidth = Float(self.size.width)
|
let imageWidth = Float(size.width)
|
||||||
let imageHeight = Float(self.size.height)
|
let imageHeight = Float(size.height)
|
||||||
let maxWidth = Float(maxSize.width)
|
let maxWidth = Float(maxSize.width)
|
||||||
let maxHeight = Float(maxSize.height)
|
let maxHeight = Float(maxSize.height)
|
||||||
|
|
||||||
// Get ratio (landscape or portrait)
|
// Get ratio (landscape or portrait)
|
||||||
if (imageWidth > imageHeight) {
|
if imageWidth > imageHeight {
|
||||||
// Landscape
|
// Landscape
|
||||||
ratio = maxWidth / imageWidth;
|
ratio = maxWidth / imageWidth
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Portrait
|
// Portrait
|
||||||
ratio = maxHeight / imageHeight;
|
ratio = maxHeight / imageHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate new size based on the ratio
|
// Calculate new size based on the ratio
|
||||||
@ -64,8 +63,8 @@ extension NSImage {
|
|||||||
let newSize: NSSize = NSSize(width: Int(newWidth), height: Int(newHeight))
|
let newSize: NSSize = NSSize(width: Int(newWidth), height: Int(newHeight))
|
||||||
|
|
||||||
// Cast the NSImage to a CGImage
|
// Cast the NSImage to a CGImage
|
||||||
var imageRect:NSRect = NSMakeRect(0, 0, self.size.width, self.size.height)
|
var imageRect: NSRect = NSMakeRect(0, 0, size.width, size.height)
|
||||||
let imageRef = self.cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
|
let imageRef = cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
|
||||||
|
|
||||||
// Create NSImage from the CGImage using the new size
|
// Create NSImage from the CGImage using the new size
|
||||||
let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize)
|
let imageWithNewSize = NSImage(cgImage: imageRef!, size: newSize)
|
||||||
@ -75,13 +74,12 @@ extension NSImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rotateByDegreess(degrees: CGFloat) -> NSImage {
|
func rotateByDegreess(degrees: CGFloat) -> NSImage {
|
||||||
|
var imageBounds = NSZeroRect; imageBounds.size = size
|
||||||
var imageBounds = NSZeroRect ; imageBounds.size = self.size
|
|
||||||
let pathBounds = NSBezierPath(rect: imageBounds)
|
let pathBounds = NSBezierPath(rect: imageBounds)
|
||||||
var transform = NSAffineTransform()
|
var transform = NSAffineTransform()
|
||||||
transform.rotate(byDegrees: degrees)
|
transform.rotate(byDegrees: degrees)
|
||||||
pathBounds.transform(using: transform as AffineTransform)
|
pathBounds.transform(using: transform as AffineTransform)
|
||||||
let rotatedBounds:NSRect = NSMakeRect(NSZeroPoint.x, NSZeroPoint.y , self.size.width, self.size.height )
|
let rotatedBounds: NSRect = NSMakeRect(NSZeroPoint.x, NSZeroPoint.y, size.width, size.height)
|
||||||
let rotatedImage = NSImage(size: rotatedBounds.size)
|
let rotatedImage = NSImage(size: rotatedBounds.size)
|
||||||
|
|
||||||
// Center the image within the rotated bounds
|
// Center the image within the rotated bounds
|
||||||
@ -98,10 +96,9 @@ extension NSImage {
|
|||||||
// Draw the original image, rotated, into the new image
|
// Draw the original image, rotated, into the new image
|
||||||
rotatedImage.lockFocus()
|
rotatedImage.lockFocus()
|
||||||
transform.concat()
|
transform.concat()
|
||||||
self.draw(in: imageBounds, from: NSZeroRect, operation: NSCompositingOperation.copy, fraction: 1.0)
|
draw(in: imageBounds, from: NSZeroRect, operation: NSCompositingOperation.copy, fraction: 1.0)
|
||||||
rotatedImage.unlockFocus()
|
rotatedImage.unlockFocus()
|
||||||
|
|
||||||
return rotatedImage
|
return rotatedImage
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
func presentSystemModal(_ touchBar: NSTouchBar!, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) -> Void {
|
func presentSystemModal(_ touchBar: NSTouchBar!, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) {
|
||||||
if #available(OSX 10.14, *) {
|
if #available(OSX 10.14, *) {
|
||||||
NSTouchBar.presentSystemModalTouchBar(touchBar, systemTrayItemIdentifier: identifier)
|
NSTouchBar.presentSystemModalTouchBar(touchBar, systemTrayItemIdentifier: identifier)
|
||||||
} else {
|
} else {
|
||||||
@ -14,7 +14,7 @@ func presentSystemModal(_ touchBar: NSTouchBar!, systemTrayItemIdentifier identi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentSystemModal(_ touchBar: NSTouchBar!, placement: Int64, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) -> Void {
|
func presentSystemModal(_ touchBar: NSTouchBar!, placement: Int64, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) {
|
||||||
if #available(OSX 10.14, *) {
|
if #available(OSX 10.14, *) {
|
||||||
NSTouchBar.presentSystemModalTouchBar(touchBar, placement: placement, systemTrayItemIdentifier: identifier)
|
NSTouchBar.presentSystemModalTouchBar(touchBar, placement: placement, systemTrayItemIdentifier: identifier)
|
||||||
} else {
|
} else {
|
||||||
@ -22,7 +22,7 @@ func presentSystemModal(_ touchBar: NSTouchBar!, placement: Int64, systemTrayIte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minimizeSystemModal(_ touchBar: NSTouchBar!) -> Void {
|
func minimizeSystemModal(_ touchBar: NSTouchBar!) {
|
||||||
if #available(OSX 10.14, *) {
|
if #available(OSX 10.14, *) {
|
||||||
NSTouchBar.minimizeSystemModalTouchBar(touchBar)
|
NSTouchBar.minimizeSystemModalTouchBar(touchBar)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
78
MTMR/SwipeItem.swift
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
//
|
||||||
|
// SwipeItem.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Fedor Zaitsev on 3/29/20.
|
||||||
|
// Copyright © 2020 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class SwipeItem: NSCustomTouchBarItem {
|
||||||
|
private var scriptApple: NSAppleScript?
|
||||||
|
private var scriptBash: String?
|
||||||
|
private var direction: String
|
||||||
|
private var fingers: Int
|
||||||
|
private var minOffset: Float
|
||||||
|
init?(identifier: NSTouchBarItem.Identifier, direction: String, fingers: Int, minOffset: Float, sourceApple: SourceProtocol?, sourceBash: SourceProtocol?) {
|
||||||
|
self.direction = direction
|
||||||
|
self.fingers = fingers
|
||||||
|
self.scriptBash = sourceBash?.string
|
||||||
|
self.scriptApple = sourceApple?.appleScript
|
||||||
|
self.minOffset = minOffset
|
||||||
|
super.init(identifier: identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func processEvent(offset: CGFloat, fingers: Int) {
|
||||||
|
if direction == "right" && Float(offset) > self.minOffset && self.fingers == fingers {
|
||||||
|
self.execute()
|
||||||
|
}
|
||||||
|
if direction == "left" && Float(offset) < -self.minOffset && self.fingers == fingers {
|
||||||
|
self.execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func execute() {
|
||||||
|
if scriptApple != nil {
|
||||||
|
DispatchQueue.appleScriptQueue.async {
|
||||||
|
var error: NSDictionary?
|
||||||
|
self.scriptApple?.executeAndReturnError(&error)
|
||||||
|
if let error = error {
|
||||||
|
print("SwipeItem apple script error: \(error)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if scriptBash != nil {
|
||||||
|
DispatchQueue.shellScriptQueue.async {
|
||||||
|
let task = Process()
|
||||||
|
if let shell = getenv("SHELL") {
|
||||||
|
task.launchPath = String.init(cString: shell)
|
||||||
|
} else {
|
||||||
|
task.launchPath = "/bin/bash"
|
||||||
|
}
|
||||||
|
task.arguments = ["-c", self.scriptBash!]
|
||||||
|
task.launch()
|
||||||
|
task.waitUntilExit()
|
||||||
|
|
||||||
|
|
||||||
|
if (task.terminationStatus != 0) {
|
||||||
|
print("SwipeItem bash script error. Status: \(task.terminationStatus)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isEqual(_ object: AnyObject?) -> Bool {
|
||||||
|
if let object = object as? SwipeItem {
|
||||||
|
return self.scriptApple?.source as String? == object.scriptApple?.source as String? && self.scriptBash == object.scriptBash && self.direction == object.direction && self.fingers == object.fingers && self.minOffset == object.minOffset
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,40 +17,54 @@ let appSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSuppor
|
|||||||
let standardConfigPath = appSupportDirectory.appending("/items.json")
|
let standardConfigPath = appSupportDirectory.appending("/items.json")
|
||||||
|
|
||||||
extension ItemType {
|
extension ItemType {
|
||||||
|
|
||||||
var identifierBase: String {
|
var identifierBase: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .staticButton(title: _):
|
case .staticButton(title: _):
|
||||||
return "com.toxblh.mtmr.staticButton."
|
return "com.toxblh.mtmr.staticButton."
|
||||||
case .appleScriptTitledButton(source: _):
|
case .appleScriptTitledButton(source: _):
|
||||||
return "com.toxblh.mtmr.appleScriptButton."
|
return "com.toxblh.mtmr.appleScriptButton."
|
||||||
case .timeButton(formatTemplate: _):
|
case .shellScriptTitledButton(source: _):
|
||||||
|
return "com.toxblh.mtmr.shellScriptButton."
|
||||||
|
case .timeButton(formatTemplate: _, timeZone: _, locale: _):
|
||||||
return "com.toxblh.mtmr.timeButton."
|
return "com.toxblh.mtmr.timeButton."
|
||||||
case .battery():
|
case .battery:
|
||||||
return "com.toxblh.mtmr.battery."
|
return "com.toxblh.mtmr.battery."
|
||||||
case .dock():
|
case .cpu(refreshInterval: _):
|
||||||
|
return "com.toxblh.mtmr.cpu."
|
||||||
|
case .dock(autoResize: _, filter: _):
|
||||||
return "com.toxblh.mtmr.dock"
|
return "com.toxblh.mtmr.dock"
|
||||||
case .volume():
|
case .volume:
|
||||||
return "com.toxblh.mtmr.volume"
|
return "com.toxblh.mtmr.volume"
|
||||||
case .brightness(refreshInterval: _):
|
case .brightness(refreshInterval: _):
|
||||||
return "com.toxblh.mtmr.brightness"
|
return "com.toxblh.mtmr.brightness"
|
||||||
case .weather(interval: _, units: _, api_key: _, icon_type: _):
|
case .weather(interval: _, units: _, api_key: _, icon_type: _):
|
||||||
return "com.toxblh.mtmr.weather"
|
return "com.toxblh.mtmr.weather"
|
||||||
case .currency(interval: _, from: _, to: _):
|
case .yandexWeather(interval: _):
|
||||||
|
return "com.toxblh.mtmr.yandexWeather"
|
||||||
|
case .currency(interval: _, from: _, to: _, full: _):
|
||||||
return "com.toxblh.mtmr.currency"
|
return "com.toxblh.mtmr.currency"
|
||||||
case .inputsource():
|
case .inputsource:
|
||||||
return "com.toxblh.mtmr.inputsource."
|
return "com.toxblh.mtmr.inputsource."
|
||||||
case .music(interval: _):
|
case .music(interval: _):
|
||||||
return "com.toxblh.mtmr.music."
|
return "com.toxblh.mtmr.music."
|
||||||
case .groupBar(items: _):
|
case .group(items: _):
|
||||||
return "com.toxblh.mtmr.groupBar."
|
return "com.toxblh.mtmr.groupBar."
|
||||||
case .nightShift(items: _):
|
case .nightShift:
|
||||||
return "com.toxblh.mtmr.nightShift."
|
return "com.toxblh.mtmr.nightShift."
|
||||||
case .dnd(items: _):
|
case .dnd:
|
||||||
return "com.toxblh.mtmr.dnd."
|
return "com.toxblh.mtmr.dnd."
|
||||||
|
case .pomodoro(interval: _):
|
||||||
|
return PomodoroBarItem.identifier
|
||||||
|
case .network(flip: _):
|
||||||
|
return NetworkBarItem.identifier
|
||||||
|
case .darkMode:
|
||||||
|
return DarkModeBarItem.identifier
|
||||||
|
case .swipe(direction: _, fingers: _, minOffset: _, sourceApple: _, sourceBash: _):
|
||||||
|
return "com.toxblh.mtmr.swipe."
|
||||||
|
case .upnext(from: _, to: _, maxToShow: _, autoResize: _):
|
||||||
|
return "com.connorgmeehan.mtmrup.next."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension NSTouchBarItem.Identifier {
|
extension NSTouchBarItem.Identifier {
|
||||||
@ -58,7 +72,6 @@ extension NSTouchBarItem.Identifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TouchBarController: NSObject, NSTouchBarDelegate {
|
class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||||
|
|
||||||
static let shared = TouchBarController()
|
static let shared = TouchBarController()
|
||||||
|
|
||||||
var touchBar: NSTouchBar!
|
var touchBar: NSTouchBar!
|
||||||
@ -69,44 +82,43 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
var items: [NSTouchBarItem.Identifier: NSTouchBarItem] = [:]
|
var items: [NSTouchBarItem.Identifier: NSTouchBarItem] = [:]
|
||||||
var leftIdentifiers: [NSTouchBarItem.Identifier] = []
|
var leftIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||||
var centerIdentifiers: [NSTouchBarItem.Identifier] = []
|
var centerIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||||
var centerItems: [NSTouchBarItem] = []
|
|
||||||
var rightIdentifiers: [NSTouchBarItem.Identifier] = []
|
var rightIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||||
var scrollArea: NSCustomTouchBarItem?
|
var basicViewIdentifier = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollView.".appending(UUID().uuidString))
|
||||||
var centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
var basicView: BasicView?
|
||||||
|
var swipeItems: [SwipeItem] = []
|
||||||
var controlStripState: Bool {
|
|
||||||
get {
|
|
||||||
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
UserDefaults.standard.set(!controlStripState, forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var touchbarNeedRefresh: Bool = true
|
|
||||||
|
|
||||||
var blacklistAppIdentifiers: [String] = []
|
var blacklistAppIdentifiers: [String] = []
|
||||||
var frontmostApplicationIdentifier: String? {
|
var frontmostApplicationIdentifier: String? {
|
||||||
get {
|
return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
|
||||||
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
|
|
||||||
return frontmostId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private override init() {
|
private override init() {
|
||||||
super.init()
|
super.init()
|
||||||
SupportedTypesHolder.sharedInstance.register(typename: "exitTouchbar", item: .staticButton(title: "exit"), action: .custom(closure: { [weak self] in self?.dismissTouchBar()}), longAction: .none)
|
SupportedTypesHolder.sharedInstance.register(
|
||||||
|
typename: "exitTouchbar",
|
||||||
|
item: .staticButton(title: "exit"),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .custom(closure: { [weak self] in self?.dismissTouchBar() }))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none
|
||||||
|
)
|
||||||
|
|
||||||
SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in
|
SupportedTypesHolder.sharedInstance.register(typename: "close") { _ in
|
||||||
return (item: .staticButton(title: ""), action: .custom(closure: { [weak self] in
|
(
|
||||||
|
item: .staticButton(title: ""),
|
||||||
|
actions: [
|
||||||
|
Action(trigger: .singleTap, value: .custom(closure: { [weak self] in
|
||||||
guard let `self` = self else { return }
|
guard let `self` = self else { return }
|
||||||
self.reloadPreset(path: self.lastPresetPath)
|
self.reloadPreset(path: self.lastPresetPath)
|
||||||
}), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: .stopProgressFreestandingTemplate))!)])
|
}))
|
||||||
|
],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
|
||||||
}
|
}
|
||||||
|
|
||||||
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
|
blacklistAppIdentifiers = AppSettings.blacklistedAppIds
|
||||||
self.blacklistAppIdentifiers = blackListed
|
|
||||||
}
|
|
||||||
|
|
||||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||||
@ -119,44 +131,94 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
if let oldBar = self.touchBar {
|
if let oldBar = self.touchBar {
|
||||||
minimizeSystemModal(oldBar)
|
minimizeSystemModal(oldBar)
|
||||||
}
|
}
|
||||||
self.touchBar = NSTouchBar()
|
touchBar = NSTouchBar()
|
||||||
self.jsonItems = newJsonItems
|
jsonItems = newJsonItems
|
||||||
self.itemDefinitions = [:]
|
itemDefinitions = [:]
|
||||||
self.items = [:]
|
|
||||||
self.leftIdentifiers = []
|
|
||||||
self.centerItems = []
|
|
||||||
self.rightIdentifiers = []
|
|
||||||
|
|
||||||
loadItemDefinitions(jsonItems: self.jsonItems)
|
loadItemDefinitions(jsonItems: jsonItems)
|
||||||
createItems()
|
|
||||||
|
|
||||||
centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
updateActiveApp()
|
||||||
return items[identifier]
|
|
||||||
})
|
|
||||||
|
|
||||||
self.centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
|
||||||
self.scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
|
||||||
|
|
||||||
touchBar.delegate = self
|
|
||||||
touchBar.defaultItemIdentifiers = []
|
|
||||||
touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers
|
|
||||||
|
|
||||||
self.updateActiveApp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func activeApplicationChanged(_ n: Notification) {
|
func didItemsChange(prevItems: [NSTouchBarItem.Identifier: NSTouchBarItem], prevSwipeItems: [SwipeItem]) -> Bool {
|
||||||
|
var changed = items.count != prevItems.count || swipeItems.count != prevSwipeItems.count
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
for (item, prevItem) in zip(items, prevItems) {
|
||||||
|
if item.key != prevItem.key {
|
||||||
|
changed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
for (swipeItem, prevSwipeItem) in zip(swipeItems, prevSwipeItems) {
|
||||||
|
if !swipeItem.isEqual(prevSwipeItem) {
|
||||||
|
changed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepareTouchBar() {
|
||||||
|
let prevItems = items
|
||||||
|
let prevSwipeItems = swipeItems
|
||||||
|
|
||||||
|
createItems()
|
||||||
|
|
||||||
|
let changed = didItemsChange(prevItems: prevItems, prevSwipeItems: prevSwipeItems)
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
|
items[identifier]
|
||||||
|
})
|
||||||
|
|
||||||
|
let centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||||
|
let scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
||||||
|
|
||||||
|
basicViewIdentifier = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollView.".appending(UUID().uuidString))
|
||||||
|
|
||||||
|
touchBar.delegate = self
|
||||||
|
touchBar.defaultItemIdentifiers = [basicViewIdentifier]
|
||||||
|
|
||||||
|
let leftItems = leftIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
|
items[identifier]
|
||||||
|
})
|
||||||
|
let rightItems = rightIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
|
items[identifier]
|
||||||
|
})
|
||||||
|
|
||||||
|
basicView = BasicView(identifier: basicViewIdentifier, items:leftItems + [scrollArea] + rightItems, swipeItems: swipeItems)
|
||||||
|
basicView?.legacyGesturesEnabled = AppSettings.multitouchGestures
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func activeApplicationChanged(_: Notification) {
|
||||||
updateActiveApp()
|
updateActiveApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateActiveApp() {
|
func updateActiveApp() {
|
||||||
if self.blacklistAppIdentifiers.index(of: self.frontmostApplicationIdentifier!) != nil {
|
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil {
|
||||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, false)
|
dismissTouchBar()
|
||||||
self.touchbarNeedRefresh = true
|
|
||||||
} else {
|
} else {
|
||||||
|
prepareTouchBar()
|
||||||
|
if touchBarContainsAnyItems() {
|
||||||
presentTouchBar()
|
presentTouchBar()
|
||||||
self.touchbarNeedRefresh = false
|
} else {
|
||||||
|
dismissTouchBar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func touchBarContainsAnyItems() -> Bool {
|
||||||
|
return items.count != 0 || swipeItems.count != 0
|
||||||
|
}
|
||||||
|
|
||||||
func reloadStandardConfig() {
|
func reloadStandardConfig() {
|
||||||
let presetPath = standardConfigPath
|
let presetPath = standardConfigPath
|
||||||
@ -171,8 +233,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
|
|
||||||
func reloadPreset(path: String) {
|
func reloadPreset(path: String) {
|
||||||
lastPresetPath = path
|
lastPresetPath = path
|
||||||
let items = path.fileData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), action: .none, longAction: .none, additionalParameters: [:])]
|
let items = path.fileData?.barItemDefinitions() ?? [BarItemDefinition(type: .staticButton(title: "bad preset"), actions: [], action: .none, legacyLongAction: .none, additionalParameters: [:])]
|
||||||
touchbarNeedRefresh = true
|
|
||||||
createAndUpdatePreset(newJsonItems: items)
|
createAndUpdatePreset(newJsonItems: items)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,8 +258,30 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createItems() {
|
func createItems() {
|
||||||
for (identifier, definition) in self.itemDefinitions {
|
items = [:]
|
||||||
self.items[identifier] = self.createItem(forIdentifier: identifier, definition: definition)
|
swipeItems = []
|
||||||
|
|
||||||
|
for (identifier, definition) in itemDefinitions {
|
||||||
|
var show = true
|
||||||
|
|
||||||
|
if let frontApp = frontmostApplicationIdentifier {
|
||||||
|
if case let .matchAppId(regexString)? = definition.additionalParameters[.matchAppId] {
|
||||||
|
let regex = try! NSRegularExpression(pattern: regexString)
|
||||||
|
let range = NSRange(location: 0, length: frontApp.count)
|
||||||
|
if regex.firstMatch(in: frontApp, range: range) == nil {
|
||||||
|
show = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if show {
|
||||||
|
let item = createItem(forIdentifier: identifier, definition: definition)
|
||||||
|
if item is SwipeItem {
|
||||||
|
swipeItems.append(item as! SwipeItem)
|
||||||
|
} else {
|
||||||
|
items[identifier] = item
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,107 +290,133 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
let item = NSCustomTouchBarItem(identifier: .controlStripItem)
|
let item = NSCustomTouchBarItem(identifier: .controlStripItem)
|
||||||
item.view = NSButton(image: #imageLiteral(resourceName: "StatusImage"), target: self, action: #selector(presentTouchBar))
|
item.view = NSButton(image: #imageLiteral(resourceName: "StatusImage"), target: self, action: #selector(presentTouchBar))
|
||||||
NSTouchBarItem.addSystemTrayItem(item)
|
NSTouchBarItem.addSystemTrayItem(item)
|
||||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
updateControlStripPresence()
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateControlStripPresence() {
|
func updateControlStripPresence() {
|
||||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
let showMtmrButtonOnControlStrip = touchBarContainsAnyItems()
|
||||||
|
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, showMtmrButtonOnControlStrip)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func presentTouchBar() {
|
@objc private func presentTouchBar() {
|
||||||
if touchbarNeedRefresh {
|
if AppSettings.showControlStripState {
|
||||||
if self.controlStripState {
|
|
||||||
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||||
} else {
|
} else {
|
||||||
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||||
}
|
}
|
||||||
}
|
updateControlStripPresence()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func dismissTouchBar() {
|
@objc private func dismissTouchBar() {
|
||||||
self.touchbarNeedRefresh = true
|
if touchBarContainsAnyItems() {
|
||||||
minimizeSystemModal(touchBar)
|
minimizeSystemModal(touchBar)
|
||||||
}
|
}
|
||||||
|
updateControlStripPresence()
|
||||||
|
}
|
||||||
|
|
||||||
@objc func resetControlStrip() {
|
@objc func resetControlStrip() {
|
||||||
dismissTouchBar()
|
dismissTouchBar()
|
||||||
presentTouchBar()
|
updateActiveApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
func touchBar(_: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
||||||
if identifier == centerScrollArea {
|
if identifier == basicViewIdentifier {
|
||||||
return self.scrollArea
|
return basicView
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let item = self.items[identifier],
|
|
||||||
let definition = self.itemDefinitions[identifier],
|
|
||||||
definition.align != .center else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
func createItem(forIdentifier identifier: NSTouchBarItem.Identifier, definition item: BarItemDefinition) -> NSTouchBarItem? {
|
func createItem(forIdentifier identifier: NSTouchBarItem.Identifier, definition item: BarItemDefinition) -> NSTouchBarItem? {
|
||||||
|
|
||||||
var barItem: NSTouchBarItem!
|
var barItem: NSTouchBarItem!
|
||||||
switch item.type {
|
switch item.type {
|
||||||
case .staticButton(title: let title):
|
case let .staticButton(title: title):
|
||||||
barItem = CustomButtonTouchBarItem(identifier: identifier, title: title)
|
barItem = CustomButtonTouchBarItem(identifier: identifier, title: title)
|
||||||
case .appleScriptTitledButton(source: let source, refreshInterval: let interval):
|
case let .appleScriptTitledButton(source: source, refreshInterval: interval, alternativeImages: alternativeImages):
|
||||||
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval, alternativeImages: alternativeImages)
|
||||||
case .timeButton(formatTemplate: let template):
|
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
|
||||||
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template)
|
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
|
||||||
case .battery():
|
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)
|
barItem = BatteryBarItem(identifier: identifier)
|
||||||
case .dock:
|
case let .cpu(refreshInterval: refreshInterval):
|
||||||
barItem = AppScrubberTouchBarItem(identifier: identifier)
|
barItem = CPUBarItem(identifier: identifier, refreshInterval: refreshInterval)
|
||||||
|
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:
|
case .volume:
|
||||||
if case .image(let source)? = item.additionalParameters[.image] {
|
if case let .image(source)? = item.additionalParameters[.image] {
|
||||||
barItem = VolumeViewController(identifier: identifier, image: source.image)
|
barItem = VolumeViewController(identifier: identifier, image: source.image)
|
||||||
} else {
|
} else {
|
||||||
barItem = VolumeViewController(identifier: identifier)
|
barItem = VolumeViewController(identifier: identifier)
|
||||||
}
|
}
|
||||||
case .brightness(refreshInterval: let interval):
|
case let .brightness(refreshInterval: interval):
|
||||||
if case .image(let source)? = item.additionalParameters[.image] {
|
if case let .image(source)? = item.additionalParameters[.image] {
|
||||||
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval, image: source.image)
|
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval, image: source.image)
|
||||||
} else {
|
} else {
|
||||||
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval)
|
barItem = BrightnessViewController(identifier: identifier, refreshInterval: interval)
|
||||||
}
|
}
|
||||||
case .weather(interval: let interval, units: let units, api_key: let api_key, icon_type: let icon_type):
|
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)
|
barItem = WeatherBarItem(identifier: identifier, interval: interval, units: units, api_key: api_key, icon_type: icon_type)
|
||||||
case .currency(interval: let interval, from: let from, to: let to):
|
case let .yandexWeather(interval: interval):
|
||||||
barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to)
|
barItem = YandexWeatherBarItem(identifier: identifier, interval: interval)
|
||||||
case .inputsource():
|
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:
|
||||||
barItem = InputSourceBarItem(identifier: identifier)
|
barItem = InputSourceBarItem(identifier: identifier)
|
||||||
case .music(interval: let interval):
|
case let .music(interval: interval, disableMarquee: disableMarquee):
|
||||||
barItem = MusicBarItem(identifier: identifier, interval: interval)
|
barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee)
|
||||||
case .groupBar(items: let items):
|
case let .group(items: items):
|
||||||
barItem = GroupBarItem(identifier: identifier, items: items)
|
barItem = GroupBarItem(identifier: identifier, items: items)
|
||||||
case .nightShift():
|
case .nightShift:
|
||||||
barItem = NightShiftBarItem(identifier: identifier)
|
barItem = NightShiftBarItem(identifier: identifier)
|
||||||
case .dnd():
|
case .dnd:
|
||||||
barItem = DnDBarItem(identifier: identifier)
|
barItem = DnDBarItem(identifier: identifier)
|
||||||
|
case let .pomodoro(workTime: workTime, restTime: restTime):
|
||||||
|
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
|
||||||
|
case let .network(flip: flip, units: units):
|
||||||
|
barItem = NetworkBarItem(identifier: identifier, flip: flip, units: units)
|
||||||
|
case .darkMode:
|
||||||
|
barItem = DarkModeBarItem(identifier: identifier)
|
||||||
|
case let .swipe(direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash):
|
||||||
|
barItem = SwipeItem(identifier: identifier, direction: direction, fingers: fingers, minOffset: minOffset, sourceApple: sourceApple, sourceBash: sourceBash)
|
||||||
|
case let .upnext(from: from, to: to, maxToShow: maxToShow, autoResize: autoResize):
|
||||||
|
barItem = UpNextScrubberTouchBarItem(identifier: identifier, interval: 60, from: from, to: to, maxToShow: maxToShow, autoResize: autoResize)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.tapClosure = action
|
item.actions.append(ItemAction(trigger: .singleTap, action))
|
||||||
}
|
}
|
||||||
if let longAction = self.longAction(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
if let longAction = self.longAction(forItem: item), let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.longTapClosure = longAction
|
item.actions.append(ItemAction(trigger: .longTap, longAction))
|
||||||
}
|
}
|
||||||
if case .bordered(let bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
|
||||||
|
if let touchBarItem = barItem as? CustomButtonTouchBarItem {
|
||||||
|
for action in item.actions {
|
||||||
|
touchBarItem.actions.append(ItemAction(trigger: action.trigger, self.closure(for: action)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if case let .bordered(bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.isBordered = bordered
|
item.isBordered = bordered
|
||||||
}
|
}
|
||||||
if case .background(let color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
|
if case let .background(color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.backgroundColor = color
|
item.backgroundColor = color
|
||||||
}
|
}
|
||||||
if case .width(let value)? = item.additionalParameters[.width], let widthBarItem = barItem as? CanSetWidth {
|
if case let .width(value)? = item.additionalParameters[.width], let widthBarItem = barItem as? CanSetWidth {
|
||||||
widthBarItem.setWidth(value: value)
|
widthBarItem.setWidth(value: value)
|
||||||
}
|
}
|
||||||
if case .image(let source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
|
if case let .image(source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.image = source.image
|
item.image = source.image
|
||||||
}
|
}
|
||||||
if case .title(let value)? = item.additionalParameters[.title] {
|
if case let .title(value)? = item.additionalParameters[.title] {
|
||||||
if let item = barItem as? GroupBarItem {
|
if let item = barItem as? GroupBarItem {
|
||||||
item.collapsedRepresentationLabel = value
|
item.collapsedRepresentationLabel = value
|
||||||
} else if let item = barItem as? CustomButtonTouchBarItem {
|
} else if let item = barItem as? CustomButtonTouchBarItem {
|
||||||
@ -317,13 +426,57 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
return barItem
|
return barItem
|
||||||
}
|
}
|
||||||
|
|
||||||
func action(forItem item: BarItemDefinition) -> (()->())? {
|
func closure(for action: Action) -> (() -> Void)? {
|
||||||
switch item.action {
|
switch action.value {
|
||||||
case .hidKey(keycode: let keycode):
|
case let .hidKey(keycode: keycode):
|
||||||
return { HIDPostAuxKey(keycode) }
|
return { HIDPostAuxKey(keycode) }
|
||||||
case .keyPress(keycode: let keycode):
|
case let .keyPress(keycode: keycode):
|
||||||
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
||||||
case .appleScript(source: let source):
|
case let .appleScript(source: source):
|
||||||
|
guard let appleScript = source.appleScript else {
|
||||||
|
print("cannot create apple script for item \(action)")
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
DispatchQueue.appleScriptQueue.async {
|
||||||
|
var error: NSDictionary?
|
||||||
|
appleScript.executeAndReturnError(&error)
|
||||||
|
if let error = error {
|
||||||
|
print("error \(error) when handling \(action) ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case let .shellScript(executable: executable, parameters: parameters):
|
||||||
|
return {
|
||||||
|
let task = Process()
|
||||||
|
task.launchPath = executable
|
||||||
|
task.arguments = parameters
|
||||||
|
task.launch()
|
||||||
|
}
|
||||||
|
case let .openUrl(url: url):
|
||||||
|
return {
|
||||||
|
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
||||||
|
#if DEBUG
|
||||||
|
print("URL was successfully opened")
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
print("error", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case let .custom(closure: closure):
|
||||||
|
return closure
|
||||||
|
case .none:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func action(forItem item: BarItemDefinition) -> (() -> Void)? {
|
||||||
|
switch item.legacyAction {
|
||||||
|
case let .hidKey(keycode: keycode):
|
||||||
|
return { HIDPostAuxKey(keycode) }
|
||||||
|
case let .keyPress(keycode: keycode):
|
||||||
|
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
||||||
|
case let .appleScript(source: source):
|
||||||
guard let appleScript = source.appleScript else {
|
guard let appleScript = source.appleScript else {
|
||||||
print("cannot create apple script for item \(item)")
|
print("cannot create apple script for item \(item)")
|
||||||
return {}
|
return {}
|
||||||
@ -337,14 +490,14 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .shellScript(executable: let executable, parameters: let parameters):
|
case let .shellScript(executable: executable, parameters: parameters):
|
||||||
return {
|
return {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = executable
|
task.launchPath = executable
|
||||||
task.arguments = parameters
|
task.arguments = parameters
|
||||||
task.launch()
|
task.launch()
|
||||||
}
|
}
|
||||||
case .openUrl(url: let url):
|
case let .openUrl(url: url):
|
||||||
return {
|
return {
|
||||||
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -354,21 +507,20 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
print("error", url)
|
print("error", url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .custom(closure: let closure):
|
case let .custom(closure: closure):
|
||||||
return closure
|
return closure
|
||||||
case .none:
|
case .none:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func longAction(forItem item: BarItemDefinition) -> (() -> Void)? {
|
||||||
func longAction(forItem item: BarItemDefinition) -> (()->())? {
|
switch item.legacyLongAction {
|
||||||
switch item.longAction {
|
case let .hidKey(keycode: keycode):
|
||||||
case .hidKey(keycode: let keycode):
|
|
||||||
return { HIDPostAuxKey(keycode) }
|
return { HIDPostAuxKey(keycode) }
|
||||||
case .keyPress(keycode: let keycode):
|
case let .keyPress(keycode: keycode):
|
||||||
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
return { GenericKeyPress(keyCode: CGKeyCode(keycode)).send() }
|
||||||
case .appleScript(source: let source):
|
case let .appleScript(source: source):
|
||||||
guard let appleScript = source.appleScript else {
|
guard let appleScript = source.appleScript else {
|
||||||
print("cannot create apple script for item \(item)")
|
print("cannot create apple script for item \(item)")
|
||||||
return {}
|
return {}
|
||||||
@ -380,14 +532,14 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
print("error \(error) when handling \(item) ")
|
print("error \(error) when handling \(item) ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .shellScript(executable: let executable, parameters: let parameters):
|
case let .shellScript(executable: executable, parameters: parameters):
|
||||||
return {
|
return {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = executable
|
task.launchPath = executable
|
||||||
task.arguments = parameters
|
task.arguments = parameters
|
||||||
task.launch()
|
task.launch()
|
||||||
}
|
}
|
||||||
case .openUrl(url: let url):
|
case let .openUrl(url: url):
|
||||||
return {
|
return {
|
||||||
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -397,7 +549,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
print("error", url)
|
print("error", url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case .custom(closure: let closure):
|
case let .custom(closure: closure):
|
||||||
return closure
|
return closure
|
||||||
case .none:
|
case .none:
|
||||||
return nil
|
return nil
|
||||||
@ -411,13 +563,19 @@ protocol CanSetWidth {
|
|||||||
|
|
||||||
extension NSCustomTouchBarItem: CanSetWidth {
|
extension NSCustomTouchBarItem: CanSetWidth {
|
||||||
func setWidth(value: CGFloat) {
|
func setWidth(value: CGFloat) {
|
||||||
self.view.widthAnchor.constraint(equalToConstant: value).isActive = true
|
view.widthAnchor.constraint(equalToConstant: value).isActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension NSPopoverTouchBarItem: CanSetWidth {
|
||||||
|
func setWidth(value: CGFloat) {
|
||||||
|
view?.widthAnchor.constraint(equalToConstant: value).isActive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension BarItemDefinition {
|
extension BarItemDefinition {
|
||||||
var align: Align {
|
var align: Align {
|
||||||
if case .align(let result)? = self.additionalParameters[.align] {
|
if case let .align(result)? = additionalParameters[.align] {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
return .center
|
return .center
|
||||||
|
|||||||
@ -7,232 +7,169 @@
|
|||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrubberDataSource {
|
class AppScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||||
|
private var scrollView = NSScrollView()
|
||||||
private var scrubber: NSScrubber!
|
private var autoResize: Bool = false
|
||||||
|
private var widthConstraint: NSLayoutConstraint?
|
||||||
private let hf: HapticFeedback = HapticFeedback()
|
private let filter: NSRegularExpression?
|
||||||
|
|
||||||
private var timer: Timer!
|
|
||||||
private var ticks: Int = 0
|
|
||||||
private let minTicks: Int = 5
|
|
||||||
private let maxTicks: Int = 20
|
|
||||||
private var lastSelected: Int = 0
|
|
||||||
|
|
||||||
private var persistentAppIdentifiers: [String] = []
|
private var persistentAppIdentifiers: [String] = []
|
||||||
private var runningAppsIdentifiers: [String] = []
|
private var runningAppsIdentifiers: [String] = []
|
||||||
|
|
||||||
private var frontmostApplicationIdentifier: String? {
|
private var frontmostApplicationIdentifier: String? {
|
||||||
get {
|
return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
|
||||||
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
|
|
||||||
return frontmostId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var applications: [DockItem] = []
|
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)
|
super.init(identifier: identifier)
|
||||||
|
self.autoResize = autoResize
|
||||||
|
view = scrollView
|
||||||
|
|
||||||
scrubber = NSScrubber();
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(hardReloadItems), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||||
scrubber.delegate = self
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(hardReloadItems), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||||
scrubber.dataSource = self
|
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(softReloadItems), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||||
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
|
|
||||||
|
|
||||||
view = scrubber
|
persistentAppIdentifiers = AppSettings.dockPersistentAppIds
|
||||||
|
hardReloadItems()
|
||||||
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") {
|
|
||||||
self.persistentAppIdentifiers = persistent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRunningApplication()
|
required init?(coder _: NSCoder) {
|
||||||
}
|
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func activeApplicationChanged(n: Notification) {
|
@objc func hardReloadItems() {
|
||||||
updateRunningApplication()
|
applications = launchedApplications()
|
||||||
}
|
|
||||||
|
|
||||||
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
||||||
updateRunningApplication()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateRunningApplication() {
|
|
||||||
let newApplications = launchedApplications()
|
|
||||||
|
|
||||||
let index = newApplications.index {
|
|
||||||
$0.bundleIdentifier == frontmostApplicationIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
applications = newApplications
|
|
||||||
applications += getDockPersistentAppsList()
|
applications += getDockPersistentAppsList()
|
||||||
scrubber.reloadData()
|
reloadData()
|
||||||
|
softReloadItems()
|
||||||
scrubber.selectedIndex = index ?? 0
|
updateSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func numberOfItems(for scrubber: NSScrubber) -> Int {
|
@objc func softReloadItems() {
|
||||||
return applications.count
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func scrubber(_ scrubber: NSScrubber, viewForItemAt index: Int) -> NSScrubberItemView {
|
func updateSize() {
|
||||||
let item = scrubber.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "ScrubberApplicationsItemReuseIdentifier"), owner: self) as? NSScrubberImageItemView ?? NSScrubberImageItemView()
|
if self.autoResize {
|
||||||
item.imageView.imageScaling = .scaleProportionallyDown
|
self.widthConstraint?.isActive = false
|
||||||
|
|
||||||
let app = applications[index]
|
let width = self.scrollView.documentView?.fittingSize.width ?? 0
|
||||||
|
self.widthConstraint = self.scrollView.widthAnchor.constraint(equalToConstant: width)
|
||||||
if let icon = app.icon {
|
self.widthConstraint!.isActive = true
|
||||||
item.image = icon
|
}
|
||||||
item.image.size = NSSize(width: 26, height: 26)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item.removeFromSuperview()
|
func reloadData() {
|
||||||
|
items = applications.map { self.createAppButton(for: $0) }
|
||||||
let dotView = NSView(frame: .zero)
|
let stackView = NSStackView(views: items.compactMap { $0.view })
|
||||||
dotView.wantsLayer = true
|
stackView.spacing = 1
|
||||||
if self.runningAppsIdentifiers.contains(app.bundleIdentifier!) {
|
stackView.orientation = .horizontal
|
||||||
dotView.layer?.backgroundColor = NSColor.white.cgColor
|
let visibleRect = self.scrollView.documentVisibleRect
|
||||||
} else {
|
scrollView.documentView = stackView
|
||||||
dotView.layer?.backgroundColor = NSColor.black.cgColor
|
stackView.scroll(visibleRect.origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func createAppButton(for app: DockItem) -> DockBarItem {
|
||||||
|
let item = DockBarItem(app)
|
||||||
|
item.isBordered = false
|
||||||
|
item.actions.append(contentsOf: [
|
||||||
|
ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
|
self?.switchToApp(app: app)
|
||||||
|
},
|
||||||
|
ItemAction(trigger: .longTap) { [weak self] in
|
||||||
|
self?.handleHalfLongPress(item: app)
|
||||||
|
}
|
||||||
|
])
|
||||||
|
item.killAppClosure = {[weak self] in
|
||||||
|
self?.handleLongPress(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)
|
|
||||||
|
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
public func didBeginInteracting(with scrubber: NSScrubber) {
|
public func switchToApp(app: DockItem) {
|
||||||
stopTimer()
|
let bundleIdentifier = app.bundleIdentifier
|
||||||
self.ticks = 0
|
|
||||||
self.timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(checkTimer), userInfo: nil, repeats: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func checkTimer() {
|
|
||||||
self.ticks += 1
|
|
||||||
|
|
||||||
if (self.ticks == minTicks) {
|
|
||||||
hf.tap(strong: 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.ticks > maxTicks) {
|
|
||||||
stopTimer()
|
|
||||||
hf.tap(strong: 6)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func stopTimer() {
|
|
||||||
self.timer?.invalidate()
|
|
||||||
self.timer = nil
|
|
||||||
self.lastSelected = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
public func didCancelInteracting(with scrubber: NSScrubber) {
|
|
||||||
stopTimer()
|
|
||||||
}
|
|
||||||
|
|
||||||
public func didFinishInteracting(with scrubber: NSScrubber) {
|
|
||||||
stopTimer()
|
|
||||||
|
|
||||||
if (ticks == 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.ticks >= minTicks && scrubber.selectedIndex > 0) {
|
|
||||||
self.longPress(selected: scrubber.selectedIndex)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
|
||||||
if bundleIdentifier!.contains("file://") {
|
if bundleIdentifier!.contains("file://") {
|
||||||
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
||||||
} else {
|
} else {
|
||||||
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
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
|
// 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"
|
// "When switching to an application, switch to a Space with open windows for the application"
|
||||||
// in Mission control settings
|
// in Mission control settings
|
||||||
}
|
}
|
||||||
|
|
||||||
private func longPress(selected: Int) {
|
//todo
|
||||||
let bundleIdentifier = applications[selected].bundleIdentifier
|
private func handleLongPress(item: DockItem) {
|
||||||
|
if let pid = item.pid, let app = NSRunningApplication(processIdentifier: pid) {
|
||||||
if (self.ticks > maxTicks) {
|
if !app.terminate() {
|
||||||
if let processIdentifier = applications[selected].pid {
|
app.forceTerminate()
|
||||||
if !(NSRunningApplication(processIdentifier: processIdentifier)?.terminate())! {
|
|
||||||
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
|
||||||
}
|
}
|
||||||
|
hardReloadItems()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
hf.tap(strong: 6)
|
|
||||||
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
|
|
||||||
self.persistentAppIdentifiers.remove(at: index)
|
|
||||||
} else {
|
|
||||||
self.persistentAppIdentifiers.append(bundleIdentifier!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDefaults.standard.set(self.persistentAppIdentifiers, forKey: "com.toxblh.mtmr.dock.persistent")
|
private func handleHalfLongPress(item: DockItem) {
|
||||||
UserDefaults.standard.synchronize()
|
if let index = self.persistentAppIdentifiers.firstIndex(of: item.bundleIdentifier) {
|
||||||
|
persistentAppIdentifiers.remove(at: index)
|
||||||
|
hardReloadItems()
|
||||||
|
} else {
|
||||||
|
persistentAppIdentifiers.append(item.bundleIdentifier)
|
||||||
}
|
}
|
||||||
self.ticks = 0
|
|
||||||
updateRunningApplication()
|
AppSettings.dockPersistentAppIds = persistentAppIdentifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
private func launchedApplications() -> [DockItem] {
|
private func launchedApplications() -> [DockItem] {
|
||||||
self.runningAppsIdentifiers = []
|
runningAppsIdentifiers = []
|
||||||
var returnable: [DockItem] = []
|
var returnable: [DockItem] = []
|
||||||
for app in NSWorkspace.shared.runningApplications {
|
for app in NSWorkspace.shared.runningApplications {
|
||||||
guard app.activationPolicy == NSApplication.ActivationPolicy.regular else { continue }
|
guard app.activationPolicy == NSApplication.ActivationPolicy.regular else { continue }
|
||||||
guard let bundleIdentifier = app.bundleIdentifier 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
|
||||||
|
}
|
||||||
|
|
||||||
self.runningAppsIdentifiers.append(bundleIdentifier)
|
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)
|
returnable.append(dockItem)
|
||||||
}
|
}
|
||||||
return returnable
|
return returnable
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getIcon(forBundleIdentifier bundleIdentifier: String? = nil, orPath path: String? = nil, orType type: String? = nil) -> NSImage {
|
public func getIcon(forBundleIdentifier bundleIdentifier: String? = nil, orPath path: String? = nil) -> NSImage {
|
||||||
if bundleIdentifier != nil {
|
if let bundleIdentifier = bundleIdentifier, let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier) {
|
||||||
if let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: bundleIdentifier!) {
|
|
||||||
return NSWorkspace.shared.icon(forFile: appPath)
|
return NSWorkspace.shared.icon(forFile: appPath)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if path != nil {
|
if let path = path {
|
||||||
return NSWorkspace.shared.icon(forFile: path!)
|
return NSWorkspace.shared.icon(forFile: path)
|
||||||
}
|
}
|
||||||
|
|
||||||
let genericIcon = NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns")
|
let genericIcon = NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericDocumentIcon.icns")
|
||||||
return genericIcon ?? NSImage(size: .zero)
|
return genericIcon ?? NSImage(size: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public func getDockPersistentAppsList() -> [DockItem] {
|
public func getDockPersistentAppsList() -> [DockItem] {
|
||||||
var returnable: [DockItem] = []
|
var returnable: [DockItem] = []
|
||||||
|
|
||||||
for bundleIdentifier in persistentAppIdentifiers {
|
for bundleIdentifier in persistentAppIdentifiers {
|
||||||
if !self.runningAppsIdentifiers.contains(bundleIdentifier) {
|
if !runningAppsIdentifiers.contains(bundleIdentifier) {
|
||||||
let dockItem = DockItem(bundleIdentifier: bundleIdentifier, icon: getIcon(forBundleIdentifier: bundleIdentifier))
|
let dockItem = DockItem(bundleIdentifier: bundleIdentifier, icon: getIcon(forBundleIdentifier: bundleIdentifier))
|
||||||
returnable.append(dockItem)
|
returnable.append(dockItem)
|
||||||
}
|
}
|
||||||
@ -252,3 +189,60 @@ public class DockItem: NSObject {
|
|||||||
self.pid = pid
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import IOKit.ps
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import IOKit.ps
|
||||||
|
|
||||||
class BatteryBarItem: CustomButtonTouchBarItem {
|
class BatteryBarItem: CustomButtonTouchBarItem {
|
||||||
private let batteryInfo = BatteryInfo()
|
private let batteryInfo = BatteryInfo()
|
||||||
@ -18,15 +18,15 @@ class BatteryBarItem: CustomButtonTouchBarItem {
|
|||||||
batteryInfo.start { [weak self] in
|
batteryInfo.start { [weak self] in
|
||||||
self?.refresh()
|
self?.refresh()
|
||||||
}
|
}
|
||||||
self.refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func refresh() {
|
func refresh() {
|
||||||
self.attributedTitle = self.batteryInfo.formattedInfo()
|
attributedTitle = batteryInfo.formattedInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@ -42,14 +42,14 @@ class BatteryInfo: NSObject {
|
|||||||
var isCharging: Bool = false
|
var isCharging: Bool = false
|
||||||
var ACPower: String = ""
|
var ACPower: String = ""
|
||||||
var timeRemaining: String = ""
|
var timeRemaining: String = ""
|
||||||
var notifyBlock: ()->() = {}
|
var notifyBlock: () -> Void = {}
|
||||||
var loop: CFRunLoopSource?
|
var loop: CFRunLoopSource?
|
||||||
|
|
||||||
func start(notifyBlock: @escaping ()->()) {
|
func start(notifyBlock: @escaping () -> Void) {
|
||||||
self.notifyBlock = notifyBlock
|
self.notifyBlock = notifyBlock
|
||||||
let opaque = Unmanaged.passRetained(self).toOpaque()
|
let opaque = Unmanaged.passRetained(self).toOpaque()
|
||||||
let context = UnsafeMutableRawPointer(opaque)
|
let context = UnsafeMutableRawPointer(opaque)
|
||||||
loop = IOPSNotificationCreateRunLoopSource({ (context) in
|
loop = IOPSNotificationCreateRunLoopSource({ context in
|
||||||
guard let ctx = context else {
|
guard let ctx = context else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ class BatteryInfo: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stop() {
|
func stop() {
|
||||||
self.notifyBlock = {}
|
notifyBlock = {}
|
||||||
guard let loop = self.loop else {
|
guard let loop = self.loop else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -75,41 +75,35 @@ class BatteryInfo: NSObject {
|
|||||||
|
|
||||||
for ps in psList {
|
for ps in psList {
|
||||||
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
|
if let psDesc = IOPSGetPowerSourceDescription(psInfo, ps).takeUnretainedValue() as? [String: Any] {
|
||||||
let current = psDesc[kIOPSCurrentCapacityKey]
|
if let current = psDesc[kIOPSCurrentCapacityKey] as? Int {
|
||||||
if (current != nil) {
|
self.current = current
|
||||||
self.current = current as! Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeToEmpty = psDesc[kIOPSTimeToEmptyKey]
|
if let timeToEmpty = psDesc[kIOPSTimeToEmptyKey] as? Int {
|
||||||
if (timeToEmpty != nil) {
|
self.timeToEmpty = timeToEmpty
|
||||||
self.timeToEmpty = timeToEmpty as! Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeToFull = psDesc[kIOPSTimeToFullChargeKey]
|
if let timeToFull = psDesc[kIOPSTimeToFullChargeKey] as? Int {
|
||||||
if (timeToFull != nil) {
|
self.timeToFull = timeToFull
|
||||||
self.timeToFull = timeToFull as! Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let isCharged = psDesc[kIOPSIsChargedKey]
|
if let isCharged = psDesc[kIOPSIsChargedKey] as? Bool {
|
||||||
if (isCharged != nil) {
|
self.isCharged = isCharged
|
||||||
self.isCharged = isCharged as! Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let isCharging = psDesc[kIOPSIsChargingKey]
|
if let isCharging = psDesc[kIOPSIsChargingKey] as? Bool {
|
||||||
if (isCharging != nil) {
|
self.isCharging = isCharging
|
||||||
self.isCharging = isCharging as! Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let ACPower = psDesc[kIOPSPowerSourceStateKey]
|
if let ACPower = psDesc[kIOPSPowerSourceStateKey] as? String {
|
||||||
if (ACPower != nil) {
|
self.ACPower = ACPower
|
||||||
self.ACPower = ACPower as! String
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFormattedTime(time: Int) -> String {
|
func getFormattedTime(time: Int) -> String {
|
||||||
if (time > 0) {
|
if time > 0 {
|
||||||
let timeFormatted = NSString(format: " %d:%02d", time / 60, time % 60) as String
|
let timeFormatted = NSString(format: " %d:%02d", time / 60, time % 60) as String
|
||||||
return timeFormatted
|
return timeFormatted
|
||||||
}
|
}
|
||||||
@ -119,7 +113,7 @@ class BatteryInfo: NSObject {
|
|||||||
|
|
||||||
public func formattedInfo() -> NSAttributedString {
|
public func formattedInfo() -> NSAttributedString {
|
||||||
var title = ""
|
var title = ""
|
||||||
self.getPSInfo()
|
getPSInfo()
|
||||||
|
|
||||||
if ACPower == "AC Power" {
|
if ACPower == "AC Power" {
|
||||||
if current < 100 {
|
if current < 100 {
|
||||||
@ -138,10 +132,9 @@ class BatteryInfo: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: NSFont.systemFont(ofSize: 15), .baselineOffset: 1])
|
let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: NSFont.systemFont(ofSize: 15), .baselineOffset: 1])
|
||||||
let newTitleSecond = NSMutableAttributedString(string: timeRemaining as String, attributes: [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 8, weight: .regular), NSAttributedStringKey.baselineOffset: 7])
|
let newTitleSecond = NSMutableAttributedString(string: timeRemaining as String, attributes: [NSAttributedString.Key.foregroundColor: color, NSAttributedString.Key.font: NSFont.systemFont(ofSize: 8, weight: .regular), NSAttributedString.Key.baselineOffset: 7])
|
||||||
newTitle.append(newTitleSecond)
|
newTitle.append(newTitleSecond)
|
||||||
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
||||||
return newTitle
|
return newTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import Cocoa
|
|
||||||
import AppKit
|
import AppKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
import Cocoa
|
||||||
import CoreAudio
|
import CoreAudio
|
||||||
|
|
||||||
class BrightnessViewController: NSCustomTouchBarItem {
|
class BrightnessViewController: NSCustomTouchBarItem {
|
||||||
@ -9,7 +9,7 @@ class BrightnessViewController: NSCustomTouchBarItem {
|
|||||||
init(identifier: NSTouchBarItem.Identifier, refreshInterval: Double, image: NSImage? = nil) {
|
init(identifier: NSTouchBarItem.Identifier, refreshInterval: Double, image: NSImage? = nil) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
|
||||||
if (image == nil) {
|
if image == nil {
|
||||||
sliderItem = CustomSlider()
|
sliderItem = CustomSlider()
|
||||||
} else {
|
} else {
|
||||||
sliderItem = CustomSlider(knob: image!)
|
sliderItem = CustomSlider(knob: image!)
|
||||||
@ -20,13 +20,13 @@ class BrightnessViewController: NSCustomTouchBarItem {
|
|||||||
sliderItem.maxValue = 100.0
|
sliderItem.maxValue = 100.0
|
||||||
sliderItem.floatValue = getBrightness() * 100
|
sliderItem.floatValue = getBrightness() * 100
|
||||||
|
|
||||||
self.view = sliderItem
|
view = sliderItem
|
||||||
|
|
||||||
let timer = Timer.scheduledTimer(timeInterval: refreshInterval, target: self, selector: #selector(BrightnessViewController.updateBrightnessSlider), userInfo: nil, repeats: true)
|
let timer = Timer.scheduledTimer(timeInterval: refreshInterval, target: self, selector: #selector(BrightnessViewController.updateBrightnessSlider), userInfo: nil, repeats: true)
|
||||||
RunLoop.current.add(timer, forMode: RunLoopMode.commonModes)
|
RunLoop.current.add(timer, forMode: RunLoop.Mode.common)
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,17 +47,25 @@ class BrightnessViewController: NSCustomTouchBarItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func getBrightness() -> Float32 {
|
private func getBrightness() -> Float32 {
|
||||||
|
if #available(OSX 10.13, *) {
|
||||||
|
return Float32(CoreDisplay_Display_GetUserBrightness(0))
|
||||||
|
} else {
|
||||||
var level: Float32 = 0.5
|
var level: Float32 = 0.5
|
||||||
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IODisplayConnect"))
|
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IODisplayConnect"))
|
||||||
|
|
||||||
IODisplayGetFloatParameter(service, 0, kIODisplayBrightnessKey as CFString, &level)
|
IODisplayGetFloatParameter(service, 0, kIODisplayBrightnessKey as CFString, &level)
|
||||||
return level
|
return level
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func setBrightness(level: Float) {
|
private func setBrightness(level: Float) {
|
||||||
|
if #available(OSX 10.13, *) {
|
||||||
|
CoreDisplay_Display_SetUserBrightness(0, Double(level))
|
||||||
|
} else {
|
||||||
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IODisplayConnect"))
|
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IODisplayConnect"))
|
||||||
|
|
||||||
IODisplaySetFloatParameter(service, 0, kIODisplayBrightnessKey as CFString, level)
|
IODisplaySetFloatParameter(service, 1, kIODisplayBrightnessKey as CFString, level)
|
||||||
IOObjectRelease(service)
|
IOObjectRelease(service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
82
MTMR/Widgets/CPUBarItem.swift
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
//
|
||||||
|
// CPUBarItem.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by bobrosoft on 17/08/2021.
|
||||||
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class CPUBarItem: CustomButtonTouchBarItem {
|
||||||
|
private let refreshInterval: TimeInterval
|
||||||
|
private var refreshQueue: DispatchQueue? = DispatchQueue(label: "mtmr.cpu")
|
||||||
|
private let defaultSingleTapScript: NSAppleScript! = "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell".appleScript
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, refreshInterval: TimeInterval) {
|
||||||
|
self.refreshInterval = refreshInterval
|
||||||
|
super.init(identifier: identifier, title: "⏳")
|
||||||
|
|
||||||
|
// Set default image
|
||||||
|
if self.image == nil {
|
||||||
|
self.image = #imageLiteral(resourceName: "cpu").resize(maxSize: NSSize(width: 24, height: 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default action
|
||||||
|
if actions.filter({ $0.trigger == .singleTap }).isEmpty {
|
||||||
|
actions.append(ItemAction(
|
||||||
|
trigger: .singleTap,
|
||||||
|
defaultTapAction
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshAndSchedule()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshAndSchedule() {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
// Get CPU load
|
||||||
|
let usage = 100 - CPU.systemUsage().idle
|
||||||
|
guard usage.isFinite else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose color based on CPU load
|
||||||
|
var color: NSColor? = nil
|
||||||
|
var bgColor: NSColor? = nil
|
||||||
|
if usage > 70 {
|
||||||
|
color = .black
|
||||||
|
bgColor = .yellow
|
||||||
|
} else if usage > 30 {
|
||||||
|
color = .yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update layout
|
||||||
|
let attrTitle = NSMutableAttributedString.init(attributedString: String(format: "%.1f%%", usage).defaultTouchbarAttributedString)
|
||||||
|
if let color = color {
|
||||||
|
attrTitle.addAttributes([.foregroundColor: color], range: NSRange(location: 0, length: attrTitle.length))
|
||||||
|
}
|
||||||
|
self.attributedTitle = attrTitle
|
||||||
|
self.backgroundColor = bgColor
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshQueue?.asyncAfter(deadline: .now() + refreshInterval) { [weak self] in
|
||||||
|
self?.refreshAndSchedule()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultTapAction() {
|
||||||
|
refreshQueue?.async { [weak self] in
|
||||||
|
self?.defaultSingleTapScript.executeAndReturnError(nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
refreshQueue?.suspend()
|
||||||
|
refreshQueue = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,9 +12,14 @@ import CoreLocation
|
|||||||
class CurrencyBarItem: CustomButtonTouchBarItem {
|
class CurrencyBarItem: CustomButtonTouchBarItem {
|
||||||
private let activity: NSBackgroundActivityScheduler
|
private let activity: NSBackgroundActivityScheduler
|
||||||
private var prefix: String
|
private var prefix: String
|
||||||
|
private var postfix: String
|
||||||
private var from: String
|
private var from: String
|
||||||
private var to: String
|
private var to: String
|
||||||
|
private var decimal: Int
|
||||||
|
private var decimalValue: Float32!
|
||||||
|
private var decimalString: String!
|
||||||
private var oldValue: Float32!
|
private var oldValue: Float32!
|
||||||
|
private var full: Bool = false
|
||||||
|
|
||||||
private let currencies = [
|
private let currencies = [
|
||||||
"USD": "$",
|
"USD": "$",
|
||||||
@ -30,24 +35,68 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
"IDR": "Rp",
|
"IDR": "Rp",
|
||||||
"MXN": "$",
|
"MXN": "$",
|
||||||
"SGD": "$",
|
"SGD": "$",
|
||||||
"CHF": "Fr.",
|
|
||||||
"BTC": "฿",
|
"BTC": "฿",
|
||||||
"LTC": "Ł",
|
"LTC": "Ł",
|
||||||
"ETH": "Ξ",
|
"ETH": "Ξ",
|
||||||
|
"SOL": "◎",
|
||||||
|
"DOT": "●",
|
||||||
|
"DOGE": "Ð",
|
||||||
|
"XMR": "ɱ",
|
||||||
|
"ADA": "₳",
|
||||||
|
"PLN": "zł",
|
||||||
|
"UAH": "₴",
|
||||||
|
]
|
||||||
|
private let decimals = [
|
||||||
|
"USD": 4,
|
||||||
|
"EUR": 4,
|
||||||
|
"RUB": 2,
|
||||||
|
"JPY": 2,
|
||||||
|
"GBP": 4,
|
||||||
|
"CAD": 4,
|
||||||
|
"KRW": 4,
|
||||||
|
"CNY": 4,
|
||||||
|
"AUD": 4,
|
||||||
|
"BRL": 4,
|
||||||
|
"IDR": 1,
|
||||||
|
"MXN": 2,
|
||||||
|
"SGD": 4,
|
||||||
|
"CHF": 4,
|
||||||
|
"BTC": 3,
|
||||||
|
"LTC": 2,
|
||||||
|
"ETH": 2,
|
||||||
|
"DOT": 3,
|
||||||
|
"DOGE": 4,
|
||||||
|
"ADA": 3,
|
||||||
|
"USDT": 3
|
||||||
]
|
]
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String) {
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, full: Bool) {
|
||||||
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||||
activity.interval = interval
|
activity.interval = interval
|
||||||
self.from = from
|
self.from = from
|
||||||
self.to = to
|
self.to = to
|
||||||
|
self.full = full
|
||||||
|
|
||||||
if let prefix = currencies[from] {
|
if let prefix = currencies[from] {
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
} else {
|
} else {
|
||||||
self.prefix = from
|
prefix = from
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let postfix = currencies[to] {
|
||||||
|
self.postfix = postfix
|
||||||
|
} else {
|
||||||
|
postfix = to
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if let decimal = decimals[to] {
|
||||||
|
self.decimal = decimal
|
||||||
|
} else {
|
||||||
|
decimal = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
super.init(identifier: identifier, title: "⏳")
|
super.init(identifier: identifier, title: "⏳")
|
||||||
|
|
||||||
activity.repeats = true
|
activity.repeats = true
|
||||||
@ -59,14 +108,14 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
updateCurrency()
|
updateCurrency()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func updateCurrency() {
|
@objc func updateCurrency() {
|
||||||
let urlRequest = URLRequest(url: URL(string: "https://api.coinbase.com/v2/exchange-rates?currency=\(from)")!)
|
let urlRequest = URLRequest(url: URL(string: "https://api.coinbase.com/v2/exchange-rates?currency=\(from)")!)
|
||||||
|
|
||||||
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
|
let task = URLSession.shared.dataTask(with: urlRequest) { data, _, error in
|
||||||
if error == nil {
|
if error == nil {
|
||||||
do {
|
do {
|
||||||
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
|
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
|
||||||
@ -103,13 +152,25 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
color = NSColor.red
|
color = NSColor.red
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.oldValue = value
|
|
||||||
|
|
||||||
let title = String(format: "%@%.2f", self.prefix, value)
|
oldValue = value
|
||||||
|
decimalValue = (value * pow(10,Float(decimal))).rounded() / pow(10,Float(decimal))
|
||||||
|
decimalString = String(decimalValue)
|
||||||
|
|
||||||
let regularFont = self.attributedTitle.attribute(.font, at: 0, effectiveRange: nil) as? NSFont ?? NSFont.systemFont(ofSize: 15)
|
var title = ""
|
||||||
let newTitle = NSMutableAttributedString(string: title as String, attributes: [.foregroundColor: color, .font: regularFont])
|
if full {
|
||||||
|
title = String(format: "%@%@‣%@", prefix, postfix, decimalString)
|
||||||
|
} else {
|
||||||
|
title = String(format: "%@%.2f", prefix, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
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, .baselineOffset: 1])
|
||||||
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
newTitle.setAlignment(.center, range: NSRange(location: 0, length: title.count))
|
||||||
self.attributedTitle = newTitle
|
attributedTitle = newTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
activity.invalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
MTMR/Widgets/DarkModeBarItem.swift
Normal file
@ -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)
|
||||||
|
|
||||||
|
actions.append(ItemAction(trigger: .singleTap) { [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
|
||||||
|
}
|
||||||
|
|
||||||
@ -13,17 +13,17 @@ class DnDBarItem : CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier) {
|
init(identifier: NSTouchBarItem.Identifier) {
|
||||||
super.init(identifier: identifier, title: "")
|
super.init(identifier: identifier, title: "")
|
||||||
self.isBordered = false
|
isBordered = false
|
||||||
self.setWidth(value: 32)
|
setWidth(value: 32)
|
||||||
|
|
||||||
self.tapClosure = { [weak self] in self?.DnDToggle() }
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in self?.DnDToggle() })
|
||||||
|
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
self.refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class DnDBarItem : CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func refresh() {
|
@objc func refresh() {
|
||||||
self.image = DoNotDisturb.isEnabled ? #imageLiteral(resourceName: "dnd-on") : #imageLiteral(resourceName: "dnd-off")
|
image = DoNotDisturb.isEnabled ? #imageLiteral(resourceName: "dnd-on") : #imageLiteral(resourceName: "dnd-off")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
||||||
|
|
||||||
var jsonItems: [BarItemDefinition]
|
var jsonItems: [BarItemDefinition]
|
||||||
|
|
||||||
var itemDefinitions: [NSTouchBarItem.Identifier: BarItemDefinition] = [:]
|
var itemDefinitions: [NSTouchBarItem.Identifier: BarItemDefinition] = [:]
|
||||||
@ -23,48 +22,46 @@ class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
|||||||
init(identifier: NSTouchBarItem.Identifier, items: [BarItemDefinition]) {
|
init(identifier: NSTouchBarItem.Identifier, items: [BarItemDefinition]) {
|
||||||
jsonItems = items
|
jsonItems = items
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
self.popoverTouchBar.delegate = self
|
popoverTouchBar.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {}
|
||||||
|
|
||||||
}
|
@objc override func showPopover(_: Any?) {
|
||||||
|
itemDefinitions = [:]
|
||||||
|
items = [:]
|
||||||
|
leftIdentifiers = []
|
||||||
|
centerItems = []
|
||||||
|
rightIdentifiers = []
|
||||||
|
|
||||||
@objc override func showPopover(_ sender: Any?) {
|
loadItemDefinitions(jsonItems: jsonItems)
|
||||||
self.itemDefinitions = [:]
|
createItems()
|
||||||
self.items = [:]
|
|
||||||
self.leftIdentifiers = []
|
|
||||||
self.centerItems = []
|
|
||||||
self.rightIdentifiers = []
|
|
||||||
|
|
||||||
self.loadItemDefinitions(jsonItems: jsonItems)
|
|
||||||
self.createItems()
|
|
||||||
|
|
||||||
centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
centerItems = centerIdentifiers.compactMap({ (identifier) -> NSTouchBarItem? in
|
||||||
return items[identifier]
|
items[identifier]
|
||||||
})
|
})
|
||||||
|
|
||||||
self.centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||||
self.scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
||||||
|
|
||||||
TouchBarController.shared.touchBar.delegate = self
|
TouchBarController.shared.touchBar.delegate = self
|
||||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = []
|
TouchBarController.shared.touchBar.defaultItemIdentifiers = []
|
||||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers
|
TouchBarController.shared.touchBar.defaultItemIdentifiers = leftIdentifiers + [centerScrollArea] + rightIdentifiers
|
||||||
|
|
||||||
if TouchBarController.shared.controlStripState {
|
if AppSettings.showControlStripState {
|
||||||
presentSystemModal(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||||
} else {
|
} else {
|
||||||
presentSystemModal(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
presentSystemModal(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
func touchBar(_: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
|
||||||
if identifier == centerScrollArea {
|
if identifier == centerScrollArea {
|
||||||
return self.scrollArea
|
return scrollArea
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let item = self.items[identifier],
|
guard let item = self.items[identifier],
|
||||||
@ -96,8 +93,8 @@ class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createItems() {
|
func createItems() {
|
||||||
for (identifier, definition) in self.itemDefinitions {
|
for (identifier, definition) in itemDefinitions {
|
||||||
self.items[identifier] = TouchBarController.shared.createItem(forIdentifier: identifier, definition: definition)
|
items[identifier] = TouchBarController.shared.createItem(forIdentifier: identifier, definition: definition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,33 +9,33 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
class InputSourceBarItem: CustomButtonTouchBarItem {
|
class InputSourceBarItem: CustomButtonTouchBarItem {
|
||||||
|
|
||||||
fileprivate var notificationCenter: CFNotificationCenter
|
fileprivate var notificationCenter: CFNotificationCenter
|
||||||
let buttonSize = NSSize(width: 21, height: 21)
|
let buttonSize = NSSize(width: 21, height: 21)
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier) {
|
init(identifier: NSTouchBarItem.Identifier) {
|
||||||
notificationCenter = CFNotificationCenterGetDistributedCenter();
|
notificationCenter = CFNotificationCenterGetDistributedCenter()
|
||||||
super.init(identifier: identifier, title: "⏳")
|
super.init(identifier: identifier, title: "⏳")
|
||||||
|
|
||||||
observeIputSourceChangedNotification();
|
observeIputSourceChangedNotification()
|
||||||
textInputSourceDidChange()
|
textInputSourceDidChange()
|
||||||
self.tapClosure = { [weak self] in
|
|
||||||
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
self?.switchInputSource()
|
self?.switchInputSource()
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
CFNotificationCenterRemoveEveryObserver(notificationCenter, UnsafeRawPointer(Unmanaged.passUnretained(self).toOpaque()));
|
CFNotificationCenterRemoveEveryObserver(notificationCenter, UnsafeRawPointer(Unmanaged.passUnretained(self).toOpaque()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func textInputSourceDidChange() {
|
@objc public func textInputSourceDidChange() {
|
||||||
let currentSource = TISCopyCurrentKeyboardInputSource().takeUnretainedValue()
|
let currentSource = TISCopyCurrentKeyboardInputSource().takeUnretainedValue()
|
||||||
|
|
||||||
var iconImage: NSImage? = nil
|
var iconImage: NSImage?
|
||||||
|
|
||||||
if let imageURL = currentSource.iconImageURL,
|
if let imageURL = currentSource.iconImageURL,
|
||||||
let image = NSImage(contentsOf: imageURL) {
|
let image = NSImage(contentsOf: imageURL) {
|
||||||
@ -46,10 +46,10 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
if let iconImage = iconImage {
|
if let iconImage = iconImage {
|
||||||
iconImage.size = buttonSize
|
iconImage.size = buttonSize
|
||||||
self.image = iconImage
|
image = iconImage
|
||||||
self.title = ""
|
title = ""
|
||||||
} else {
|
} else {
|
||||||
self.title = currentSource.name
|
title = currentSource.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for item in inputSources {
|
for item in inputSources {
|
||||||
if (item.id != currentSource.id) {
|
if item.id != currentSource.id {
|
||||||
TISSelectInputSource(item)
|
TISSelectInputSource(item)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc public func observeIputSourceChangedNotification() {
|
@objc public func observeIputSourceChangedNotification() {
|
||||||
let callback: CFNotificationCallback = { center, observer, name, object, info in
|
let callback: CFNotificationCallback = { _, observer, _, _, _ in
|
||||||
let mySelf = Unmanaged<InputSourceBarItem>.fromOpaque(observer!).takeUnretainedValue()
|
let mySelf = Unmanaged<InputSourceBarItem>.fromOpaque(observer!).takeUnretainedValue()
|
||||||
mySelf.textInputSourceDidChange()
|
mySelf.textInputSourceDidChange()
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ extension TISInputSource {
|
|||||||
|
|
||||||
private func getProperty(_ key: CFString) -> AnyObject? {
|
private func getProperty(_ key: CFString) -> AnyObject? {
|
||||||
let cfType = TISGetInputSourceProperty(self, key)
|
let cfType = TISGetInputSourceProperty(self, key)
|
||||||
if (cfType != nil) {
|
if cfType != nil {
|
||||||
return Unmanaged<AnyObject>.fromOpaque(cfType!).takeUnretainedValue()
|
return Unmanaged<AnyObject>.fromOpaque(cfType!).takeUnretainedValue()
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@ -131,4 +131,3 @@ extension TISInputSource {
|
|||||||
return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef)) as IconRef?
|
return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef)) as IconRef?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,61 +10,81 @@ import Cocoa
|
|||||||
import ScriptingBridge
|
import ScriptingBridge
|
||||||
|
|
||||||
class MusicBarItem: CustomButtonTouchBarItem {
|
class MusicBarItem: CustomButtonTouchBarItem {
|
||||||
private let interval: TimeInterval
|
private enum Player: String {
|
||||||
private var songTitle: String?
|
case Music = "com.apple.Music"
|
||||||
private var timer: Timer?
|
case iTunes = "com.apple.iTunes"
|
||||||
let buttonSize = NSSize(width: 21, height: 21)
|
case Spotify = "com.spotify.client"
|
||||||
|
case VOX = "com.coppertino.Vox"
|
||||||
|
case Chrome = "com.google.Chrome"
|
||||||
|
case Safari = "com.apple.Safari"
|
||||||
|
}
|
||||||
|
|
||||||
let playerBundleIdentifiers = [
|
private let playerBundleIdentifiers = [
|
||||||
"com.apple.iTunes",
|
Player.Music,
|
||||||
"com.spotify.client",
|
Player.iTunes,
|
||||||
"com.coppertino.Vox",
|
Player.Spotify,
|
||||||
"com.google.Chrome",
|
Player.VOX,
|
||||||
"com.apple.Safari"
|
Player.Chrome,
|
||||||
|
Player.Safari,
|
||||||
]
|
]
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval) {
|
private let interval: TimeInterval
|
||||||
|
private let disableMarquee: Bool
|
||||||
|
private var songTitle: String?
|
||||||
|
private var timer: Timer?
|
||||||
|
private let iconSize = NSSize(width: 21, height: 21)
|
||||||
|
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, disableMarquee: Bool) {
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
self.disableMarquee = disableMarquee
|
||||||
|
|
||||||
super.init(identifier: identifier, title: "⏳")
|
super.init(identifier: identifier, title: "⏳")
|
||||||
self.isBordered = false
|
isBordered = false
|
||||||
|
|
||||||
self.tapClosure = { [weak self] in self?.playPause() }
|
actions = [
|
||||||
self.longTapClosure = { [weak self] in self?.nextTrack() }
|
ItemAction(trigger: .singleTap) { [weak self] in self?.playPause() },
|
||||||
|
ItemAction(trigger: .doubleTap) { [weak self] in self?.previousTrack() },
|
||||||
|
ItemAction(trigger: .longTap) { [weak self] in self?.nextTrack() }
|
||||||
|
]
|
||||||
|
|
||||||
self.refreshAndSchedule()
|
refreshAndSchedule()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func marquee() {
|
@objc func marquee() {
|
||||||
let str = self.title
|
let str = title
|
||||||
if (str.count > 10) {
|
if str.count > 10 {
|
||||||
let indexFirst = str.index(str.startIndex, offsetBy: 0)
|
let indexFirst = str.index(str.startIndex, offsetBy: 0)
|
||||||
let indexSecond = str.index(str.startIndex, offsetBy: 1)
|
let indexSecond = str.index(str.startIndex, offsetBy: 1)
|
||||||
self.title = String(str.suffix(from: indexSecond)) + String(str[indexFirst])
|
title = String(str.suffix(from: indexSecond)) + String(str[indexFirst])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func playPause() {
|
@objc func playPause() {
|
||||||
for ident in playerBundleIdentifiers {
|
for ident in playerBundleIdentifiers {
|
||||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||||
if (musicPlayer.isRunning) {
|
if musicPlayer.isRunning {
|
||||||
if (musicPlayer.className == "SpotifyApplication") {
|
if ident == .Spotify {
|
||||||
let mp = (musicPlayer as SpotifyApplication)
|
let mp = (musicPlayer as SpotifyApplication)
|
||||||
mp.playpause!()
|
mp.playpause!()
|
||||||
return
|
return
|
||||||
} else if (musicPlayer.className == "ITunesApplication") {
|
} else if ident == .iTunes {
|
||||||
let mp = (musicPlayer as iTunesApplication)
|
let mp = (musicPlayer as iTunesApplication)
|
||||||
mp.playpause!()
|
mp.playpause!()
|
||||||
return
|
return
|
||||||
} else if (musicPlayer.className == "VOXApplication") {
|
} else if ident == .Music {
|
||||||
|
let mp = (musicPlayer as MusicApplication)
|
||||||
|
mp.playpause!()
|
||||||
|
return
|
||||||
|
} else if ident == .VOX {
|
||||||
let mp = (musicPlayer as VoxApplication)
|
let mp = (musicPlayer as VoxApplication)
|
||||||
mp.playpause!()
|
mp.playpause!()
|
||||||
return
|
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'.
|
// 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 safariApplication = musicPlayer as SafariApplication
|
||||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||||
@ -74,7 +94,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
if (tab.URL?.starts(with: "https://music.yandex.ru"))! {
|
if (tab.URL?.starts(with: "https://music.yandex.ru"))! {
|
||||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('player-controls__btn_play')[0].click()", in: tab)
|
_ = safariApplication.doJavaScript!("document.getElementsByClassName('player-controls__btn_play')[0].click()", in: tab)
|
||||||
return
|
return
|
||||||
} else if ((tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))!) {
|
} else if (tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))! {
|
||||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('audio_page_player_play')[0].click()", in: tab)
|
_ = safariApplication.doJavaScript!("document.getElementsByClassName('audio_page_player_play')[0].click()", in: tab)
|
||||||
return
|
return
|
||||||
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
||||||
@ -84,7 +104,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (musicPlayer.className == "GoogleChromeApplication") {
|
// else if (ident == .Chrome) {
|
||||||
// let chromeApplication = musicPlayer as GoogleChromeApplication
|
// let chromeApplication = musicPlayer as GoogleChromeApplication
|
||||||
// let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
// let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
||||||
// for window in chromeWindows! {
|
// for window in chromeWindows! {
|
||||||
@ -111,24 +131,29 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
|
|
||||||
@objc func nextTrack() {
|
@objc func nextTrack() {
|
||||||
for ident in playerBundleIdentifiers {
|
for ident in playerBundleIdentifiers {
|
||||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||||
if (musicPlayer.isRunning) {
|
if musicPlayer.isRunning {
|
||||||
if (musicPlayer.className == "SpotifyApplication") {
|
if ident == .Spotify {
|
||||||
let mp = (musicPlayer as SpotifyApplication)
|
let mp = (musicPlayer as SpotifyApplication)
|
||||||
mp.nextTrack!()
|
mp.nextTrack!()
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
return
|
return
|
||||||
} else if (musicPlayer.className == "ITunesApplication") {
|
} else if ident == .iTunes {
|
||||||
let mp = (musicPlayer as iTunesApplication)
|
let mp = (musicPlayer as iTunesApplication)
|
||||||
mp.nextTrack!()
|
mp.nextTrack!()
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
return
|
return
|
||||||
} else if (musicPlayer.className == "VOXApplication") {
|
} else if ident == .Music {
|
||||||
|
let mp = (musicPlayer as MusicApplication)
|
||||||
|
mp.nextTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
} else if ident == .VOX {
|
||||||
let mp = (musicPlayer as VoxApplication)
|
let mp = (musicPlayer as VoxApplication)
|
||||||
mp.next!()
|
mp.next!()
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
return
|
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'.
|
// 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 safariApplication = musicPlayer as SafariApplication
|
||||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||||
@ -139,7 +164,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('player-controls__btn_next')[0].click()", in: tab)
|
_ = safariApplication.doJavaScript!("document.getElementsByClassName('player-controls__btn_next')[0].click()", in: tab)
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
return
|
return
|
||||||
} else if ((tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))!) {
|
} else if (tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))! {
|
||||||
_ = safariApplication.doJavaScript!("document.getElementsByClassName('audio_page_player_next')[0].click()", in: tab)
|
_ = safariApplication.doJavaScript!("document.getElementsByClassName('audio_page_player_next')[0].click()", in: tab)
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
return
|
return
|
||||||
@ -156,6 +181,31 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func previousTrack() {
|
||||||
|
for ident in playerBundleIdentifiers {
|
||||||
|
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||||
|
if musicPlayer.isRunning {
|
||||||
|
if ident == .Spotify {
|
||||||
|
let mp = (musicPlayer as SpotifyApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
} else if ident == .iTunes {
|
||||||
|
let mp = (musicPlayer as iTunesApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
} else if ident == .Music {
|
||||||
|
let mp = (musicPlayer as MusicApplication)
|
||||||
|
mp.previousTrack!()
|
||||||
|
updatePlayer()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func refreshAndSchedule() {
|
func refreshAndSchedule() {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.updatePlayer()
|
self.updatePlayer()
|
||||||
@ -169,17 +219,19 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
var iconUpdated = false
|
var iconUpdated = false
|
||||||
var titleUpdated = false
|
var titleUpdated = false
|
||||||
|
|
||||||
for var ident in playerBundleIdentifiers {
|
for ident in playerBundleIdentifiers {
|
||||||
if let musicPlayer = SBApplication(bundleIdentifier: ident) {
|
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
|
||||||
if (musicPlayer.isRunning) {
|
if musicPlayer.isRunning {
|
||||||
var tempTitle = ""
|
var tempTitle = ""
|
||||||
if (musicPlayer.className == "SpotifyApplication") {
|
if ident == .Spotify {
|
||||||
tempTitle = (musicPlayer as SpotifyApplication).title
|
tempTitle = (musicPlayer as SpotifyApplication).title
|
||||||
} else if (musicPlayer.className == "ITunesApplication") {
|
} else if ident == .iTunes {
|
||||||
tempTitle = (musicPlayer as iTunesApplication).title
|
tempTitle = (musicPlayer as iTunesApplication).title
|
||||||
} else if (musicPlayer.className == "VOXApplication") {
|
} else if ident == .Music {
|
||||||
|
tempTitle = (musicPlayer as MusicApplication).title
|
||||||
|
} else if ident == .VOX {
|
||||||
tempTitle = (musicPlayer as VoxApplication).title
|
tempTitle = (musicPlayer as VoxApplication).title
|
||||||
} else if (musicPlayer.className == "SafariApplication") {
|
} else if ident == .Safari {
|
||||||
let safariApplication = musicPlayer as SafariApplication
|
let safariApplication = musicPlayer as SafariApplication
|
||||||
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
let safariWindows = safariApplication.windows?().compactMap({ $0 as? SafariWindow })
|
||||||
for window in safariWindows! {
|
for window in safariWindows! {
|
||||||
@ -190,7 +242,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
tempTitle = (tab.name)!
|
tempTitle = (tab.name)!
|
||||||
break
|
break
|
||||||
// }
|
// }
|
||||||
} else if ((tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))!) {
|
} else if (tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))! {
|
||||||
tempTitle = (tab.name)!
|
tempTitle = (tab.name)!
|
||||||
break
|
break
|
||||||
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
||||||
@ -199,21 +251,18 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tempTitle == "" {
|
} else if ident == .Chrome {
|
||||||
ident = ""
|
|
||||||
}
|
|
||||||
} else if (musicPlayer.className == "GoogleChromeApplication") {
|
|
||||||
let chromeApplication = musicPlayer as GoogleChromeApplication
|
let chromeApplication = musicPlayer as GoogleChromeApplication
|
||||||
let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
let chromeWindows = chromeApplication.windows?().compactMap({ $0 as? GoogleChromeWindow })
|
||||||
for window in chromeWindows! {
|
for window in chromeWindows! {
|
||||||
for tab in window.tabs!() {
|
for tab in window.tabs!() {
|
||||||
let tab = tab as! GoogleChromeTab
|
let tab = tab as! GoogleChromeTab
|
||||||
if (tab.URL?.starts(with: "https://music.yandex.ru"))! {
|
if (tab.URL?.starts(with: "https://music.yandex.ru"))! {
|
||||||
if (!(tab.title?.hasSuffix("на Яндекс.Музыке"))!) {
|
if !(tab.title?.hasSuffix("на Яндекс.Музыке"))! {
|
||||||
tempTitle = tab.title!
|
tempTitle = tab.title!
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if ((tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))!) {
|
} else if (tab.URL?.starts(with: "https://vk.com/audios"))! || (tab.URL?.starts(with: "https://vk.com/music"))! {
|
||||||
tempTitle = tab.title!
|
tempTitle = tab.title!
|
||||||
break
|
break
|
||||||
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
} else if (tab.URL?.starts(with: "https://www.youtube.com/watch"))! {
|
||||||
@ -222,28 +271,31 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tempTitle == "" {
|
|
||||||
ident = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempTitle == self.songTitle) {
|
if tempTitle == self.songTitle {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
self.songTitle = tempTitle
|
self.songTitle = tempTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
if let songTitle = self.songTitle?.ifNotEmpty {
|
if let songTitle = self.songTitle?.ifNotEmpty {
|
||||||
self.title = " " + songTitle + " "
|
|
||||||
titleUpdated = true
|
|
||||||
self.timer?.invalidate()
|
self.timer?.invalidate()
|
||||||
self.timer = nil
|
self.timer = nil
|
||||||
|
|
||||||
|
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)
|
self.timer = Timer.scheduledTimer(timeInterval: 0.25, target: self, selector: #selector(self.marquee), userInfo: nil, repeats: true)
|
||||||
}
|
}
|
||||||
if let ident = ident.ifNotEmpty,
|
|
||||||
let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: ident) {
|
titleUpdated = true
|
||||||
|
}
|
||||||
|
if let _ = tempTitle.ifNotEmpty,
|
||||||
|
let appPath = NSWorkspace.shared.absolutePathForApplication(withBundleIdentifier: ident.rawValue) {
|
||||||
let image = NSWorkspace.shared.icon(forFile: appPath)
|
let image = NSWorkspace.shared.icon(forFile: appPath)
|
||||||
image.size = self.buttonSize
|
image.size = self.iconSize
|
||||||
self.image = image
|
self.image = image
|
||||||
iconUpdated = true
|
iconUpdated = true
|
||||||
}
|
}
|
||||||
@ -270,12 +322,14 @@ class MusicBarItem: CustomButtonTouchBarItem {
|
|||||||
@objc optional func previousTrack()
|
@objc optional func previousTrack()
|
||||||
@objc optional func playpause()
|
@objc optional func playpause()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBApplication: SpotifyApplication {}
|
extension SBApplication: SpotifyApplication {}
|
||||||
|
|
||||||
@objc protocol SpotifyTrack {
|
@objc protocol SpotifyTrack {
|
||||||
@objc optional var artist: String { get }
|
@objc optional var artist: String { get }
|
||||||
@objc optional var name: String { get }
|
@objc optional var name: String { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: SpotifyTrack {}
|
extension SBObject: SpotifyTrack {}
|
||||||
|
|
||||||
extension SpotifyApplication {
|
extension SpotifyApplication {
|
||||||
@ -285,19 +339,20 @@ extension SpotifyApplication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@objc protocol iTunesApplication {
|
@objc protocol iTunesApplication {
|
||||||
@objc optional var currentTrack: iTunesTrack { get }
|
@objc optional var currentTrack: iTunesTrack { get }
|
||||||
@objc optional func playpause()
|
@objc optional func playpause()
|
||||||
@objc optional func nextTrack()
|
@objc optional func nextTrack()
|
||||||
@objc optional func previousTrack()
|
@objc optional func previousTrack()
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBApplication: iTunesApplication {}
|
extension SBApplication: iTunesApplication {}
|
||||||
|
|
||||||
@objc protocol iTunesTrack {
|
@objc protocol iTunesTrack {
|
||||||
@objc optional var artist: String { get }
|
@objc optional var artist: String { get }
|
||||||
@objc optional var name: String { get }
|
@objc optional var name: String { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: iTunesTrack {}
|
extension SBObject: iTunesTrack {}
|
||||||
|
|
||||||
extension iTunesApplication {
|
extension iTunesApplication {
|
||||||
@ -307,7 +362,28 @@ extension iTunesApplication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc protocol MusicApplication {
|
||||||
|
@objc optional var currentTrack: MusicTrack { get }
|
||||||
|
@objc optional func playpause()
|
||||||
|
@objc optional func nextTrack()
|
||||||
|
@objc optional func previousTrack()
|
||||||
|
}
|
||||||
|
|
||||||
|
extension SBApplication: MusicApplication {}
|
||||||
|
|
||||||
|
@objc protocol MusicTrack {
|
||||||
|
@objc optional var artist: String { get }
|
||||||
|
@objc optional var name: String { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
extension SBObject: MusicTrack {}
|
||||||
|
|
||||||
|
extension MusicApplication {
|
||||||
|
var title: String {
|
||||||
|
guard let t = currentTrack else { return "" }
|
||||||
|
return (t.artist ?? "") + " — " + (t.name ?? "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc protocol VoxApplication {
|
@objc protocol VoxApplication {
|
||||||
@objc optional func playpause()
|
@objc optional func playpause()
|
||||||
@ -316,6 +392,7 @@ extension iTunesApplication {
|
|||||||
@objc optional var track: String { get }
|
@objc optional var track: String { get }
|
||||||
@objc optional var artist: String { get }
|
@objc optional var artist: String { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBApplication: VoxApplication {}
|
extension SBApplication: VoxApplication {}
|
||||||
|
|
||||||
extension VoxApplication {
|
extension VoxApplication {
|
||||||
@ -324,7 +401,6 @@ extension VoxApplication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@objc public protocol SBObjectProtocol: NSObjectProtocol {
|
@objc public protocol SBObjectProtocol: NSObjectProtocol {
|
||||||
func get() -> Any!
|
func get() -> Any!
|
||||||
}
|
}
|
||||||
@ -338,6 +414,7 @@ extension VoxApplication {
|
|||||||
@objc optional func windows() -> SBElementArray
|
@objc optional func windows() -> SBElementArray
|
||||||
@objc optional func doJavaScript(_ x: String!, in in_: Any!) -> Any // Applies a string of JavaScript code to a document.
|
@objc optional func doJavaScript(_ x: String!, in in_: Any!) -> Any // Applies a string of JavaScript code to a document.
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBApplication: SafariApplication {}
|
extension SBApplication: SafariApplication {}
|
||||||
|
|
||||||
@objc public protocol SafariWindow: SBObjectProtocol {
|
@objc public protocol SafariWindow: SBObjectProtocol {
|
||||||
@ -346,6 +423,7 @@ extension SBApplication: SafariApplication {}
|
|||||||
// @objc optional var document: SafariDocument { get } // The document whose contents are displayed in the window.
|
// @objc optional var document: SafariDocument { get } // The document whose contents are displayed in the window.
|
||||||
// @objc optional func setCurrentTab(_ currentTab: SafariTab!) // The current tab.
|
// @objc optional func setCurrentTab(_ currentTab: SafariTab!) // The current tab.
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: SafariWindow {}
|
extension SBObject: SafariWindow {}
|
||||||
|
|
||||||
// @objc public protocol SafariDocument: SBObjectProtocol {
|
// @objc public protocol SafariDocument: SBObjectProtocol {
|
||||||
@ -358,24 +436,26 @@ extension SBObject: SafariWindow {}
|
|||||||
@objc optional var URL: String { get } // The current URL of the tab.
|
@objc optional var URL: String { get } // The current URL of the tab.
|
||||||
@objc optional var name: String { get } // The name of the tab.
|
@objc optional var name: String { get } // The name of the tab.
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: SafariTab {}
|
extension SBObject: SafariTab {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@objc public protocol GoogleChromeApplication: SBApplicationProtocol {
|
@objc public protocol GoogleChromeApplication: SBApplicationProtocol {
|
||||||
@objc optional func windows() -> SBElementArray
|
@objc optional func windows() -> SBElementArray
|
||||||
@objc optional func executeJavaScript(javascript: String!) -> Any // Applies a string of JavaScript code to a document. //, id: Any!
|
@objc optional func executeJavaScript(javascript: String!) -> Any // Applies a string of JavaScript code to a document. //, id: Any!
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBApplication: GoogleChromeApplication {}
|
extension SBApplication: GoogleChromeApplication {}
|
||||||
|
|
||||||
@objc public protocol GoogleChromeWindow: SBObjectProtocol {
|
@objc public protocol GoogleChromeWindow: SBObjectProtocol {
|
||||||
@objc optional var name: String { get } // The title of the window.
|
@objc optional var name: String { get } // The title of the window.
|
||||||
@objc optional func tabs() -> SBElementArray
|
@objc optional func tabs() -> SBElementArray
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: GoogleChromeWindow {}
|
extension SBObject: GoogleChromeWindow {}
|
||||||
|
|
||||||
@objc public protocol GoogleChromeTab: SBObjectProtocol {
|
@objc public protocol GoogleChromeTab: SBObjectProtocol {
|
||||||
@objc optional var URL: String { get } // The current URL of the tab.
|
@objc optional var URL: String { get } // The current URL of the tab.
|
||||||
@objc optional var title: String { get } // The name of the tab.
|
@objc optional var title: String { get } // The name of the tab.
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SBObject: GoogleChromeTab {}
|
extension SBObject: GoogleChromeTab {}
|
||||||
|
|||||||
178
MTMR/Widgets/NetworkBarItem.swift
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
//
|
||||||
|
// NetworkBarItem.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Anton Palgunov on 23/02/2019.
|
||||||
|
// Copyright © 2019 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
class NetworkBarItem: CustomButtonTouchBarItem, Widget {
|
||||||
|
static var name: String = "network"
|
||||||
|
static var identifier: String = "com.toxblh.mtmr.network"
|
||||||
|
|
||||||
|
private let flip: Bool
|
||||||
|
private let units: String
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, flip: Bool = false, units: String) {
|
||||||
|
self.flip = flip
|
||||||
|
self.units = units
|
||||||
|
super.init(identifier: identifier, title: " ")
|
||||||
|
startMonitoringProcess()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func startMonitoringProcess() {
|
||||||
|
var pipe: Pipe
|
||||||
|
var outputHandle: FileHandle
|
||||||
|
var bandwidthProcess: Process?
|
||||||
|
var dSpeed: UInt64?
|
||||||
|
var uSpeed: UInt64?
|
||||||
|
var curr: Array<Substring>?
|
||||||
|
var dataAvailable: NSObjectProtocol?
|
||||||
|
|
||||||
|
pipe = Pipe()
|
||||||
|
bandwidthProcess = Process()
|
||||||
|
bandwidthProcess?.launchPath = "/usr/bin/env"
|
||||||
|
bandwidthProcess?.arguments = ["netstat", "-w1", "-l", "en0"]
|
||||||
|
bandwidthProcess?.standardOutput = pipe
|
||||||
|
|
||||||
|
outputHandle = pipe.fileHandleForReading
|
||||||
|
outputHandle.waitForDataInBackgroundAndNotify(forModes: [RunLoop.Mode.common])
|
||||||
|
|
||||||
|
dataAvailable = NotificationCenter.default.addObserver(
|
||||||
|
forName: NSNotification.Name.NSFileHandleDataAvailable,
|
||||||
|
object: outputHandle,
|
||||||
|
queue: nil
|
||||||
|
) { _ -> Void in
|
||||||
|
let data = pipe.fileHandleForReading.availableData
|
||||||
|
if data.count > 0 {
|
||||||
|
if let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue) {
|
||||||
|
curr = [""]
|
||||||
|
curr = str
|
||||||
|
.replacingOccurrences(of: " ", with: " ")
|
||||||
|
.split(separator: " ")
|
||||||
|
if curr == nil || (curr?.count)! < 6 {} else {
|
||||||
|
if Int64(curr![2]) == nil {} else {
|
||||||
|
dSpeed = UInt64(curr![2])
|
||||||
|
uSpeed = UInt64(curr![5])
|
||||||
|
|
||||||
|
self.setTitle(up: self.getHumanizeSize(speed: uSpeed!), down: self.getHumanizeSize(speed: dSpeed!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputHandle.waitForDataInBackgroundAndNotify()
|
||||||
|
} else if let dataAvailable = dataAvailable {
|
||||||
|
NotificationCenter.default.removeObserver(dataAvailable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dataReady: NSObjectProtocol?
|
||||||
|
dataReady = NotificationCenter.default.addObserver(
|
||||||
|
forName: Process.didTerminateNotification,
|
||||||
|
object: outputHandle,
|
||||||
|
queue: nil
|
||||||
|
) { _ -> Void in
|
||||||
|
print("Task terminated!")
|
||||||
|
if let observer = dataReady {
|
||||||
|
NotificationCenter.default.removeObserver(observer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bandwidthProcess?.launch()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHumanizeSize(speed: UInt64) -> String {
|
||||||
|
let humanText: String
|
||||||
|
|
||||||
|
func speedB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.0f", Double(speed)) + " B/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
func speedKB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.1f", Double(speed) / 1024) + " KB/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
func speedMB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.1f", Double(speed) / (1024 * 1024)) + " MB/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
func speedGB(speed: UInt64)-> String {
|
||||||
|
return String(format: "%.2f", Double(speed) / (1024 * 1024 * 1024)) + " GB/s"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch self.units {
|
||||||
|
case "B/s":
|
||||||
|
humanText = speedB(speed: speed)
|
||||||
|
case "KB/s":
|
||||||
|
humanText = speedKB(speed: speed)
|
||||||
|
case "MB/s":
|
||||||
|
humanText = speedMB(speed: speed)
|
||||||
|
case "GB/s":
|
||||||
|
humanText = speedGB(speed: speed)
|
||||||
|
default:
|
||||||
|
if speed < 1024 {
|
||||||
|
humanText = speedB(speed: speed)
|
||||||
|
} else if speed < (1024 * 1024) {
|
||||||
|
humanText = speedKB(speed: speed)
|
||||||
|
} else if speed < (1024 * 1024 * 1024) {
|
||||||
|
humanText = speedMB(speed: speed)
|
||||||
|
} else {
|
||||||
|
humanText = speedGB(speed: speed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return humanText
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendUpSpeed(appendString: NSMutableAttributedString, up: String, titleFont: NSFont, newStr: Bool = false) {
|
||||||
|
appendString.append(NSMutableAttributedString(
|
||||||
|
string: newStr ? "\n↑" : "↑",
|
||||||
|
attributes: [
|
||||||
|
NSAttributedString.Key.foregroundColor: NSColor.blue,
|
||||||
|
NSAttributedString.Key.font: titleFont,
|
||||||
|
]))
|
||||||
|
|
||||||
|
appendString.append(NSMutableAttributedString(
|
||||||
|
string: up,
|
||||||
|
attributes: [
|
||||||
|
NSAttributedString.Key.font: titleFont,
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendDownSpeed(appendString: NSMutableAttributedString, down: String, titleFont: NSFont, newStr: Bool = false) {
|
||||||
|
appendString.append(NSMutableAttributedString(
|
||||||
|
string: newStr ? "\n↓" : "↓",
|
||||||
|
attributes: [
|
||||||
|
NSAttributedString.Key.foregroundColor: NSColor.red,
|
||||||
|
NSAttributedString.Key.font: titleFont,
|
||||||
|
]))
|
||||||
|
|
||||||
|
appendString.append(NSMutableAttributedString(
|
||||||
|
string: down,
|
||||||
|
attributes: [
|
||||||
|
NSAttributedString.Key.font: titleFont
|
||||||
|
]))
|
||||||
|
}
|
||||||
|
|
||||||
|
func setTitle(up: String, down: String) {
|
||||||
|
let titleFont = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFont.Weight.light)
|
||||||
|
|
||||||
|
let newTitle: NSMutableAttributedString = NSMutableAttributedString(string: "")
|
||||||
|
|
||||||
|
if (self.flip) {
|
||||||
|
appendUpSpeed(appendString: newTitle, up: up, titleFont: titleFont)
|
||||||
|
appendDownSpeed(appendString: newTitle, down: down, titleFont: titleFont, newStr: true)
|
||||||
|
} else {
|
||||||
|
appendDownSpeed(appendString: newTitle, down: down, titleFont: titleFont)
|
||||||
|
appendUpSpeed(appendString: newTitle, up: up, titleFont: titleFont, newStr: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
self.attributedTitle = newTitle
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,35 +19,35 @@ class NightShiftBarItem: CustomButtonTouchBarItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var isNightShiftEnabled: Bool {
|
private var isNightShiftEnabled: Bool {
|
||||||
return self.blueLightStatus.enabled.boolValue
|
return blueLightStatus.enabled.boolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setNightShift(state: Bool) {
|
private func setNightShift(state: Bool) {
|
||||||
self.nsclient.setEnabled(state)
|
nsclient.setEnabled(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier) {
|
init(identifier: NSTouchBarItem.Identifier) {
|
||||||
super.init(identifier: identifier, title: "")
|
super.init(identifier: identifier, title: "")
|
||||||
self.isBordered = false
|
isBordered = false
|
||||||
self.setWidth(value: 28)
|
setWidth(value: 28)
|
||||||
|
|
||||||
self.tapClosure = { [weak self] in self?.nightShiftAction() }
|
actions.append(ItemAction(trigger: .singleTap) { [weak self] in self?.nightShiftAction() })
|
||||||
|
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(refresh), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
self.refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func nightShiftAction() {
|
func nightShiftAction() {
|
||||||
self.setNightShift(state: !self.isNightShiftEnabled)
|
setNightShift(state: !isNightShiftEnabled)
|
||||||
self.refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func refresh() {
|
@objc func refresh() {
|
||||||
self.image = isNightShiftEnabled ? #imageLiteral(resourceName: "nightShiftOn") : #imageLiteral(resourceName: "nightShiftOff")
|
image = isNightShiftEnabled ? #imageLiteral(resourceName: "nightShiftOn") : #imageLiteral(resourceName: "nightShiftOff")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
127
MTMR/Widgets/PomodoroBarItem.swift
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
//
|
||||||
|
// PomodoroBarItem.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Daniel Apatin on 10.05.2018.
|
||||||
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class PomodoroBarItem: CustomButtonTouchBarItem, Widget {
|
||||||
|
static let identifier = "com.toxblh.mtmr.pomodoro."
|
||||||
|
static let name = "pomodoro"
|
||||||
|
static let decoder: ParametersDecoder = { decoder in
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case workTime
|
||||||
|
case restTime
|
||||||
|
}
|
||||||
|
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime)
|
||||||
|
let restTime = try container.decodeIfPresent(Double.self, forKey: .restTime)
|
||||||
|
|
||||||
|
return (
|
||||||
|
item: .pomodoro(workTime: workTime ?? 1500.00, restTime: restTime ?? 300),
|
||||||
|
actions: [],
|
||||||
|
legacyAction: .none,
|
||||||
|
legacyLongAction: .none,
|
||||||
|
parameters: [:]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum TimeTypes {
|
||||||
|
case work
|
||||||
|
case rest
|
||||||
|
case none
|
||||||
|
}
|
||||||
|
|
||||||
|
private let defaultTitle = "🍅 "
|
||||||
|
private let workTime: TimeInterval
|
||||||
|
private let restTime: TimeInterval
|
||||||
|
private var typeTime: TimeTypes = .none
|
||||||
|
private var timer: DispatchSourceTimer?
|
||||||
|
|
||||||
|
private var timeLeft: Int = 0
|
||||||
|
private var timeLeftString: String {
|
||||||
|
return String(format: "%.2i:%.2i", timeLeft / 60, timeLeft % 60)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, workTime: TimeInterval, restTime: TimeInterval) {
|
||||||
|
self.workTime = workTime
|
||||||
|
self.restTime = restTime
|
||||||
|
super.init(identifier: identifier, title: defaultTitle)
|
||||||
|
actions.append(contentsOf: [
|
||||||
|
ItemAction(trigger: .singleTap) { [weak self] in self?.startStopWork() },
|
||||||
|
ItemAction(trigger: .longTap) { [weak self] in self?.startStopRest() }
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
timer?.cancel()
|
||||||
|
timer = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func startStopWork() {
|
||||||
|
typeTime = .work
|
||||||
|
startStopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func startStopRest() {
|
||||||
|
typeTime = .rest
|
||||||
|
startStopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func startStopTimer() {
|
||||||
|
timer == nil ? start() : reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func start() {
|
||||||
|
timeLeft = Int(typeTime == .work ? workTime : restTime)
|
||||||
|
let queue: DispatchQueue = DispatchQueue(label: "Timer")
|
||||||
|
timer = DispatchSource.makeTimerSource(flags: .strict, queue: queue)
|
||||||
|
timer?.schedule(deadline: .now(), repeating: .seconds(1), leeway: .never)
|
||||||
|
timer?.setEventHandler(handler: tick)
|
||||||
|
timer?.resume()
|
||||||
|
|
||||||
|
NSSound.beep()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func finish() {
|
||||||
|
if typeTime != .none {
|
||||||
|
sendNotification()
|
||||||
|
}
|
||||||
|
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reset() {
|
||||||
|
typeTime = .none
|
||||||
|
timer?.cancel()
|
||||||
|
timer = nil
|
||||||
|
title = defaultTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
private func tick() {
|
||||||
|
timeLeft -= 1
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if self.timeLeft >= 0 {
|
||||||
|
self.title = self.defaultTitle + " " + self.timeLeftString
|
||||||
|
} else {
|
||||||
|
self.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sendNotification() {
|
||||||
|
let notification: NSUserNotification = NSUserNotification()
|
||||||
|
notification.title = "Pomodoro"
|
||||||
|
notification.informativeText = typeTime == .work ? "it's time to rest your mind!" : "It's time to work!"
|
||||||
|
notification.soundName = "Submarine"
|
||||||
|
NSUserNotificationCenter.default.deliver(notification)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,20 +4,25 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
private let dateFormatter = DateFormatter()
|
private let dateFormatter = DateFormatter()
|
||||||
private var timer: Timer!
|
private var timer: Timer!
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String) {
|
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil, locale: String? = nil) {
|
||||||
dateFormatter.setLocalizedDateFormatFromTemplate(formatTemplate)
|
dateFormatter.dateFormat = formatTemplate
|
||||||
|
if let locale = locale {
|
||||||
|
dateFormatter.locale = Locale(identifier: locale)
|
||||||
|
}
|
||||||
|
if let abbr = timeZone {
|
||||||
|
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
|
||||||
|
}
|
||||||
super.init(identifier: identifier, title: " ")
|
super.init(identifier: identifier, title: " ")
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
|
||||||
self.isBordered = false
|
isBordered = false
|
||||||
updateTime()
|
updateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func updateTime() {
|
@objc func updateTime() {
|
||||||
self.title = self.dateFormatter.string(from: Date())
|
title = dateFormatter.string(from: Date())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
256
MTMR/Widgets/UpNextScrubberTouchBarItem.swift
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
//
|
||||||
|
// UpNextScrubberTouchBarItems.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Connor Meehan on 13/7/20.
|
||||||
|
// Copyright © 2020 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import EventKit
|
||||||
|
|
||||||
|
class UpNextScrubberTouchBarItem: NSCustomTouchBarItem {
|
||||||
|
// Dependencies
|
||||||
|
private let scrollView = NSScrollView()
|
||||||
|
private let activity: NSBackgroundActivityScheduler // Update scheduler
|
||||||
|
private var eventSources : [IUpNextSource] = []
|
||||||
|
private var items: [UpNextItem] = []
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
private var futureSearchCutoff: Double
|
||||||
|
private var pastSearchCutoff: Double
|
||||||
|
private var maxToShow: Int
|
||||||
|
private var widthConstraint: NSLayoutConstraint?
|
||||||
|
private var autoResize: Bool = false
|
||||||
|
|
||||||
|
/// <#Description#>
|
||||||
|
/// - Parameters:
|
||||||
|
/// - identifier: Unique identifier of widget
|
||||||
|
/// - interval: Update view interval in seconds
|
||||||
|
/// - from: Relative to current time, how far back we search for events in hours
|
||||||
|
/// - to: Relative to current time, how far forward we search for events in hours
|
||||||
|
/// - maxToShow: Which event to show (1 is first, 2 is second, and so on)
|
||||||
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: Double, to: Double, maxToShow: Int, autoResize: Bool) {
|
||||||
|
// Initialise member properties
|
||||||
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updateCheck")
|
||||||
|
pastSearchCutoff = from * 3600
|
||||||
|
futureSearchCutoff = to * 3600
|
||||||
|
self.maxToShow = maxToShow
|
||||||
|
self.autoResize = autoResize
|
||||||
|
UpNextItem.df.dateFormat = "HH:mm"
|
||||||
|
// Error handling
|
||||||
|
if (maxToShow <= 0) {
|
||||||
|
fatalError("Error on UpNext bar item. maxToShow property must be greater than 0.")
|
||||||
|
}
|
||||||
|
// Init super
|
||||||
|
super.init(identifier: identifier)
|
||||||
|
view = scrollView
|
||||||
|
// Add event sources
|
||||||
|
// Can optionally pass an update view callback to an event source to redraw element
|
||||||
|
self.eventSources.append(UpNextCalenderSource(updateCallback: self.updateView))
|
||||||
|
// Fallback interactivity via interval
|
||||||
|
activity.interval = interval
|
||||||
|
activity.repeats = true
|
||||||
|
activity.qualityOfService = .utility
|
||||||
|
activity.schedule { (completion: NSBackgroundActivityScheduler.CompletionHandler) in
|
||||||
|
self.updateView()
|
||||||
|
completion(NSBackgroundActivityScheduler.Result.finished)
|
||||||
|
}
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateView() -> Void {
|
||||||
|
items = []
|
||||||
|
var upcomingEvents = self.getUpcomingEvents()
|
||||||
|
upcomingEvents.sort(by: {$0.startDate.compare($1.startDate) == .orderedAscending})
|
||||||
|
var index = 1
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
for event in upcomingEvents {
|
||||||
|
// Create UpNextItem
|
||||||
|
let item = UpNextItem(event: event)
|
||||||
|
item.backgroundColor = self.getBackgroundColor(startDate: event.startDate)
|
||||||
|
// Bind tap event
|
||||||
|
item.actions.append(ItemAction(trigger: .singleTap) { [weak self] in
|
||||||
|
self?.switchToApp(event: event)
|
||||||
|
})
|
||||||
|
// Add to view
|
||||||
|
self.items.append(item)
|
||||||
|
// Check if should display any more
|
||||||
|
if (index == self.maxToShow) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
self.reloadData()
|
||||||
|
self.updateSize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reloadData() {
|
||||||
|
let stackView = NSStackView(views: items.compactMap { $0.view })
|
||||||
|
stackView.spacing = 5
|
||||||
|
stackView.orientation = .horizontal
|
||||||
|
let visibleRect = self.scrollView.documentVisibleRect
|
||||||
|
self.scrollView.documentView = stackView
|
||||||
|
stackView.scroll(visibleRect.origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateSize() {
|
||||||
|
if self.autoResize {
|
||||||
|
self.widthConstraint?.isActive = false
|
||||||
|
|
||||||
|
let width = self.scrollView.documentView?.fittingSize.width ?? 0
|
||||||
|
self.widthConstraint = self.scrollView.widthAnchor.constraint(equalToConstant: width)
|
||||||
|
self.widthConstraint!.isActive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private func getUpcomingEvents() -> [UpNextEventModel] {
|
||||||
|
var upcomingEvents: [UpNextEventModel] = []
|
||||||
|
|
||||||
|
// Calculate the range we're going to search for events in
|
||||||
|
let dateLowerBounds = Date(timeIntervalSinceNow: self.pastSearchCutoff)
|
||||||
|
let dateUpperBounds = Date(timeIntervalSinceNow: self.futureSearchCutoff)
|
||||||
|
|
||||||
|
// Get all events from all sources
|
||||||
|
for eventSource in self.eventSources {
|
||||||
|
if (eventSource.hasPermission) {
|
||||||
|
let events = eventSource.getUpcomingEvents(dateLowerBounds: dateLowerBounds, dateUpperBounds: dateUpperBounds)
|
||||||
|
upcomingEvents.append(contentsOf: events)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return upcomingEvents
|
||||||
|
}
|
||||||
|
|
||||||
|
public func switchToApp(event: UpNextEventModel) {
|
||||||
|
var bundleIdentifier: String
|
||||||
|
switch(event.sourceType) {
|
||||||
|
case .iCalendar:
|
||||||
|
bundleIdentifier = UpNextCalenderSource.bundleIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
||||||
|
|
||||||
|
// NB: if you can't open app which on another space, try to check mark
|
||||||
|
// "When switching to an application, switch to a Space with open windows for the application"
|
||||||
|
// in Mission control settings
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func getBackgroundColor(startDate: Date) -> NSColor {
|
||||||
|
let distance = startDate.timeIntervalSinceReferenceDate/60 - Date().timeIntervalSinceReferenceDate/60 // Get time difference in minutes
|
||||||
|
if (distance < 0 as TimeInterval) { // If it's in the past, draw as blue
|
||||||
|
return NSColor.systemBlue
|
||||||
|
} else if (distance < 30 as TimeInterval) { // Less than 30 minutes, backround is red
|
||||||
|
return NSColor.systemRed
|
||||||
|
}
|
||||||
|
return NSColor.clear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class UpNextItem : CustomButtonTouchBarItem {
|
||||||
|
static public let df = DateFormatter()
|
||||||
|
|
||||||
|
init(event: UpNextEventModel) {
|
||||||
|
let identifier = UpNextItem.getIdentifier(event: event)
|
||||||
|
let title = UpNextItem.getTitle(event: event)
|
||||||
|
super.init(identifier: NSTouchBarItem.Identifier(rawValue: identifier), title: title)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func getTitle(event: UpNextEventModel) -> String {
|
||||||
|
var title = ""
|
||||||
|
let startDateString = UpNextItem.df.string(for: event.startDate)
|
||||||
|
switch event.sourceType {
|
||||||
|
case .iCalendar:
|
||||||
|
title = String.init(format: "🗓 %@ - %@ ", event.title, startDateString!)
|
||||||
|
}
|
||||||
|
return title
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func getIdentifier(event: UpNextEventModel) -> String {
|
||||||
|
var identifier : String
|
||||||
|
switch event.sourceType {
|
||||||
|
case .iCalendar:
|
||||||
|
identifier = "com.mtmr.iCalendarEvent"
|
||||||
|
}
|
||||||
|
return identifier + "." + event.title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum UpNextSourceType {
|
||||||
|
case iCalendar
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model for events to be displayed in dock
|
||||||
|
struct UpNextEventModel {
|
||||||
|
let title: String
|
||||||
|
let startDate: Date
|
||||||
|
let sourceType: UpNextSourceType
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Interface for any event source
|
||||||
|
protocol IUpNextSource {
|
||||||
|
static var bundleIdentifier: String { get }
|
||||||
|
var hasPermission : Bool { get }
|
||||||
|
var updateCallback : () -> Void { get set }
|
||||||
|
|
||||||
|
init(updateCallback: @escaping () -> Void)
|
||||||
|
func getUpcomingEvents(dateLowerBounds: Date, dateUpperBounds: Date) -> [UpNextEventModel]
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpNextCalenderSource : IUpNextSource {
|
||||||
|
static public let bundleIdentifier: String = "com.apple.iCal"
|
||||||
|
|
||||||
|
public var hasPermission: Bool = false
|
||||||
|
private var eventStore : EKEventStore
|
||||||
|
internal var updateCallback: () -> Void
|
||||||
|
|
||||||
|
required init(updateCallback: @escaping () -> Void = {}) {
|
||||||
|
self.updateCallback = updateCallback
|
||||||
|
eventStore = EKEventStore()
|
||||||
|
NotificationCenter.default.addObserver(forName: .EKEventStoreChanged, object: eventStore, queue: nil, using: handleUpdate)
|
||||||
|
let authStatus = EKEventStore.authorizationStatus(for: .event)
|
||||||
|
if (authStatus != .authorized) {
|
||||||
|
eventStore.requestAccess(to: .event){ granted, error in
|
||||||
|
self.hasPermission = granted;
|
||||||
|
self.handleUpdate()
|
||||||
|
if(!granted) {
|
||||||
|
NSLog("Error: MTMR UpNextBarWidget not given calendar access.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.handleUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public func handleUpdate() {
|
||||||
|
self.handleUpdate(note: Notification(name: Notification.Name("refresh view")))
|
||||||
|
}
|
||||||
|
public func handleUpdate(note: Notification) {
|
||||||
|
self.updateCallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getUpcomingEvents(dateLowerBounds: Date, dateUpperBounds: Date) -> [UpNextEventModel] {
|
||||||
|
var upcomingEvents: [UpNextEventModel] = []
|
||||||
|
let calendars = self.eventStore.calendars(for: .event)
|
||||||
|
let predicate = self.eventStore.predicateForEvents(withStart: dateLowerBounds, end: dateUpperBounds, calendars: calendars)
|
||||||
|
let events = self.eventStore.events(matching: predicate)
|
||||||
|
for event in events {
|
||||||
|
upcomingEvents.append(UpNextEventModel(title: event.title, startDate: event.startDate, sourceType: UpNextSourceType.iCalendar))
|
||||||
|
}
|
||||||
|
return upcomingEvents
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,22 +1,16 @@
|
|||||||
import Cocoa
|
|
||||||
import AppKit
|
import AppKit
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
|
import Cocoa
|
||||||
import CoreAudio
|
import CoreAudio
|
||||||
|
|
||||||
class VolumeViewController: NSCustomTouchBarItem {
|
class VolumeViewController: NSCustomTouchBarItem {
|
||||||
private(set) var sliderItem: CustomSlider!
|
private(set) var sliderItem: CustomSlider!
|
||||||
|
private var currentDeviceId: AudioObjectID = AudioObjectID(0)
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, image: NSImage? = nil) {
|
init(identifier: NSTouchBarItem.Identifier, image: NSImage? = nil) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
|
||||||
var forPropertyAddress = AudioObjectPropertyAddress(
|
if image == nil {
|
||||||
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMasterVolume,
|
|
||||||
mScope: kAudioDevicePropertyScopeOutput,
|
|
||||||
mElement: kAudioObjectPropertyElementMaster)
|
|
||||||
|
|
||||||
AudioObjectAddPropertyListenerBlock(defaultDeviceID, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
|
||||||
|
|
||||||
if (image == nil) {
|
|
||||||
sliderItem = CustomSlider()
|
sliderItem = CustomSlider()
|
||||||
} else {
|
} else {
|
||||||
sliderItem = CustomSlider(knob: image!)
|
sliderItem = CustomSlider(knob: image!)
|
||||||
@ -27,16 +21,59 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
sliderItem.maxValue = 100.0
|
sliderItem.maxValue = 100.0
|
||||||
sliderItem.floatValue = getInputGain() * 100
|
sliderItem.floatValue = getInputGain() * 100
|
||||||
|
|
||||||
self.view = sliderItem
|
view = sliderItem
|
||||||
|
|
||||||
|
currentDeviceId = defaultDeviceID
|
||||||
|
self.addAudioRouteChangedListener()
|
||||||
|
self.addCurrentAudioVolumeChangedListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
func audioObjectPropertyListenerBlock (numberAddresses: UInt32, addresses: UnsafePointer<AudioObjectPropertyAddress>) {
|
private func addAudioRouteChangedListener() {
|
||||||
|
let audioId = AudioObjectID(bitPattern: kAudioObjectSystemObject)
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwarePropertyDefaultOutputDevice,
|
||||||
|
mScope: kAudioObjectPropertyScopeGlobal,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster)
|
||||||
|
AudioObjectAddPropertyListenerBlock(audioId, &forPropertyAddress, nil, audioRouteChanged)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func audioRouteChanged(numberAddresses _: UInt32, addresses _: UnsafePointer<AudioObjectPropertyAddress>) {
|
||||||
|
self.removeLastAudioVolumeChangeListener()
|
||||||
|
currentDeviceId = defaultDeviceID
|
||||||
|
self.addCurrentAudioVolumeChangedListener()
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.sliderItem.floatValue = self.getInputGain() * 100
|
self.sliderItem.floatValue = self.getInputGain() * 100
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
private func addCurrentAudioVolumeChangedListener() {
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||||
|
mScope: kAudioDevicePropertyScopeOutput,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster
|
||||||
|
)
|
||||||
|
|
||||||
|
AudioObjectAddPropertyListenerBlock(defaultDeviceID, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removeLastAudioVolumeChangeListener() {
|
||||||
|
var forPropertyAddress = AudioObjectPropertyAddress(
|
||||||
|
mSelector: kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||||
|
mScope: kAudioDevicePropertyScopeOutput,
|
||||||
|
mElement: kAudioObjectPropertyElementMaster
|
||||||
|
)
|
||||||
|
|
||||||
|
AudioObjectRemovePropertyListenerBlock(currentDeviceId, &forPropertyAddress, nil, audioObjectPropertyListenerBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
func audioObjectPropertyListenerBlock(numberAddresses _: UInt32, addresses _: UnsafePointer<AudioObjectPropertyAddress>) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.sliderItem.floatValue = self.getInputGain() * 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +102,7 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
var volume: Float32 = 0.5
|
var volume: Float32 = 0.5
|
||||||
var size: UInt32 = UInt32(MemoryLayout.size(ofValue: volume))
|
var size: UInt32 = UInt32(MemoryLayout.size(ofValue: volume))
|
||||||
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
||||||
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMasterVolume)
|
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMainVolume)
|
||||||
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
||||||
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
||||||
AudioObjectGetPropertyData(defaultDeviceID, &address, 0, nil, &size, &volume)
|
AudioObjectGetPropertyData(defaultDeviceID, &address, 0, nil, &size, &volume)
|
||||||
@ -85,7 +122,7 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
var address: AudioObjectPropertyAddress = AudioObjectPropertyAddress()
|
||||||
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
address.mScope = AudioObjectPropertyScope(kAudioDevicePropertyScopeOutput)
|
||||||
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
address.mElement = AudioObjectPropertyElement(kAudioObjectPropertyElementMaster)
|
||||||
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMasterVolume)
|
address.mSelector = AudioObjectPropertySelector(kAudioHardwareServiceDeviceProperty_VirtualMainVolume)
|
||||||
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &inputVolume)
|
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &inputVolume)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,4 +136,3 @@ class VolumeViewController: NSCustomTouchBarItem {
|
|||||||
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &muteVal)
|
return AudioObjectSetPropertyData(defaultDeviceID, &address, 0, nil, size, &muteVal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !CLLocationManager.locationServicesEnabled() {
|
if !CLLocationManager.locationServicesEnabled() {
|
||||||
print("Location services not enabled");
|
print("Location services not enabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,15 +69,15 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
|||||||
manager.startUpdatingLocation()
|
manager.startUpdatingLocation()
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func updateWeather() {
|
@objc func updateWeather() {
|
||||||
if self.location != nil {
|
if location != nil {
|
||||||
let urlRequest = URLRequest(url: URL(string: "https://api.openweathermap.org/data/2.5/weather?lat=\(location.coordinate.latitude)&lon=\(location.coordinate.longitude)&units=\(self.units)&appid=\(self.api_key)")!)
|
let urlRequest = URLRequest(url: URL(string: "https://api.openweathermap.org/data/2.5/weather?lat=\(location.coordinate.latitude)&lon=\(location.coordinate.longitude)&units=\(units)&appid=\(api_key)")!)
|
||||||
|
|
||||||
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
|
let task = URLSession.shared.dataTask(with: urlRequest) { data, _, error in
|
||||||
|
|
||||||
if error == nil {
|
if error == nil {
|
||||||
do {
|
do {
|
||||||
@ -115,25 +115,28 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setWeather(text: String) {
|
func setWeather(text: String) {
|
||||||
self.title = text
|
title = text
|
||||||
}
|
}
|
||||||
|
|
||||||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||||
let lastLocation = locations.last!
|
let lastLocation = locations.last!
|
||||||
self.location = lastLocation
|
location = lastLocation
|
||||||
if prev_location == nil {
|
if prev_location == nil {
|
||||||
updateWeather()
|
updateWeather()
|
||||||
}
|
}
|
||||||
prev_location = lastLocation
|
prev_location = lastLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
func locationManager(_: CLLocationManager, didFailWithError error: Error) {
|
||||||
print(error);
|
print(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
|
func locationManager(_: CLLocationManager, didChangeAuthorization _: CLAuthorizationStatus) {
|
||||||
// print("inside didChangeAuthorization ");
|
// print("inside didChangeAuthorization ");
|
||||||
updateWeather()
|
updateWeather()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
activity.invalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
MTMR/Widgets/WidgetProtocol.swift
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// WidgetProtocol.swift
|
||||||
|
// MTMR
|
||||||
|
//
|
||||||
|
// Created by Anton Palgunov on 20/10/2018.
|
||||||
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
protocol Widget {
|
||||||
|
static var name: String { get }
|
||||||
|
static var identifier: String { get }
|
||||||
|
}
|
||||||
172
MTMR/Widgets/YandexWeatherBarItem.swift
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
//
|
||||||
|
// 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": "☁️",
|
||||||
|
"cloudy": "☁️",
|
||||||
|
"light-rain": "🌦",
|
||||||
|
"drizzle": "💦",
|
||||||
|
"rain": "🌧",
|
||||||
|
"heavy-rain": "⛈",
|
||||||
|
"storm": "🌩",
|
||||||
|
"thunderstorm-with-rain": "⛈",
|
||||||
|
"sleet": "☔️",
|
||||||
|
"light-snow": "❄️",
|
||||||
|
"snow": "🌨",
|
||||||
|
"fog": "🌫"
|
||||||
|
]
|
||||||
|
private var location: CLLocation!
|
||||||
|
private var prevLocation: CLLocation!
|
||||||
|
private var manager: CLLocationManager!
|
||||||
|
private var updateWeatherTask: URLSessionDataTask?
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
if actions.filter({ $0.trigger == .singleTap }).isEmpty {
|
||||||
|
actions.append(ItemAction(
|
||||||
|
trigger: .singleTap,
|
||||||
|
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
|
||||||
|
|
||||||
|
updateWeatherTask?.cancel()
|
||||||
|
updateWeatherTask = 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: "\"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)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWeatherTask?.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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,79 +1,109 @@
|
|||||||
[
|
[
|
||||||
{ "type": "escape", "align": "left" },
|
|
||||||
{ "type": "exitTouchbar", "width": 44, "align": "left" },
|
|
||||||
{ "type": "brightnessDown", "width": 44, "align": "left" },
|
|
||||||
{
|
{
|
||||||
"type": "brightness",
|
"type": "escape",
|
||||||
"width": 60,
|
"width": 64,
|
||||||
|
"align": "left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "dnd",
|
||||||
"align": "left",
|
"align": "left",
|
||||||
"image": {
|
"width": 38
|
||||||
"base64":
|
|
||||||
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAQMAAAD58POIAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURffLOPfLNyaSVzUAAAACdFJOU/kBxOqnWgAAAbJJREFUSMfVljtyhDAQBVulQCFH4CgcDR1NR9ERFBKoeA5GfGddtkNvwFINFKP5tED22+Zxwviv6QVKfIEc/iNoF5gkpLIeYI8SUp4PsAUJiekADQntF6isQjvxCTrhAJlFqMMBeIH9BMsD7DAb2BhvYbIyNAOCZIWqYKGTpDZJFQu9EKVd44RxQRq3IrULWD62C8wSssWUZEsR0k6wcDOrJZmoBpMKI+s5qkBQCQOUJADVOECdOsDS0gDbsgHMfT4rVwHSrZQFIN5ABka8BgDgAeZ+BztBgvUEnSgVlhNsTFJjvoF5HAZorBpdYKAiSRbqNyBIUr6AjZMdPwO72R40MElS+wZUWA+wQ6LAYkFvdIhkmA+wQSDDdIAGAZ6A34H0x0fca11gBZZsIHSIfnE/5+NjCn/OuiuUB+/aunZwDeNayjXdTpDN0wlY+r1PfWu75nfj8RogN2JuCN2Y5qgMwTI0wGPUnQw6Qarx0sVNKA5Mn6VUL22lIbZoYitDbPmlvocc9Umfl2D7adz1reC3pF8av4m+DCenp/ndZuG3E7fhuC3pH2+vnz8V3MfE+bnxBTXuuIMTrLWHAAAAAElFTkSuQmCC"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{ "type": "brightnessUp", "width": 44, "align": "left" },
|
{ "type": "brightnessDown", "width": 32, "bordered": false, "align": "left" },
|
||||||
|
{ "type": "brightnessUp", "width": 32, "bordered": false, "align": "left" },
|
||||||
|
|
||||||
|
// Spotify
|
||||||
{
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"inline":
|
"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"
|
||||||
"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",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"inline":
|
"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"
|
||||||
"if application \"iTunes\" is running then\rtell application \"iTunes\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
|
||||||
},
|
},
|
||||||
"refreshInterval": 1,
|
"refreshInterval": 1,
|
||||||
"image": {
|
"image": {
|
||||||
"base64":
|
"base64": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURUdwTB3WXx3UXh3VXx7XYBkXFRpVLRyURmIaeAQAAAAEdFJOUwDDO3fSqUUkAAABbklEQVRIx61VbW6DMAztoAeYNA7ApB6gkzhAWS24wIAL0HABaK6/pHFNEhy8TXu/kPzkPD/8cTj8K7KPAqB+K5NhQPCUrABCXe7HOUYYZxgVRLiG8RfY4DUgFFtC7cffAfZTFBwBdhWEKfgEq4ocEjgj4ZQifO6/QG9kkETp1dDeVWfRKx3XYSW0LoqY5kCElXDrQkyeCCuh6WL0M4nIWQIyzqixdfKU1koFDKvyCA8NJMzU4xiD+b4kfHRpsIyKc6hBwjVptFHVY51EMAINNDFGJITKDNQcdpX74Hz0CQ3rY5qwMp4EIxrlafzrsYZ2Veb0DkRgfNCUok4Y1fqEijfyi2b8RE9beWqa48Y/uvCNMcH9btfUi+/CGLR1vhL6Zz9N/vBlaCU+7lwY/cmJ67Ryen/2tj23PLqJBodZH8vgj544vOL4pxfI5acrSFxi8hrkU9TSKr78ZpnL50A8KPJJEo+afBblwyqf5j/iGys5j6ScrST2AAAAAElFTkSuQmCC"
|
||||||
"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=="
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Music
|
||||||
{
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"inline":
|
"inline": "if application \"Music\" is running then\rtell application \"Music\"\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"
|
||||||
"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",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"inline":
|
"inline": "if application \"Music\" is running then\rtell application \"Music\"\rif player state is playing then\rnext track\rend if\rend tell\rend if\r"
|
||||||
"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,
|
"longAction": "appleScript",
|
||||||
|
"longActionAppleScript": {
|
||||||
|
"inline": "if application \"Music\" is running then\rtell application \"Music\"\rif player state is playing then\rprev track\rend if\rend tell\rend if\r"
|
||||||
|
},
|
||||||
|
"refreshInterval": 2,
|
||||||
"image": {
|
"image": {
|
||||||
"base64":
|
"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=="
|
||||||
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURUdwTB3WXx3UXh3VXx7XYBkXFRpVLRyURmIaeAQAAAAEdFJOUwDDO3fSqUUkAAABbklEQVRIx61VbW6DMAztoAeYNA7ApB6gkzhAWS24wIAL0HABaK6/pHFNEhy8TXu/kPzkPD/8cTj8K7KPAqB+K5NhQPCUrABCXe7HOUYYZxgVRLiG8RfY4DUgFFtC7cffAfZTFBwBdhWEKfgEq4ocEjgj4ZQifO6/QG9kkETp1dDeVWfRKx3XYSW0LoqY5kCElXDrQkyeCCuh6WL0M4nIWQIyzqixdfKU1koFDKvyCA8NJMzU4xiD+b4kfHRpsIyKc6hBwjVptFHVY51EMAINNDFGJITKDNQcdpX74Hz0CQ3rY5qwMp4EIxrlafzrsYZ2Veb0DkRgfNCUok4Y1fqEijfyi2b8RE9beWqa48Y/uvCNMcH9btfUi+/CGLR1vhL6Zz9N/vBlaCU+7lwY/cmJ67Ryen/2tj23PLqJBodZH8vgj544vOL4pxfI5acrSFxi8hrkU9TSKr78ZpnL50A8KPJJEo+afBblwyqf5j/iGys5j6ScrST2AAAAAElFTkSuQmCC"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// iTunes
|
||||||
{
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"inline":
|
"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"
|
||||||
"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",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"inline":
|
"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"
|
||||||
"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,
|
"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": {
|
"image": {
|
||||||
"base64":
|
"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=="
|
||||||
"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": "displaySleep", "width": 40, "align": "right", "bordered": false },
|
||||||
{ "type": "play", "width": 44 },
|
{
|
||||||
{ "type": "next", "width": 44 },
|
"type": "weather",
|
||||||
{ "type": "weather", "icon_type": "images", "units": "metric" },
|
"align": "right",
|
||||||
{ "type": "currency", "from": "BTC", "to": "USD" },
|
"icon_type": "images",
|
||||||
{ "type": "sleep", "width": 44 },
|
"api_key": "ca93a0bb8cdb428552660d83249e4bc9",
|
||||||
{ "type": "mute", "width": 40, "align": "right" },
|
"bordered": false
|
||||||
{ "type": "volumeDown", "width": 34, "align": "right" },
|
},
|
||||||
{ "type": "volume", "width": 60, "align": "right" },
|
{
|
||||||
{ "type": "volumeUp", "width": 34, "align": "right" },
|
"type": "volumeDown",
|
||||||
{ "type": "inputsource", "align": "right" },
|
"bordered": false,
|
||||||
{ "type": "battery", "align": "right" },
|
"align": "right",
|
||||||
{ "type": "timeButton", "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"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
36
MTMR/dsa_pub.pem
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
-----BEGIN PUBLIC KEY-----
|
||||||
|
MIIGRzCCBDkGByqGSM44BAEwggQsAoICAQDYdwbPwVzbYmnGvpiuwcMuHbpwBymv
|
||||||
|
X+yc6OmFgZNRX39k9T3KyPNwRA8izqsdLsGQe66WxU+HYcVymUt6AWyFYQy4izUN
|
||||||
|
LNO90jqrcpQgES/5n0losdU/uYsATIo098RrGKB8pX5aPU/LavuQQCwyUcqSyRxs
|
||||||
|
p1SSyfj8gkyyFA8wnVmK/xe+O9xVbFzmcxPecwAVW9NIhCjSxTWZJyo5ocg/rf6G
|
||||||
|
dK+MmlrkgSEinXsUs8bR0FqW/3abQXDeAzKrvOTImyvdHb78usLPOopM05j9w3Dq
|
||||||
|
jHj6LdVFf3lAdg7pP0EJYkpuCyJnMQP3BDrewTkIVgmg8nrjR9ZCMSTdNIFTQwqp
|
||||||
|
jfTNh6vUdhPWt4bqMNRT3GbjMBaUNNVt7h0tsrND1nNFUS+PifoJCogqUAcQII//
|
||||||
|
U5lvfC01KxfyOYL1yzNCrq5tZFWqcgm9ko0fOf7c/vFrAQAX7+g5CkDB0DZIdwiq
|
||||||
|
66FDWewudzp3fe9EZB1/NrNX0Dh03uAGc/zCZjLODSqDyrmsG8p9x1uC0fyoFkfm
|
||||||
|
Itjm7nQtcPNdC782QJnDF9c/T1gbaJVMOFvRFiiWbP8U9w9dd5aJZpm3LtDEwT+X
|
||||||
|
ehLmi5n41L0fnh71kSQ63hmu26vLhfbFC+pTMelWnej7d1bNVujdsyqmuKqiv2qC
|
||||||
|
l9izOglpi5G16wIhAIuuCaGHwNtZPE8kw5TIxamUQaBR6ypUgc23Bmq3w6sNAoIC
|
||||||
|
ABaip4l8PU8nlvbA0PshCTTxTokiG8e7qnZRcp3nS/3Fm8QEQlZ15qgsuAym82F/
|
||||||
|
pBYN7ACR+KnePmHLJyIdBYDceW3FS2UcDvA1OZuNbnJwor8RggYfusKSM5AmULwQ
|
||||||
|
qZh42wVQ3NXaJMfGVr8sLH9M6GKgygj7D0Fv7bkDuntIo/Lh9n1q/Y9h8JU0O38r
|
||||||
|
JAiUrJ+q/rNo+8OeNGPadP3W9Slq81JjgSLfMpLDBOEpCEG4Lk6nmbhc45VhUG4+
|
||||||
|
uREm50/ow4PqnW4rr1WDRgjeSGptvxXh8OsLehQcl9ochYyS2PFywfmDCzA81fsg
|
||||||
|
hFAy8BICWB6/rC61+H8+8m0exUfTnzIC6RFderrymq7kbfRwYkh5etRjvEWEdgeI
|
||||||
|
WrJxLiHktDs72bAX9ujwJdXvqJy9SYVy+yWr8fY8vfXtLtZ7KI7gZu4q5tHxCA3s
|
||||||
|
zNK67yjxb6Zpjap/UP4iKyHnTy8DZ26120Jy4oN80xzQzNHfEzOxidQ54pVRH8uA
|
||||||
|
9B5MqySrNOuViAkJCa7LaPu2EEs8tLmiCa4gksaQj3Kdi+j5Icl2A/gkgIcqwyvW
|
||||||
|
VX/8ulRyrRRwVjxuJPNV3UwMANdNmRKWouVO1YLmS5XiBiYj25Tyo1IXH9c+AREB
|
||||||
|
4/gByGkWS9+x0JBAPZ8k4F7wsP73td/zckLaxwDB+7woA4ICBgACggIBAM5ntyMa
|
||||||
|
GTSdchuDYXIwH4iC72tXYgDIXBdLuVWGiOHeo25FFoXyrFVTm31sinzingQiAvXL
|
||||||
|
nlzTT8cdN2oWpOPNG14BzPPxSmRUzXJvgope4/Xp38eELi6DJvpMaAgSIBo+EAP+
|
||||||
|
b6vZO4Bcy3ExW+hMKGnbaRn90tQM7NIEbk+2/j75Z5ihNNQ6y+5JzcDqgacnP3fC
|
||||||
|
mwDkcOQtQyZrR3VByd6ZoV0dpqHapLU/mQwD34Qo34u9TwY0NFJRuz21aJ10EPNf
|
||||||
|
hnlsWtKGhijY79RplZRHdFtR5Y0e3Y3N9s5B5KM6qmyGJP7UyCfG70vrDGrBAei5
|
||||||
|
VupQIiDGw9UVP55wtuJridjTWTCKAhP+UUXaZhu1STYnQmfejU90bkRyggnd9g0E
|
||||||
|
bBixfxa+whskGWHG4pHzfpZVpkbceTdXnF5ieWG4jHzob82OwyTJ9yffWDr0eNlj
|
||||||
|
6vhral8ANHCqbx2vI8foU4XbKURSQxe93eLc+o1+sNlEexH+wg645BeVjI5Zaumg
|
||||||
|
GMcdiwbFdId3cCBOOwvo2KIlSI/DdwSJ9NCgCF2NJCpuZJy2HliCrDegymTf+Y18
|
||||||
|
Gt81NhNe9B8rB7slmX8XU7RlSdmMhNRm9fLSKGADJzhdwSPnaJxQ+AP6QgBeJWLf
|
||||||
|
35sZE2RHp4aEb9WceYHpjz8orPiLHJ/7OPbZ
|
||||||
|
-----END PUBLIC KEY-----
|
||||||
@ -1,13 +1,12 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class AppleScriptDefinitionTests: XCTestCase {
|
class AppleScriptDefinitionTests: XCTestCase {
|
||||||
|
|
||||||
func testInline() {
|
func testInline() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ]
|
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" } } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||||
guard case .appleScriptTitledButton(let source, _)? = result?.first?.type else {
|
guard case .appleScriptTitledButton(let source, _, _)? = result?.first?.type else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -19,7 +18,7 @@ class AppleScriptDefinitionTests: XCTestCase {
|
|||||||
[ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/pew" } } ]
|
[ { "type": "appleScriptTitledButton", "source": { "filePath": "/ololo/pew" } } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||||
guard case .appleScriptTitledButton(let source, _)? = result?.first?.type else {
|
guard case .appleScriptTitledButton(let source, _, _)? = result?.first?.type else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -27,15 +26,41 @@ class AppleScriptDefinitionTests: XCTestCase {
|
|||||||
XCTAssertEqual(sourceStruct?.filePath, "/ololo/pew")
|
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() {
|
func testRefreshInterval() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]
|
[ { "type": "appleScriptTitledButton", "source": { "inline": "tell everything fine" }, "refreshInterval": 305} ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||||
guard case .appleScriptTitledButton(_, 305)? = result?.first?.type else {
|
guard case .appleScriptTitledButton(_, 305, _)? = result?.first?.type else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class BackgroundColorTests: XCTestCase {
|
class BackgroundColorTests: XCTestCase {
|
||||||
|
|
||||||
func testOpaque() {
|
func testOpaque() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ]
|
[ { "type": "staticButton", "title": "Pew", "background": "#FF0000" } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||||
guard case .background(let color)? = result?.first?.additionalParameters[.background] else {
|
guard case let .background(color)? = result?.first?.additionalParameters[.background] else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -19,11 +18,10 @@ class BackgroundColorTests: XCTestCase {
|
|||||||
[ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ]
|
[ { "type": "staticButton", "title": "Pew", "background": "#FF000080" } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonNoActionFixture)
|
||||||
guard case .background(let color)? = result?.first?.additionalParameters[.background] else {
|
guard case let .background(color)? = result?.first?.additionalParameters[.background] else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01)
|
XCTAssertEqual(color.alphaComponent, 0.5, accuracy: 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class ParseConfig: XCTestCase {
|
class ParseConfig: XCTestCase {
|
||||||
|
|
||||||
func testButtonNoAction() {
|
func testButtonNoAction() {
|
||||||
let buttonNoActionFixture = """
|
let buttonNoActionFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew" } ]
|
[ { "type": "staticButton", "title": "Pew" } ]
|
||||||
@ -11,13 +10,28 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .none? = result?.first?.action else {
|
guard result?.first?.actions.count == 0 else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testButtonKeyCodeAction() {
|
func testButtonKeyCodeAction() {
|
||||||
|
let buttonKeycodeFixture = """
|
||||||
|
[ { "type": "staticButton", "title": "Pew", "actions": [ { "trigger": "singleTap", "action": "hidKey", "keycode": 123 } ] } ]
|
||||||
|
""".data(using: .utf8)!
|
||||||
|
let result = try? JSONDecoder().decode([BarItemDefinition].self, from: buttonKeycodeFixture)
|
||||||
|
guard case .staticButton("Pew")? = result?.first?.type else {
|
||||||
|
XCTFail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard case .hidKey(keycode: 123)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
|
XCTFail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testButtonKeyCodeLegacyAction() {
|
||||||
let buttonKeycodeFixture = """
|
let buttonKeycodeFixture = """
|
||||||
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123 } ]
|
[ { "type": "staticButton", "title": "Pew", "action": "hidKey", "keycode": 123 } ]
|
||||||
""".data(using: .utf8)!
|
""".data(using: .utf8)!
|
||||||
@ -26,7 +40,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .hidKey(keycode: 123)? = result?.first?.action else {
|
guard case .hidKey(keycode: 123)? = result?.first?.legacyAction else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -41,7 +55,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -56,7 +70,7 @@ class ParseConfig: XCTestCase {
|
|||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard case .keyPress(keycode: 53)? = result?.first?.action else {
|
guard case .keyPress(keycode: 53)? = result?.first?.actions.filter({ $0.trigger == .singleTap }).first?.value else {
|
||||||
XCTFail()
|
XCTFail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -65,5 +79,4 @@ class ParseConfig: XCTestCase {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
520
README.md
@ -1,75 +1,64 @@
|
|||||||
|
# My touchbar. My rules. [](https://github.com/Toxblh/MTMR/releases) [](https://github.com/Toxblh/MTMR/blob/master/LICENSE)  
|
||||||
|
|
||||||
|
<img src="Resources/logo.png" align="right"
|
||||||
|
title="MTMR by Toxblh" width="110" height="110">
|
||||||
|
|
||||||
|
_The TouchBar Customization App for your MacBook Pro_
|
||||||
|
|
||||||
|
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">
|
<p align="center">
|
||||||
<img src="Resources/logo.png" width="120">
|
<img src="./Resources/aaaaa-acc6-17fee7572ed0.png" alt="Mackbook with touchbar" width="800">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# My TouchBar. My rules
|
|
||||||
|
|
||||||
*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)  
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="Resources/TouchBar-v0.8.1.png">
|
<a href="https://discord.gg/CmNcDuQ"><img height="20px" src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/62fddf0fde45a8baedcc7ee5_847541504914fd33810e70a0ea73177e%20(2)-1.png"> Discord</a>
|
||||||
|
<a href="https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g"><img height="20px" src="https://telegram.org/img/t_logo.png" /> Telegram</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
**MTMR** Community:
|
<p align="center"><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WUAAG2HH58WE4" title="Donate via Paypal"><img height="36px" src="Resources/support_paypal.svg" alt="PayPal donate button" /></a>
|
||||||
[<img height="24px" src="https://github.com/discourse/DiscourseMobile/raw/master/icon.png" /> Discourse](https://forum.mtmr.app)
|
<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>
|
||||||
[<img height="24px" src="https://telegram.org/img/t_logo.png" /> Telegram](https://t.me/joinchat/AmVYGg8vW38c13_3MxdE_g)
|
<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%">
|
||||||
#### Help to purchase Apple Developer License ($99)
|
</a></p>
|
||||||
<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 the idea is to create the program like a platform for plugins for customization TouchBar. I very like BTT and a full custom TouchBar (my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)). And I want to create it. And it's my the first Swift project for MacOS :)
|
|
||||||
|
|
||||||
### Roadmap
|
|
||||||
- [x] Create the first prototype with TouchBar in Storyboard
|
|
||||||
- [x] Put in stripe menu on startup the application
|
|
||||||
- [x] Find how to simulate real buttons like brightness, volume, night shift and etc.
|
|
||||||
- [x] Time in touchbar!
|
|
||||||
- [x] First the weather plugin
|
|
||||||
- [x] Find how to open full-screen TouchBar without the cross and stripe menu
|
|
||||||
- [x] Find how to add haptic feedback
|
|
||||||
- [x] Add icon and menu in StatusBar
|
|
||||||
- [x] Hide from Dock
|
|
||||||
- [x] Status menu: "preferences", "quit"
|
|
||||||
- [x] JSON or another approch for save preset, maybe in `~/Library/Application Support/MTMR/`
|
|
||||||
- [x] Custom buttons size, actions by click
|
|
||||||
- [x] Layout: [always left, NSSliderView for center, always right]
|
|
||||||
- [ ] Overwrite default values from item types (e.g. title for brightness)
|
|
||||||
- [ ] Custom settings for paddings and margins for buttons
|
|
||||||
- [ ] XPC Service for scripts
|
|
||||||
- [ ] UI for settings
|
|
||||||
- [ ] Import config from BTT
|
|
||||||
- [ ] System for autoupdate (maybe https://sparkle-project.org/)
|
|
||||||
|
|
||||||
Settings:
|
|
||||||
- [ ] Interface for plugins and export like presets
|
|
||||||
- [x] Startup at login
|
|
||||||
- [ ] Show on/off in Dock
|
|
||||||
- [ ] Show on/off in StatusBar
|
|
||||||
- [ ] On/off Haptic Feedback
|
|
||||||
|
|
||||||
Maybe:
|
|
||||||
- [ ] Refactoring the application on packages (AppleScript, JavaScript? and Swift?)
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
- Download last [release](https://github.com/Toxblh/MTMR/releases)
|
|
||||||
- Or via Homebrew `brew cask install mtmr`
|
|
||||||
|
|
||||||
## Preset
|
- Download latest [release](https://github.com/Toxblh/MTMR/releases) (.dmg) from github
|
||||||
|
- Or via Homebrew `brew install --cask mtmr`
|
||||||
|
- [Dario Prski](https://medium.com/@urdigitalpulse) has written a [fantastic article on medium](https://medium.com/@urdigitalpulse/customise-your-macbook-pro-touch-bar-966998e606b5) that goes into more detail on installing MTMR
|
||||||
|
|
||||||
File for customize your preset for MTMR: `open ~/Library/Application\ Support/MTMR/items.json`
|
**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 in `~/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:
|
## Built-in button types:
|
||||||
|
|
||||||
|
> Buttons
|
||||||
|
|
||||||
- escape
|
- escape
|
||||||
- exitTouchbar
|
- exitTouchbar
|
||||||
- brightnessUp
|
- brightnessUp
|
||||||
@ -79,128 +68,370 @@ File for customize your preset for MTMR: `open ~/Library/Application\ Support/MT
|
|||||||
- volumeDown
|
- volumeDown
|
||||||
- volumeUp
|
- volumeUp
|
||||||
- mute
|
- mute
|
||||||
- dock (half-long click to open app, full-long click to kill app)
|
|
||||||
- nightShift
|
|
||||||
- dnd (Dont disturb)
|
|
||||||
|
|
||||||
> Native Plugins
|
> Native Plugins
|
||||||
|
|
||||||
|
- timeButton
|
||||||
- battery
|
- battery
|
||||||
|
- cpu
|
||||||
- currency
|
- currency
|
||||||
- weather
|
- weather
|
||||||
|
- yandexWeather
|
||||||
- inputsource
|
- inputsource
|
||||||
- music (tap for pause, longTap for next)
|
- 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
|
||||||
|
- upnext (Calendar events)
|
||||||
|
|
||||||
> Media Keys
|
> Media Keys
|
||||||
|
|
||||||
- previous
|
- previous
|
||||||
- play
|
- play
|
||||||
- next
|
- next
|
||||||
|
|
||||||
> AppleScript plugins
|
> AppleScript plugins
|
||||||
|
|
||||||
- sleep
|
- sleep
|
||||||
- displaySleep
|
- displaySleep
|
||||||
|
|
||||||
## Gestures on central part:
|
> Custom buttons
|
||||||
|
|
||||||
|
- staticButton
|
||||||
|
- appleScriptTitledButton
|
||||||
|
- shellScriptTitledButton
|
||||||
|
|
||||||
|
## Gestures
|
||||||
|
|
||||||
|
By default you can enable basic gestures from application menu (status bar -> MTMR icon -> Volume/Brightness gestures):
|
||||||
- two finger slide: change you Volume
|
- two finger slide: change you Volume
|
||||||
- three finger slide: change you Brightness
|
- three finger slide: change you Brightness
|
||||||
|
|
||||||
|
### Custom gestures
|
||||||
|
|
||||||
|
You can add custom actions for two/three/four finger swipes. To do it, you need to use `swipe` type:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"type": "swipe",
|
||||||
|
"fingers": 2, // number of fingers required (2,3 or 4)
|
||||||
|
"direction": "right", // direction of swipe (right/left)
|
||||||
|
"minOffset": 10, // optional: minimal required offset for gesture to emit event
|
||||||
|
"sourceApple": { // optional: apple script to run
|
||||||
|
"inline": "beep"
|
||||||
|
},
|
||||||
|
"sourceBash": { // optional: bash script to run
|
||||||
|
"inline": "touch /Users/lobster/test"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You may create as many `swipe` objects in the preset as you want.
|
||||||
|
|
||||||
## Built-in slider types:
|
## Built-in slider types:
|
||||||
|
|
||||||
- brightness
|
- brightness
|
||||||
- volume
|
- volume
|
||||||
|
|
||||||
### You can also make a custom buttons using these types
|
### You can also make custom buttons using these types
|
||||||
- `staticButton`
|
|
||||||
|
#### `staticButton`
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"type": "staticButton",
|
"type": "staticButton",
|
||||||
"title": "esc",
|
"title": "esc",
|
||||||
```
|
```
|
||||||
|
|
||||||
- `appleScriptTitledButton`
|
#### `appleScriptTitledButton`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"refreshInterval": 60, //optional
|
"refreshInterval": 60, //optional
|
||||||
"source": {
|
"source": {
|
||||||
"filePath": "/Users/toxblh/Library/Application Support/MTMR/iTunes.nowPlaying.scpt",
|
"filePath": "~/Library/Application Support/MTMR/iTunes.nowPlaying.scpt",
|
||||||
// or
|
// 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
|
// or
|
||||||
"base64": "StringInbase64"
|
"base64": "StringInbase64"
|
||||||
},
|
},
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- `timeButton`
|
> Note: You can change appleScriptTitledButton's icon by following these steps:
|
||||||
|
1. Declare dictionary of icons in `alternativeImages` field
|
||||||
|
2. Make you script return array of two values - `{"TITLE", "IMAGE_LABEL"}`
|
||||||
|
3. Make sure that your `IMAGE_LABEL` is declared in `alternativeImages` field
|
||||||
|
|
||||||
|
Example:
|
||||||
```js
|
```js
|
||||||
"type": "timeButton",
|
{
|
||||||
"formatTemplate": "HH:mm" //optional
|
"type": "appleScriptTitledButton",
|
||||||
|
"source": {
|
||||||
|
"inline": "if (random number from 1 to 2) = 1 then\n\tset val to {\"title\", \"play\"}\nelse\n\tset val to {\"title\", \"pause\"}\nend if\nreturn val"
|
||||||
|
},
|
||||||
|
"refreshInterval": 1,
|
||||||
|
"image": {
|
||||||
|
"base64": "iVBORw0KGgoAAAANSUhEUgA..."
|
||||||
|
},
|
||||||
|
"alternativeImages": {
|
||||||
|
"play": {
|
||||||
|
"base64": "iVBORw0KGgoAAAANSUhEUgAAAAAA..."
|
||||||
|
},
|
||||||
|
"pause": {
|
||||||
|
"base64": "iVBORw0KGgoAAAANSUhEUgAAAIAA..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `shellScriptTitledButton`
|
||||||
|
> Note: script may also use escape sequences to return colors (read https://misc.flogisoft.com/bash/tip_colors_and_formatting for more information)
|
||||||
|
> "16 Colors" is the only mode supported presently. Buttons will set their own background color to the color returned.
|
||||||
|
|
||||||
|
Example of "CPU load" button which also changes color based on load value (Note: The native `cpu` plugin runs runs better):
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"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}'"
|
||||||
|
},
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"trigger": "singleTap",
|
||||||
|
"action": "appleScript",
|
||||||
|
"actionAppleScript": {
|
||||||
|
"inline": "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"align": "right",
|
||||||
|
"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
|
## Groups
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"type": "group",
|
"type": "group",
|
||||||
"align": "center",
|
"align": "center",
|
||||||
"bordered": true,
|
"bordered": true,
|
||||||
"title": "stats",
|
"title": "stats",
|
||||||
"items": [{ button }, {button}, ...]
|
"items": [
|
||||||
|
{ "type": "play" },
|
||||||
|
{ "type": "mute" },
|
||||||
|
...
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To close a group, use the button:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"type": "close",
|
||||||
|
"width": 64
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
## Native plugins
|
## Native plugins
|
||||||
- `weather`
|
|
||||||
> Provider: https://openweathermap.org Need allowance location service
|
#### `cpu`
|
||||||
|
|
||||||
|
> Shows current CPU load in percent, changes color based on load value.
|
||||||
|
> Has lower power consumption and higher stability than the shell-based solution.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "cpu",
|
||||||
|
"refreshInterval": 3,
|
||||||
|
"width": 80
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `timeButton`
|
||||||
|
|
||||||
|
> NOTE: Some values don't work properly: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
|
||||||
|
|
||||||
|
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
|
||||||
|
|
||||||
|
> 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 \
|
||||||
|
> Note: Register at https://openweathermap.org to get your API key \
|
||||||
|
> Note: Wait for 20 minutes or so for Openweathermap to activate your API key.\
|
||||||
|
> Note: Enable MTMR in "Location Services" in the "Security & Privacy" System Preferences pane
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"type": "weather",
|
"type": "weather",
|
||||||
"refreshInterval": 600,
|
"refreshInterval": 600, // in seconds
|
||||||
"units": "metric", // or imperial
|
"units": "metric", // or imperial
|
||||||
"icon_type": "text" // or images
|
"icon_type": "text", // or images
|
||||||
"api_key": "" // you can get the key on openweather
|
"api_key": "" // you can get the key on openweather
|
||||||
```
|
```
|
||||||
|
|
||||||
- `currency`
|
#### `yandexWeather` (experimental)
|
||||||
|
|
||||||
|
> Provider: https://yandex.ru/pogoda. One click to open up weather forecast in your browser. \
|
||||||
|
> Note: Enable MTMR in "Location Services" in the "Security & Privacy" System Preferences pane
|
||||||
|
|
||||||
|
```js
|
||||||
|
"type": "yandexWeather",
|
||||||
|
"refreshInterval": 600 // in seconds
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `currency`
|
||||||
|
|
||||||
> Provider: https://coinbase.com
|
> Provider: https://coinbase.com
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"type": "currency",
|
"type": "currency",
|
||||||
"refreshInterval": 600,
|
"refreshInterval": 600, // in seconds
|
||||||
"align": "right",
|
"align": "right",
|
||||||
"from": "BTC",
|
"from": "BTC",
|
||||||
"to": "USD",
|
"to": "USD",
|
||||||
|
"full": true // £‣1.29$
|
||||||
```
|
```
|
||||||
|
|
||||||
- `music`
|
#### `music`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
"type": "music",
|
"type": "music",
|
||||||
"align": "center",
|
"align": "center",
|
||||||
"width": 80,
|
"width": 80, // Optional
|
||||||
"bordered": false,
|
"bordered": false, // Optional
|
||||||
"refreshInterval": 2,
|
"refreshInterval": 2, // in seconds. Optional. Default 5 seconds
|
||||||
|
"disableMarquee": true // to disable marquee effect. Optional. Default false
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### `pomodoro`
|
||||||
|
|
||||||
|
> Pomodoro plugin. One tap starts the work timer, long-press to start the rest timer. Tap an in-progress timer to 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)
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `network`
|
||||||
|
|
||||||
|
> Network plugin. The plugin to show network usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "network",
|
||||||
|
"flip": true,
|
||||||
|
"units": "dynamic" // or B/s, KB/s, MB/s, GB/s
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `dock`
|
||||||
|
|
||||||
|
> Dock plugin
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "dock",
|
||||||
|
"filter": "(^Xcode$)|(Safari)|(.*player)",
|
||||||
|
"autoResize": true
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `upnext`
|
||||||
|
|
||||||
|
> Calendar next event plugin
|
||||||
|
Displays upcoming events from macOS Calendar. Does not display current event.
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"type": "upnext",
|
||||||
|
"from": 0, // Lower bound of search range for next event in hours. Default 0 (current time)(can be negative to view events in the past)
|
||||||
|
"to": 12, // Upper bounds of search range for next event in hours. Default 12 (12 hours in the future)
|
||||||
|
"maxToShow": 3, // Limits the maximum number of events displayed. Default 3 (the first 3 upcoming events)
|
||||||
|
"autoResize": false // If true, widget will expand to display all events. Default false (scrollable view within "width")
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Actions:
|
## Actions:
|
||||||
|
|
||||||
|
### Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"trigger": "singleTap",
|
||||||
|
"action": "hidKey",
|
||||||
|
"keycode": 53
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Triggers:
|
||||||
|
|
||||||
|
- `singleTap`
|
||||||
|
- `doubleTap`
|
||||||
|
- `tripleTap`
|
||||||
|
- `longTap`
|
||||||
|
|
||||||
|
### Types
|
||||||
|
|
||||||
- `hidKey`
|
- `hidKey`
|
||||||
> https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers
|
> https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"action": "hidKey",
|
"action": "hidKey",
|
||||||
"keycode": 53,
|
"keycode": 53,
|
||||||
```
|
```
|
||||||
|
|
||||||
- `keyPress`
|
- `keyPress`
|
||||||
|
> https://eastmanreference.com/complete-list-of-applescript-key-codes
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"action": "keyPress",
|
"action": "keyPress",
|
||||||
"keycode": 1,
|
"keycode": 1,
|
||||||
```
|
```
|
||||||
|
|
||||||
- `appleScript`
|
- `appleScript`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"action": "appleScript",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"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
|
// "filePath" or "base64" will work as well
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
- `shellScript`
|
- `shellScript`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"action": "shellScript",
|
"action": "shellScript",
|
||||||
"executablePath": "/usr/bin/pmset",
|
"executablePath": "/usr/bin/pmset",
|
||||||
@ -209,105 +440,78 @@ File for customize your preset for MTMR: `open ~/Library/Application\ Support/MT
|
|||||||
```
|
```
|
||||||
|
|
||||||
- `openUrl`
|
- `openUrl`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"action": "openUrl",
|
"action": "openUrl",
|
||||||
"url": "https://google.com",
|
"url": "https://google.com",
|
||||||
```
|
```
|
||||||
|
|
||||||
## LongActions
|
|
||||||
This then you want to use longPress for some operations is will the same values like for Actions but different additional parameters, example:
|
|
||||||
```js
|
|
||||||
"longAction": "hidKey",
|
|
||||||
"longKeycode": 53,
|
|
||||||
```
|
|
||||||
|
|
||||||
- longAction
|
|
||||||
- longKeycode
|
|
||||||
- longActionAppleScript
|
|
||||||
- longExecutablePath
|
|
||||||
- longShellArguments
|
|
||||||
- longUrl
|
|
||||||
|
|
||||||
## Additional parameters:
|
## Additional parameters:
|
||||||
|
|
||||||
- `width` allow to restrict how much room a particular button will take
|
- `width` restrict how much room a particular button will take
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"width": 34
|
"width": 34
|
||||||
```
|
```
|
||||||
|
|
||||||
- `align` can stick the item to the side. default is center
|
- `align` can stick the item to the side. default is center
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"align": "left" //or "right" or "center"
|
"align": "left" // "left", "right" or "center"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example configuration:
|
- `bordered` you can do button without border
|
||||||
|
|
||||||
|
```js
|
||||||
|
"bordered": "false" // "true" or "false"
|
||||||
|
```
|
||||||
|
|
||||||
|
- `background` allow to specify you button background color
|
||||||
|
|
||||||
|
```js
|
||||||
|
"background": "#FF0000",
|
||||||
|
```
|
||||||
|
by using background with color "#000000" and bordered == false you can create button without gray background but with background when the button is pressed
|
||||||
|
|
||||||
|
- `title` specify button title
|
||||||
|
|
||||||
|
```js
|
||||||
|
"title": "hello"
|
||||||
|
```
|
||||||
|
|
||||||
|
- `image` specify button icon
|
||||||
|
|
||||||
|
```js
|
||||||
|
"image": {
|
||||||
|
//Can be either of those
|
||||||
|
"base64": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdB...."
|
||||||
|
//or
|
||||||
|
"filePath": "~/img.png"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `matchAppId` displays the button only when active app's id matches given regexp
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
"matchAppId": "Safari"
|
||||||
{ "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" }
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Author's presets
|
## Troubleshooting
|
||||||
|
|
||||||
[@Toxblh preset](Resources/toxblh.json)
|
#### If you can't open preferences:
|
||||||
|
- Opening another program which can't edit text
|
||||||
|
1. Open Terminal.app
|
||||||
|
2. Put `open -a TextEdit ~/Library/Application\ Support/MTMR/items.json` command and press <kbd>Enter</kbd>
|
||||||
|
|
||||||
[@ReDetection preset](Resources/ReDetection.json)
|
|
||||||
|
|
||||||
### User's presets
|
#### Buttons or gestures doesn't work:
|
||||||
|
- "After the last update my mtmr is not working anymore!"
|
||||||
|
- "Buttons sometimes do not trigger action"
|
||||||
|
- "ESC don't work"
|
||||||
|
- "Gestures don't work"
|
||||||
|
|
||||||
[@luongvo209 preset](Resources/luongvo209.json)
|
Re-tick or check a tick for access 🍏→ System Preferences → Security and Privacy → tab Privacy → Accessibility → MTMR
|
||||||

|
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
|||||||
BIN
Resources/Artboard.png
Normal file
|
After Width: | Height: | Size: 259 KiB |
BIN
Resources/Group 3.png
Normal file
|
After Width: | Height: | Size: 257 KiB |
@ -14,7 +14,7 @@
|
|||||||
{ "type": "appleScriptTitledButton", "source": { "inline": "if application \"iTunes\" is running then\r\ttell application \"iTunes\"\r\t\tif player state is not stopped then return \"\"\r\tend tell\rend if\rif 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 \"\"\r\t\t\t\tend if\r\t\t\tend tell\r\t\tend repeat\r\tend tell\rend if\rreturn \"▶\"" }, "refreshInterval": 30, "width": 40, "align": "right" },
|
{ "type": "appleScriptTitledButton", "source": { "inline": "if application \"iTunes\" is running then\r\ttell application \"iTunes\"\r\t\tif player state is not stopped then return \"\"\r\tend tell\rend if\rif 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 \"\"\r\t\t\t\tend if\r\t\t\tend tell\r\t\tend repeat\r\tend tell\rend if\rreturn \"▶\"" }, "refreshInterval": 30, "width": 40, "align": "right" },
|
||||||
{ "type": "volume", "width": 100, "align": "right" },
|
{ "type": "volume", "width": 100, "align": "right" },
|
||||||
{ "type": "displaySleep", "width": 44, "align": "right" },
|
{ "type": "displaySleep", "width": 44, "align": "right" },
|
||||||
{ "type": "appleScriptTitledButton", "refreshInterval": 1800, "source": { "filePath": "/Users/redetection/Library/Application Support/MTMR/Weather.scpt"}, "align": "right" },
|
{ "type": "appleScriptTitledButton", "refreshInterval": 1800, "source": { "filePath": "~/Library/Application Support/MTMR/Weather.scpt"}, "align": "right" },
|
||||||
|
|
||||||
|
|
||||||
{ "type": "timeButton" , "align": "right"},
|
{ "type": "timeButton" , "align": "right"},
|
||||||
|
|||||||
BIN
Resources/aaaaa-acc6-17fee7572ed0.png
Normal file
|
After Width: | Height: | Size: 583 KiB |
129
Resources/aadi_vs_anand.json
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
[
|
||||||
|
{ "type": "escape", "align": "left" },
|
||||||
|
// --- 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"
|
||||||
|
},
|
||||||
|
"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=="
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// --- 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": "dock", "width": 200, "align": "left"},
|
||||||
|
//{ "type": "button", "title": "alfred"},
|
||||||
|
//{ "type": "volume", "width": 160, "align": "right"},
|
||||||
|
{
|
||||||
|
"type": "group",
|
||||||
|
"align": "right",
|
||||||
|
"bordered": false,
|
||||||
|
"title": "Media",
|
||||||
|
"items": [
|
||||||
|
{"type": "close", "bordered": false, "align": "left"},
|
||||||
|
{
|
||||||
|
"type": "brightnessDown",
|
||||||
|
"bordered": false,
|
||||||
|
"align": "left",
|
||||||
|
"width": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "brightness",
|
||||||
|
"width": 200,
|
||||||
|
"align": "left",
|
||||||
|
"image": {
|
||||||
|
"base64":
|
||||||
|
"iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAQMAAAD58POIAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAGUExURffLOPfLNyaSVzUAAAACdFJOU/kBxOqnWgAAAbJJREFUSMfVljtyhDAQBVulQCFH4CgcDR1NR9ERFBKoeA5GfGddtkNvwFINFKP5tED22+Zxwviv6QVKfIEc/iNoF5gkpLIeYI8SUp4PsAUJiekADQntF6isQjvxCTrhAJlFqMMBeIH9BMsD7DAb2BhvYbIyNAOCZIWqYKGTpDZJFQu9EKVd44RxQRq3IrULWD62C8wSssWUZEsR0k6wcDOrJZmoBpMKI+s5qkBQCQOUJADVOECdOsDS0gDbsgHMfT4rVwHSrZQFIN5ABka8BgDgAeZ+BztBgvUEnSgVlhNsTFJjvoF5HAZorBpdYKAiSRbqNyBIUr6AjZMdPwO72R40MElS+wZUWA+wQ6LAYkFvdIhkmA+wQSDDdIAGAZ6A34H0x0fca11gBZZsIHSIfnE/5+NjCn/OuiuUB+/aunZwDeNayjXdTpDN0wlY+r1PfWu75nfj8RogN2JuCN2Y5qgMwTI0wGPUnQw6Qarx0sVNKA5Mn6VUL22lIbZoYitDbPmlvocc9Umfl2D7adz1reC3pF8av4m+DCenp/ndZuG3E7fhuC3pH2+vnz8V3MfE+bnxBTXuuIMTrLWHAAAAAElFTkSuQmCC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "brightnessUp",
|
||||||
|
"bordered": false,
|
||||||
|
"align": "left",
|
||||||
|
"width": 36
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "volumeDown",
|
||||||
|
"bordered": false,
|
||||||
|
"align": "left",
|
||||||
|
"width": 36,
|
||||||
|
},
|
||||||
|
{ "type": "volume", "width": 200, "align": "left"},
|
||||||
|
{
|
||||||
|
"type": "volumeUp",
|
||||||
|
"bordered": false,
|
||||||
|
"align": "left",
|
||||||
|
"width": 36
|
||||||
|
},
|
||||||
|
{"type": "previous", "bordered": false, "align": "center"},
|
||||||
|
//{"type": "play", "bordered": false, "align": "center"},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "appleScriptTitledButton",
|
||||||
|
"align": "center",
|
||||||
|
"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\rpause\rend if\rend tell\rend if\r"
|
||||||
|
},
|
||||||
|
"refreshInterval": 0.0001,
|
||||||
|
"image": {
|
||||||
|
"base64":
|
||||||
|
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURUdwTB3WXx3UXh3VXx7XYBkXFRpVLRyURmIaeAQAAAAEdFJOUwDDO3fSqUUkAAABbklEQVRIx61VbW6DMAztoAeYNA7ApB6gkzhAWS24wIAL0HABaK6/pHFNEhy8TXu/kPzkPD/8cTj8K7KPAqB+K5NhQPCUrABCXe7HOUYYZxgVRLiG8RfY4DUgFFtC7cffAfZTFBwBdhWEKfgEq4ocEjgj4ZQifO6/QG9kkETp1dDeVWfRKx3XYSW0LoqY5kCElXDrQkyeCCuh6WL0M4nIWQIyzqixdfKU1koFDKvyCA8NJMzU4xiD+b4kfHRpsIyKc6hBwjVptFHVY51EMAINNDFGJITKDNQcdpX74Hz0CQ3rY5qwMp4EIxrlafzrsYZ2Veb0DkRgfNCUok4Y1fqEijfyi2b8RE9beWqa48Y/uvCNMcH9btfUi+/CGLR1vhL6Zz9N/vBlaCU+7lwY/cmJ67Ryen/2tj23PLqJBodZH8vgj544vOL4pxfI5acrSFxi8hrkU9TSKr78ZpnL50A8KPJJEo+afBblwyqf5j/iGys5j6ScrST2AAAAAElFTkSuQmCC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{"type": "next", "bordered": false, "align": "center"},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{ "type": "inputsource", "align": "right", },
|
||||||
|
{ "type": "mute", "bordered": false, "align": "right"},
|
||||||
|
{ "type": "dnd", "align": "right"},
|
||||||
|
{ "type": "nightShift", "align": "right"},
|
||||||
|
{ "type": "sleep", "align": "right", "bordered": false},
|
||||||
|
{ "type": "currency",
|
||||||
|
"refreshInterval": 600, // in seconds
|
||||||
|
"bordered": false,
|
||||||
|
"align": "right",
|
||||||
|
"from": "USD",
|
||||||
|
"to": "HKD",},
|
||||||
|
{
|
||||||
|
"type": "pomodoro",
|
||||||
|
"bordered": false,
|
||||||
|
"align": "right",
|
||||||
|
"workTime": 1800, // set time work in seconds. Default 1500 (25 min)
|
||||||
|
"restTime": 600, // set time rest in seconds. Default 300 (5 min)
|
||||||
|
},
|
||||||
|
{ "type": "weather", "refreshInterval": 60, "units": "metric", "align": "right", "bordered": false, "icon_type": "images", "api_key": "84645702688e83a35e2549ca77f73369"},
|
||||||
|
{ "type": "battery", "align": "right", "bordered": false },
|
||||||
|
{ "type": "timeButton", "align": "right", "formatTemplate": "E MMM d h:mm a", "bordered": false }
|
||||||
|
]
|
||||||
BIN
Resources/aadi_vs_anand1.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
Resources/aadi_vs_anand2.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 68 KiB |
BIN
Resources/ss.png
Normal file
|
After Width: | Height: | Size: 2.1 MiB |
90
Resources/support_paypal.svg
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 19.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
viewBox="0 0 250 49" style="enable-background:new 0 0 250 49;" xml:space="preserve">
|
||||||
|
<style type="text/css">
|
||||||
|
.st0{fill:#189BD7;}
|
||||||
|
.st1{enable-background:new ;}
|
||||||
|
.st2{fill:#FFFFFF;}
|
||||||
|
</style>
|
||||||
|
<title>support</title>
|
||||||
|
<path class="st0" d="M6.6,0h236.8c3.7,0,6.6,3,6.6,6.6v35.8c0,3.7-3,6.6-6.6,6.6c0,0,0,0,0,0H6.6C3,49,0,46,0,42.4c0,0,0,0,0,0V6.6
|
||||||
|
C0,3,3,0,6.6,0z"/>
|
||||||
|
<g class="st1">
|
||||||
|
<path class="st2" d="M25.4,18.8c-0.6-0.8-1.6-1.4-2.9-1.4c-1.4,0-3,0.8-3,2.6c0,1.8,1.5,2.2,3,2.7c2,0.7,4.1,1.3,4.1,4.1
|
||||||
|
c0,2.8-2.3,4-4.6,4c-1.7,0-3.4-0.7-4.4-2.1l1.2-0.9c0.6,1,1.7,1.8,3.2,1.8c1.4,0,3.1-0.9,3.1-2.7c0-2-1.6-2.4-3.4-3
|
||||||
|
c-1.9-0.6-3.8-1.4-3.8-3.9c0-2.7,2.4-3.9,4.5-3.9c1.9,0,3.3,0.8,3.9,1.7L25.4,18.8z"/>
|
||||||
|
<path class="st2" d="M36.4,30.6c0-0.5-0.1-1.2-0.1-1.6h0c-0.5,1.1-1.9,1.8-3.2,1.8c-2.3,0-3.5-1.5-3.5-3.8v-5.7h1.3v5.1
|
||||||
|
c0,1.9,0.6,3.2,2.5,3.2c1.4,0,2.8-1.1,2.8-3.6v-4.7h1.3v7.2c0,0.5,0,1.4,0.1,2H36.4z"/>
|
||||||
|
<path class="st2" d="M42.5,35.3h-1.3v-14h1.3v1.6h0.1c0.8-1.2,2.2-1.8,3.5-1.8c2.9,0,4.8,2.1,4.8,4.9c0,2.7-1.9,4.9-4.8,4.9
|
||||||
|
c-1.3,0-2.7-0.7-3.5-1.8h-0.1V35.3z M45.9,22.2c-2.1,0-3.6,1.6-3.6,3.7c0,2.1,1.5,3.7,3.6,3.7c2.2,0,3.5-1.7,3.5-3.7
|
||||||
|
C49.4,23.9,48.1,22.2,45.9,22.2z"/>
|
||||||
|
<path class="st2" d="M55,35.3h-1.3v-14H55v1.6h0.1c0.8-1.2,2.2-1.8,3.5-1.8c2.9,0,4.8,2.1,4.8,4.9c0,2.7-1.9,4.9-4.8,4.9
|
||||||
|
c-1.3,0-2.7-0.7-3.5-1.8H55V35.3z M58.4,22.2c-2.1,0-3.6,1.6-3.6,3.7c0,2.1,1.5,3.7,3.6,3.7c2.2,0,3.5-1.7,3.5-3.7
|
||||||
|
C61.9,23.9,60.6,22.2,58.4,22.2z"/>
|
||||||
|
<path class="st2" d="M70.4,30.8c-2.9,0-4.9-2.1-4.9-4.9c0-2.8,2.1-4.9,4.9-4.9c2.9,0,4.9,2.1,4.9,4.9
|
||||||
|
C75.4,28.7,73.3,30.8,70.4,30.8z M70.4,22.2c-2.1,0-3.5,1.7-3.5,3.7c0,2.1,1.4,3.7,3.5,3.7c2.2,0,3.5-1.6,3.5-3.7
|
||||||
|
C74,23.9,72.6,22.2,70.4,22.2z"/>
|
||||||
|
</g>
|
||||||
|
<g class="st1">
|
||||||
|
<path class="st2" d="M78.3,21.3h1.3c0,0.5,0.1,1.2,0.1,1.6h0c0.5-1.1,1.7-1.8,3-1.8c0.3,0,0.6,0,0.9,0.1l-0.2,1.3
|
||||||
|
c-0.2-0.1-0.6-0.1-0.9-0.1c-1.4,0-2.7,1-2.7,3.5v4.7h-1.3v-7.2C78.4,22.9,78.4,22,78.3,21.3z"/>
|
||||||
|
</g>
|
||||||
|
<g class="st1">
|
||||||
|
<path class="st2" d="M89.5,22.4h-2.6v5.4c0,1.4,0.6,1.7,1.4,1.7c0.4,0,0.8-0.1,1.2-0.3l0.1,1.2c-0.5,0.2-1,0.3-1.6,0.3
|
||||||
|
c-1,0-2.4-0.4-2.4-2.5v-5.8h-1.9v-1.1h1.9v-2.6h1.3v2.6h2.6V22.4z"/>
|
||||||
|
<path class="st2" d="M100.8,30.8c-2.9,0-4.9-2.1-4.9-4.9c0-2.8,2.1-4.9,4.9-4.9c2.9,0,4.9,2.1,4.9,4.9
|
||||||
|
C105.7,28.7,103.7,30.8,100.8,30.8z M100.8,22.2c-2.1,0-3.5,1.7-3.5,3.7c0,2.1,1.4,3.7,3.5,3.7c2.2,0,3.5-1.6,3.5-3.7
|
||||||
|
C104.3,23.9,102.9,22.2,100.8,22.2z"/>
|
||||||
|
<path class="st2" d="M109.8,21.3c0,0.5,0.1,1.2,0.1,1.6h0c0.5-1.1,1.9-1.8,3.2-1.8c2.3,0,3.5,1.5,3.5,3.8v5.7h-1.3v-5.1
|
||||||
|
c0-1.9-0.6-3.2-2.5-3.2c-1.4,0-2.8,1.1-2.8,3.6v4.7h-1.3v-7.2c0-0.5,0-1.4-0.1-2H109.8z"/>
|
||||||
|
</g>
|
||||||
|
<path class="st2" d="M166,18.3c0.1,0,0.2,0,0.3,0h4.9c1.1-0.1,2.2,0.1,3.2,0.4c0.8,0.2,1.5,0.7,2,1.4c0.5,0.8,0.7,1.8,0.6,2.8
|
||||||
|
c-0.1,0.9-0.3,1.7-0.6,2.5c-0.3,0.8-0.8,1.5-1.4,2.1c-0.9,0.7-2,1.2-3.1,1.4c-1.1,0.1-2.2,0.1-3.3,0.1c-0.3,0-0.5,0.1-0.6,0.4
|
||||||
|
c-0.1,0.2-0.2,0.4-0.2,0.6c-0.2,1.2-0.4,2.4-0.6,3.6c-0.1,0.4-0.4,0.7-0.8,0.7h-2.8c-0.3,0-0.5-0.2-0.5-0.5c0,0,0,0,0-0.1
|
||||||
|
c0.8-4.9,1.5-9.8,2.3-14.6C165.4,18.7,165.7,18.4,166,18.3z M169.1,21.5c-0.1,0.1-0.2,0.3-0.2,0.4c-0.2,1.2-0.4,2.5-0.6,3.7h0.9
|
||||||
|
c0.8,0.1,1.6-0.1,2.3-0.4c0.5-0.3,0.9-0.8,1-1.4c0.2-0.5,0.2-1.1,0-1.6c-0.2-0.4-0.5-0.6-0.9-0.8c-0.7-0.2-1.3-0.2-2-0.2
|
||||||
|
C169.5,21.4,169.3,21.4,169.1,21.5L169.1,21.5z"/>
|
||||||
|
<path class="st2" d="M179.3,24.1c1-0.6,2.1-0.9,3.2-0.8c0.9,0,1.7,0.2,2.5,0.6c0.3,0.2,0.5,0.5,0.7,0.8c0.1-0.3,0.1-0.5,0.1-0.8
|
||||||
|
c0.1-0.2,0.3-0.4,0.5-0.4h2.7c0.3,0,0.5,0.2,0.5,0.5c0,0,0,0.1,0,0.1c-0.5,3.1-1,6.2-1.5,9.4c-0.1,0.4-0.4,0.7-0.8,0.7h-2.5
|
||||||
|
c-0.2,0-0.4-0.1-0.5-0.3c0-0.1,0-0.3,0-0.4c0-0.2,0.1-0.4,0.1-0.6c-0.6,0.6-1.3,1-2.1,1.3c-0.9,0.3-1.9,0.3-2.9,0.1
|
||||||
|
c-0.7-0.1-1.4-0.5-2-1c-0.6-0.6-1.1-1.5-1.2-2.4c-0.2-1.1-0.1-2.1,0.2-3.2C176.9,26.2,177.9,24.9,179.3,24.1z M182.6,26.2
|
||||||
|
c-0.6,0.1-1.2,0.3-1.6,0.7c-0.6,0.5-1,1.1-1.1,1.9c-0.1,0.6,0,1.3,0.3,1.8c0.3,0.4,0.7,0.7,1.2,0.8c0.8,0.2,1.7,0.1,2.4-0.3
|
||||||
|
c1.1-0.7,1.7-1.9,1.5-3.2c-0.1-0.6-0.5-1.2-1.1-1.4C183.6,26.2,183.1,26.2,182.6,26.2z"/>
|
||||||
|
<path class="st2" d="M191,23.7c0.1-0.1,0.3-0.2,0.5-0.2h2.6c0.2,0,0.4,0.1,0.6,0.2c0.1,0.2,0.2,0.4,0.3,0.6l1.5,5.1
|
||||||
|
c1.2-1.7,2.3-3.5,3.5-5.2c0.1-0.2,0.3-0.4,0.4-0.6c0.2-0.1,0.4-0.2,0.6-0.2c0.9,0,1.8,0,2.7,0c0.3,0,0.5,0.3,0.4,0.5
|
||||||
|
c0,0.1,0,0.2-0.1,0.3l-9.2,13.2c-0.1,0.2-0.4,0.4-0.7,0.4h-2.7c-0.2,0-0.3,0-0.4-0.1c-0.2-0.2-0.2-0.5-0.1-0.7l2.8-3.9
|
||||||
|
c0-0.1,0-0.1,0-0.2l-3-8.8C190.8,24,190.9,23.8,191,23.7z"/>
|
||||||
|
<path class="st2" d="M206.9,18.3c0.1,0,0.2,0,0.4,0h5.1c1-0.1,2.1,0.1,3.1,0.4c0.8,0.3,1.4,0.8,1.9,1.5c0.5,0.9,0.7,1.8,0.5,2.8
|
||||||
|
c-0.1,1-0.4,2-0.9,2.9c-0.4,0.8-1,1.5-1.7,2c-0.8,0.5-1.7,0.9-2.7,1c-1.1,0.1-2.2,0.1-3.3,0.1c-0.3,0-0.5,0.2-0.6,0.4
|
||||||
|
c-0.1,0.2-0.1,0.4-0.2,0.6l-0.6,3.8c0,0.3-0.3,0.5-0.5,0.5h-3c-0.3,0-0.5-0.2-0.5-0.5c0,0,0,0,0-0.1c0.8-4.9,1.5-9.8,2.3-14.6
|
||||||
|
C206.3,18.6,206.6,18.4,206.9,18.3z M209.9,21.9c-0.2,1.3-0.4,2.5-0.6,3.8c0.9,0,1.8,0,2.7-0.2c0.5-0.1,0.9-0.4,1.1-0.7
|
||||||
|
c0.3-0.5,0.5-1,0.5-1.5c0.1-0.4-0.1-0.9-0.3-1.3c-0.3-0.3-0.7-0.5-1.1-0.5c-0.6-0.1-1.1-0.1-1.7-0.1
|
||||||
|
C210.1,21.4,209.9,21.6,209.9,21.9C209.9,21.8,209.9,21.8,209.9,21.9L209.9,21.9z"/>
|
||||||
|
<path class="st2" d="M233.6,18.3c0.1,0,0.3,0,0.4,0h2.4c0.3,0,0.5,0.2,0.5,0.5c0,0,0,0.1,0,0.1c-0.8,4.9-1.5,9.8-2.3,14.7
|
||||||
|
c-0.1,0.4-0.4,0.7-0.8,0.7h-2.4c-0.3,0-0.5-0.2-0.5-0.5c0,0,0-0.1,0-0.1c0.8-5,1.6-9.9,2.3-14.9C233.2,18.6,233.4,18.4,233.6,18.3z"
|
||||||
|
/>
|
||||||
|
<path class="st2" d="M152.5,19c0.8,0.4,1.5,1.2,1.8,2c0.3,1.1,0.4,2.2,0.1,3.3c-0.2,1.5-0.9,3-1.9,4.1c-0.6,0.7-1.4,1.3-2.3,1.6
|
||||||
|
c-1.3,0.5-2.7,0.7-4.1,0.7c-0.3,0-0.6,0-0.8,0.1c-0.3,0.2-0.5,0.5-0.6,0.8c-0.3,1.6-0.5,3.1-0.8,4.7c0,0.2-0.1,0.5-0.1,0.7
|
||||||
|
c-0.1,0.4-0.5,0.7-0.9,0.7H139c-0.2,0-0.5-0.1-0.6-0.3c-0.1-0.2-0.1-0.4,0-0.6c0.1-0.6,0.2-1.3,0.3-1.9c0-0.1,0-0.2,0.1-0.4
|
||||||
|
c0.3-2.3,0.7-4.6,1.1-6.8c0-0.2,0.1-0.4,0.2-0.7c0.2-0.2,0.4-0.4,0.7-0.5c0.3,0,0.6,0,0.9,0c1.2,0,2.4,0,3.6-0.1
|
||||||
|
c1.6-0.2,3.2-0.8,4.5-1.9c1.2-1.1,2-2.4,2.4-3.9C152.3,20.1,152.4,19.6,152.5,19z"/>
|
||||||
|
<path class="st2" d="M221.4,23.6c0.9-0.3,1.9-0.4,2.9-0.2c0.6,0.1,1.2,0.3,1.8,0.6c0.2,0.2,0.5,0.4,0.6,0.7c0-0.3,0.1-0.5,0.1-0.8
|
||||||
|
c0.1-0.2,0.3-0.4,0.5-0.3h2.7c0.3,0,0.5,0.2,0.5,0.5c0,0,0,0.1,0,0.1l-1.5,9.3c0,0.4-0.4,0.7-0.8,0.7h-2.5c-0.3,0-0.5-0.2-0.5-0.4
|
||||||
|
c0,0,0,0,0-0.1c0-0.3,0.1-0.5,0.1-0.8c-0.7,0.7-1.5,1.1-2.4,1.4c-0.9,0.2-1.8,0.2-2.7,0c-0.9-0.2-1.6-0.7-2.2-1.3
|
||||||
|
c-0.7-0.9-1-2-1-3.2c0-1.7,0.7-3.4,1.9-4.6C219.7,24.4,220.5,23.9,221.4,23.6z M223.5,26.2c-0.9,0.1-1.8,0.6-2.3,1.4
|
||||||
|
c-0.4,0.7-0.6,1.5-0.5,2.3c0.1,0.6,0.4,1.1,0.9,1.3c0.6,0.3,1.3,0.4,2,0.3c0.8-0.2,1.6-0.7,2-1.4c0.4-0.7,0.6-1.5,0.4-2.3
|
||||||
|
c-0.2-0.6-0.6-1.1-1.1-1.3C224.5,26.2,224.1,26.2,223.5,26.2L223.5,26.2z"/>
|
||||||
|
<path class="st2" d="M133.8,34.7c-0.2,0-0.3-0.1-0.3-0.3v-0.2c0.1-0.2,0.1-0.5,0.1-0.7l3.1-19.7c0-0.2,0.1-0.4,0.2-0.6
|
||||||
|
c0.1-0.2,0.3-0.3,0.6-0.3h8.5c1.4,0,2.7,0.3,4,0.9c0.9,0.5,1.7,1.3,2,2.3c0.3,0.9,0.3,1.8,0.1,2.8c-0.1,0.6-0.2,1.1-0.4,1.6
|
||||||
|
c-0.4,1.4-1.2,2.8-2.3,3.8c-1.2,1-2.7,1.6-4.3,1.8c-0.8,0.1-1.6,0.1-2.3,0.1h-1.7c-0.2,0-0.4,0-0.6,0c-0.4,0.1-0.7,0.3-0.9,0.7V27
|
||||||
|
v0.1c-0.1,0.2-0.1,0.5-0.2,0.8c-0.2,1-0.3,2-0.5,3.1c-0.2,1.3-0.4,2.5-0.6,3.8l0,0h-4.6L133.8,34.7z"/>
|
||||||
|
<path class="st0" d="M146,13.3c1.3,0,2.6,0.3,3.8,0.9c0.9,0.5,1.5,1.2,1.8,2.1c0.2,0.8,0.3,1.7,0.1,2.6l0,0l0,0
|
||||||
|
c-0.1,0.5-0.2,1-0.4,1.5c-0.4,1.4-1.1,2.6-2.2,3.6c-1.2,1-2.6,1.5-4.1,1.7c-0.8,0.1-1.5,0.1-2.3,0.1h-1.7c-0.2,0-0.4,0-0.6,0.1
|
||||||
|
c-0.5,0.1-0.9,0.4-1.1,0.8l-0.1,0.1V27c-0.1,0.3-0.1,0.5-0.2,0.8c-0.2,1-0.3,2-0.5,3c-0.2,1.2-0.4,2.3-0.6,3.5h-4.2
|
||||||
|
c0.1-0.2,0.1-0.5,0.1-0.7v-0.2l1.1-7.1l1.9-12.1c0-0.1,0-0.1,0-0.2c0-0.1,0-0.3,0.1-0.4c0.1-0.1,0.2-0.1,0.3-0.2L146,13.3 M146,12.5
|
||||||
|
h-8.6c-0.3,0-0.6,0.2-0.8,0.5c-0.2,0.3-0.2,0.6-0.3,0.9l-3,19.3c-0.1,0.3-0.1,0.6-0.2,1v0.3c0.1,0.3,0.3,0.5,0.6,0.6h4.4h0.5
|
||||||
|
c0-0.1,0-0.2,0.1-0.4c0.3-2.3,0.7-4.6,1.1-6.8c0-0.2,0.1-0.4,0.1-0.7c0.2-0.2,0.4-0.4,0.7-0.5c0.2,0,0.3,0,0.5,0h1.7
|
||||||
|
c0.8,0,1.6,0,2.4-0.1c1.6-0.2,3.2-0.8,4.5-1.9c1.2-1.1,2-2.4,2.4-3.9c0.2-0.5,0.3-1.1,0.4-1.7l0,0c0.2-1,0.1-2-0.1-2.9
|
||||||
|
c-0.4-1.1-1.2-2-2.2-2.6c-1.3-0.6-2.7-0.9-4.1-0.9l0,0L146,12.5z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 8.0 KiB |
@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"type": "exitTouchbar",
|
"type": "exitTouchbar",
|
||||||
"image": {
|
"image": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/Resources/logo.png"
|
"filePath": "~/git/selfProjects/MTMR/Resources/logo.png"
|
||||||
},
|
},
|
||||||
"width": 36, "align": "left" },
|
"width": 36, "align": "left" },
|
||||||
{ "type": "brightnessDown", "width": 36, "align": "left" },
|
{ "type": "brightnessDown", "width": 36, "align": "left" },
|
||||||
@ -12,46 +12,46 @@
|
|||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"filePath":
|
"filePath":
|
||||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.nowPlaying.scpt"
|
"~/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.nowPlaying.scpt"
|
||||||
},
|
},
|
||||||
"action": "appleScript",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.next.scpt"
|
"filePath": "~/git/selfProjects/MTMR/MTMR/AppleScripts/iTunes.next.scpt"
|
||||||
},
|
},
|
||||||
"refreshInterval": 1,
|
"refreshInterval": 1,
|
||||||
"image": {
|
"image": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/iTunes.png"
|
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/iTunes.png"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"filePath":
|
"filePath":
|
||||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.nowPlaying.scpt"
|
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.nowPlaying.scpt"
|
||||||
},
|
},
|
||||||
"action": "appleScript",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"filePath":
|
"filePath":
|
||||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.next.scpt"
|
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Spotify.next.scpt"
|
||||||
},
|
},
|
||||||
"refreshInterval": 1,
|
"refreshInterval": 1,
|
||||||
"image": {
|
"image": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/Spotify.png"
|
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/Spotify.png"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "appleScriptTitledButton",
|
"type": "appleScriptTitledButton",
|
||||||
"source": {
|
"source": {
|
||||||
"filePath":
|
"filePath":
|
||||||
"/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.nowPlaying.scpt"
|
"~/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.nowPlaying.scpt"
|
||||||
},
|
},
|
||||||
"action": "appleScript",
|
"action": "appleScript",
|
||||||
"actionAppleScript": {
|
"actionAppleScript": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.next.scpt"
|
"filePath": "~/git/selfProjects/MTMR/MTMR/AppleScripts/Vox.next.scpt"
|
||||||
},
|
},
|
||||||
"refreshInterval": 1,
|
"refreshInterval": 1,
|
||||||
"image": {
|
"image": {
|
||||||
"filePath": "/Users/toxblh/git/selfProjects/btt-touchbar-preset/icons/Vox.png"
|
"filePath": "~/git/selfProjects/btt-touchbar-preset/icons/Vox.png"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
1
Sparkle.framework/Autoupdate
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Autoupdate
|
||||||
1
Sparkle.framework/Headers
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Headers
|
||||||
1
Sparkle.framework/Modules
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Modules
|
||||||
1
Sparkle.framework/PrivateHeaders
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/PrivateHeaders
|
||||||
1
Sparkle.framework/Resources
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Resources
|
||||||
1
Sparkle.framework/Sparkle
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Sparkle
|
||||||
1
Sparkle.framework/Updater.app
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Versions/Current/Updater.app
|
||||||
BIN
Sparkle.framework/Versions/B/Autoupdate
Executable file
59
Sparkle.framework/Versions/B/Headers/SPUDownloadData.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// SPUDownloadData.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 8/10/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUILDING_SPARKLE_DOWNLOADER_SERVICE
|
||||||
|
// Ignore incorrect warning
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
|
||||||
|
#import "SUExport.h"
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#else
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for containing downloaded data along with some information about it.
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUDownloadData : NSObject <NSSecureCoding>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The raw data that was downloaded.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSData *data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL that was fetched from.
|
||||||
|
*
|
||||||
|
* This may be different from the URL in the request if there were redirects involved.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, copy) NSURL *URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The IANA charset encoding name if available. Eg: "utf-8"
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, nullable, copy) NSString *textEncodingName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MIME type if available. Eg: "text/plain"
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, nullable, copy) NSString *MIMEType;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
//
|
||||||
|
// SPUStandardUpdaterController.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 2/28/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class SPUUpdater;
|
||||||
|
@class SPUStandardUserDriver;
|
||||||
|
@class NSMenuItem;
|
||||||
|
@protocol SPUUserDriver, SPUUpdaterDelegate, SPUStandardUserDriverDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A controller class that instantiates a `SPUUpdater` and allows binding UI to its updater settings.
|
||||||
|
|
||||||
|
This class can be instantiated in a nib or created programatically using `-initWithUpdaterDelegate:userDriverDelegate:` or `-initWithStartingUpdater:updaterDelegate:userDriverDelegate:`.
|
||||||
|
|
||||||
|
The controller's updater targets the application's main bundle and uses Sparkle's standard user interface.
|
||||||
|
Typically, this class is used by sticking it as a custom NSObject subclass in an Interface Builder nib (probably in MainMenu) but it works well programatically too.
|
||||||
|
|
||||||
|
The controller creates an `SPUUpdater` instance using a `SPUStandardUserDriver` and allows hooking up the check for updates action and handling menu item validation.
|
||||||
|
It also allows hooking up the updater's and user driver's delegates.
|
||||||
|
|
||||||
|
If you need more control over what bundle you want to update, or you want to provide a custom user interface (via `SPUUserDriver`), please use `SPUUpdater` directly instead.
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUStandardUpdaterController : NSObject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Interface builder outlet for the updater's delegate.
|
||||||
|
*/
|
||||||
|
IBOutlet __weak id<SPUUpdaterDelegate> updaterDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface builder outlet for the user driver's delegate.
|
||||||
|
*/
|
||||||
|
IBOutlet __weak id<SPUStandardUserDriverDelegate> userDriverDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accessible property for the updater. Some properties on the updater can be binded via KVO
|
||||||
|
|
||||||
|
When instantiated from a nib, don't perform update checks before the application has finished launching in a MainMenu nib (i.e applicationDidFinishLaunching:) or before the corresponding window/view controller has been loaded (i.e, windowDidLoad or viewDidLoad). The updater is not guaranteed to be started yet before these points.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) SPUUpdater *updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accessible property for the updater's user driver.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) SPUStandardUserDriver *userDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new `SPUStandardUpdaterController` from a nib.
|
||||||
|
|
||||||
|
You cannot call this initializer directly. You must instantiate a `SPUStandardUpdaterController` inside of a nib (typically the MainMenu nib) to use it.
|
||||||
|
|
||||||
|
To create a `SPUStandardUpdaterController` programatically, use `-initWithUpdaterDelegate:userDriverDelegate:` or `-initWithStartingUpdater:updaterDelegate:userDriverDelegate:` instead.
|
||||||
|
*/
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new `SPUStandardUpdaterController` programmatically.
|
||||||
|
|
||||||
|
The updater is started automatically. See `-startUpdater` for more information.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithUpdaterDelegate:(nullable id<SPUUpdaterDelegate>)updaterDelegate userDriverDelegate:(nullable id<SPUStandardUserDriverDelegate>)userDriverDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a new `SPUStandardUpdaterController` programmatically allowing you to specify whether or not to start the updater immediately.
|
||||||
|
|
||||||
|
You can specify whether or not you want to start the updater immediately.
|
||||||
|
If you do not start the updater, you must invoke `-startUpdater` at a later time to start it.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithStartingUpdater:(BOOL)startUpdater updaterDelegate:(nullable id<SPUUpdaterDelegate>)updaterDelegate userDriverDelegate:(nullable id<SPUStandardUserDriverDelegate>)userDriverDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starts the updater if it has not already been started.
|
||||||
|
|
||||||
|
You should only call this method yourself if you opted out of starting the updater on initialization.
|
||||||
|
Hence, do not call this yourself if you are instantiating this controller from a nib.
|
||||||
|
|
||||||
|
This invokes `-[SPUUpdater startUpdater:]`. If the application is misconfigured with Sparkle, an error is logged and an alert is shown to the user (after a few seconds) to contact the developer.
|
||||||
|
If you want more control over this behavior, you can create your own `SPUUpdater` instead of using `SPUStandardUpdaterController`.
|
||||||
|
*/
|
||||||
|
- (void)startUpdater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Explicitly checks for updates and displays a progress dialog while doing so.
|
||||||
|
|
||||||
|
This method is meant for a main menu item.
|
||||||
|
Connect any NSMenuItem to this action in Interface Builder or programmatically,
|
||||||
|
and Sparkle will check for updates and report back its findings verbosely when it is invoked.
|
||||||
|
|
||||||
|
When the target/action of the menu item is set to this controller and this method,
|
||||||
|
this controller also handles enabling/disabling the menu item by checking
|
||||||
|
`-[SPUUpdater canCheckForUpdates]`
|
||||||
|
|
||||||
|
This action checks updates by invoking `-[SPUUpdater checkForUpdates]`
|
||||||
|
*/
|
||||||
|
- (IBAction)checkForUpdates:(nullable id)sender;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
44
Sparkle.framework/Versions/B/Headers/SPUStandardUserDriver.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// SPUStandardUserDriver.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 2/14/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SPUUserDriver.h>
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@protocol SPUStandardUserDriverDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sparkle's standard built-in user driver for updater interactions
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUStandardUserDriver : NSObject <SPUUserDriver>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a Sparkle's standard user driver for user update interactions
|
||||||
|
|
||||||
|
@param hostBundle The target bundle of the host that is being updated.
|
||||||
|
@param delegate The optional delegate to this user driver.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle delegate:(nullable id<SPUStandardUserDriverDelegate>)delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use initWithHostBundle:delegate: instead.
|
||||||
|
*/
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
//
|
||||||
|
// SPUStandardUserDriverDelegate.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 3/3/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
|
||||||
|
@protocol SUVersionDisplay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A protocol for Sparkle's standard user driver's delegate
|
||||||
|
|
||||||
|
This includes methods related to UI interactions
|
||||||
|
*/
|
||||||
|
SU_EXPORT @protocol SPUStandardUserDriverDelegate <NSObject>
|
||||||
|
|
||||||
|
@optional
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called before showing a modal alert window,
|
||||||
|
to give the opportunity to hide attached windows that may get in the way.
|
||||||
|
*/
|
||||||
|
- (void)standardUserDriverWillShowModalAlert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called after showing a modal alert window,
|
||||||
|
to give the opportunity to hide attached windows that may get in the way.
|
||||||
|
*/
|
||||||
|
- (void)standardUserDriverDidShowModalAlert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an object that formats version numbers for display to the user.
|
||||||
|
If you don't implement this method or return @c nil, the standard version formatter will be used.
|
||||||
|
*/
|
||||||
|
- (_Nullable id <SUVersionDisplay>)standardUserDriverRequestsVersionDisplayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handles showing the full release notes to the user.
|
||||||
|
|
||||||
|
When a user checks for new updates and no new update is found, Sparkle will offer to show the application's version history to the user
|
||||||
|
by providing a "Version History" button in the no new update available alert.
|
||||||
|
|
||||||
|
If this delegate method is not implemented, Sparkle will instead offer to open the
|
||||||
|
`fullReleaseNotesLink` (or `releaseNotesLink` if the former is unavailable) from the appcast's latest `item` in the user's web browser.
|
||||||
|
|
||||||
|
If this delegate method is implemented, Sparkle will instead ask the delegate to show the full release notes to the user.
|
||||||
|
A delegate may want to implement this method if they want to show in-app or offline release notes.
|
||||||
|
|
||||||
|
@param item The appcast item corresponding to the latest version available.
|
||||||
|
*/
|
||||||
|
- (void)standardUserDriverShowVersionHistoryForAppcastItem:(SUAppcastItem *_Nonnull)item;
|
||||||
|
|
||||||
|
@end
|
||||||
33
Sparkle.framework/Versions/B/Headers/SPUUpdateCheck.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//
|
||||||
|
// SPUUpdateCheck.h
|
||||||
|
// SPUUpdateCheck
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 8/28/21.
|
||||||
|
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SPUUpdateCheck_h
|
||||||
|
#define SPUUpdateCheck_h
|
||||||
|
|
||||||
|
/**
|
||||||
|
Describes the type of update check being performed.
|
||||||
|
|
||||||
|
Each update check corresponds to an update check method on `SPUUpdater`.
|
||||||
|
*/
|
||||||
|
typedef NS_ENUM(NSInteger, SPUUpdateCheck)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
The user-initiated update check corresponding to `-[SPUUpdater checkForUpdates]`.
|
||||||
|
*/
|
||||||
|
SPUUpdateCheckUpdates = 0,
|
||||||
|
/**
|
||||||
|
The background scheduled update check corresponding to `-[SPUUpdater checkForUpdatesInBackground]`.
|
||||||
|
*/
|
||||||
|
SPUUpdateCheckUpdatesInBackground = 1,
|
||||||
|
/**
|
||||||
|
The informational probe update check corresponding to `-[SPUUpdater checkForUpdateInformation]`.
|
||||||
|
*/
|
||||||
|
SPUUpdateCheckUpdateInformation = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SPUUpdateCheck_h */
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// SPUUpdatePermissionRequest.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 8/14/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
This class represents information needed to make a permission request for checking updates.
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUUpdatePermissionRequest : NSObject<NSSecureCoding>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a new update permission request instance.
|
||||||
|
|
||||||
|
@param systemProfile The system profile information.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithSystemProfile:(NSArray<NSDictionary<NSString *, NSString *> *> *)systemProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A read-only property for the user's system profile.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSArray<NSDictionary<NSString *, NSString *> *> *systemProfile;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
301
Sparkle.framework/Versions/B/Headers/SPUUpdater.h
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
//
|
||||||
|
// SPUUpdater.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Andy Matuschak on 1/4/06.
|
||||||
|
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
#import <Sparkle/SPUUserDriver.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class SUAppcastItem, SUAppcast;
|
||||||
|
|
||||||
|
@protocol SPUUpdaterDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The main API in Sparkle for controlling the update mechanism.
|
||||||
|
|
||||||
|
This class is used to configure the update parameters as well as manually and automatically schedule and control checks for updates.
|
||||||
|
|
||||||
|
For convenience, you can create a standard or nib instantiable updater by using `SPUStandardUpdaterController`.
|
||||||
|
|
||||||
|
Prefer to set initial properties in your bundle's Info.plist as described in [Customizing Sparkle](https://sparkle-project.org/documentation/customization/).
|
||||||
|
|
||||||
|
Otherwise only if you need dynamic behavior (eg. for user preferences) should you set properties on the updater such as:
|
||||||
|
- `automaticallyChecksForUpdates`
|
||||||
|
- `updateCheckInterval`
|
||||||
|
- `automaticallyDownloadsUpdates`
|
||||||
|
- `feedURL`
|
||||||
|
|
||||||
|
Please view the documentation on each of these properties for more detail if you are to configure them dynamically.
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUUpdater : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initializes a new `SPUUpdater` instance
|
||||||
|
|
||||||
|
This creates an updater, but to start it and schedule update checks `-startUpdater:` needs to be invoked first.
|
||||||
|
|
||||||
|
Related: See `SPUStandardUpdaterController` which wraps a `SPUUpdater` instance and is suitable for instantiating inside of nib files.
|
||||||
|
|
||||||
|
@param hostBundle The bundle that should be targetted for updating.
|
||||||
|
@param applicationBundle The application bundle that should be waited for termination and relaunched (unless overridden). Usually this can be the same as hostBundle. This may differ when updating a plug-in or other non-application bundle.
|
||||||
|
@param userDriver The user driver that Sparkle uses for user update interaction.
|
||||||
|
@param delegate The delegate for `SPUUpdater`.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle applicationBundle:(NSBundle *)applicationBundle userDriver:(id <SPUUserDriver>)userDriver delegate:(nullable id<SPUUpdaterDelegate>)delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use `-initWithHostBundle:applicationBundle:userDriver:delegate:` or `SPUStandardUpdaterController` standard adapter instead.
|
||||||
|
|
||||||
|
If you want to drop an updater into a nib, use `SPUStandardUpdaterController`.
|
||||||
|
*/
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starts the updater.
|
||||||
|
|
||||||
|
This method first checks if Sparkle is configured properly. A valid feed URL should be set before this method is invoked.
|
||||||
|
|
||||||
|
If the configuration is valid, an update cycle is started in the next main runloop cycle.
|
||||||
|
During this cycle, a permission prompt may be brought up (if needed) for checking if the user wants automatic update checking.
|
||||||
|
Otherwise if automatic update checks are enabled, a scheduled update alert may be brought up if enough time has elapsed since the last check.
|
||||||
|
See `automaticallyChecksForUpdates` for more information.
|
||||||
|
|
||||||
|
After starting the updater and before the next runloop cycle, one of `-checkForUpdates`, `-checkForUpdatesInBackground`, or `-checkForUpdateInformation` can be invoked.
|
||||||
|
This may be useful if you want to check for updates immediately or without showing a potential permission prompt.
|
||||||
|
|
||||||
|
If the updater cannot be started (i.e, due to a configuration issue in the application), you may want to fall back appropriately.
|
||||||
|
For example, the standard updater controller (`SPUStandardUpdaterController`) alerts the user that the app is misconfigured and to contact the developer.
|
||||||
|
|
||||||
|
This must be called on the main thread.
|
||||||
|
|
||||||
|
@param error The error that is populated if this method fails. Pass NULL if not interested in the error information.
|
||||||
|
@return YES if the updater started otherwise NO with a populated error
|
||||||
|
*/
|
||||||
|
- (BOOL)startUpdater:(NSError * __autoreleasing *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks for updates, and displays progress while doing so if needed.
|
||||||
|
|
||||||
|
This is meant for users initiating a new update check or checking the current update progress.
|
||||||
|
|
||||||
|
If an update hasn't started, the user may be shown that a new check for updates is occurring.
|
||||||
|
If an update has already been downloaded or begun installing from a previous session, the user may be presented to install that update.
|
||||||
|
If the user is already being presented with an update, that update will be shown to the user in active focus.
|
||||||
|
|
||||||
|
This will find updates that the user has previously opted into skipping.
|
||||||
|
|
||||||
|
See `canCheckForUpdates` property which can determine when this method may be invoked.
|
||||||
|
*/
|
||||||
|
- (void)checkForUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Checks for updates, but does not display any UI unless an update is found.
|
||||||
|
|
||||||
|
You usually do not need to call this method directly. If `automaticallyChecksForUpdates` is @c YES,
|
||||||
|
Sparkle calls this method automatically according to its update schedule using the `updateCheckInterval`
|
||||||
|
and the `lastUpdateCheckDate`.
|
||||||
|
|
||||||
|
This is meant for programmatically initating a check for updates.
|
||||||
|
That is, it will display no UI unless it finds an update, in which case it proceeds as usual.
|
||||||
|
This will not find updates that the user has opted into skipping.
|
||||||
|
|
||||||
|
Note if there is no resumable update found, and automated updating is turned on,
|
||||||
|
the update will be downloaded in the background without disrupting the user.
|
||||||
|
|
||||||
|
This method does not do anything if there is a `sessionInProgress`.
|
||||||
|
*/
|
||||||
|
- (void)checkForUpdatesInBackground;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Begins a "probing" check for updates which will not actually offer to
|
||||||
|
update to that version.
|
||||||
|
|
||||||
|
However, the delegate methods
|
||||||
|
`-[SPUUpdaterDelegate updater:didFindValidUpdate:]` and
|
||||||
|
`-[SPUUpdaterDelegate updaterDidNotFindUpdate:]` will be called,
|
||||||
|
so you can use that information in your UI.
|
||||||
|
|
||||||
|
`-[SPUUpdaterDelegate updater:didFinishUpdateCycleForUpdateCheck:error:]` will be called when
|
||||||
|
this probing check is completed.
|
||||||
|
|
||||||
|
Updates that have been skipped by the user will not be found.
|
||||||
|
|
||||||
|
This method does not do anything if there is a `sessionInProgress`.
|
||||||
|
*/
|
||||||
|
- (void)checkForUpdateInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating whether or not updates can be checked by the user.
|
||||||
|
|
||||||
|
An update check can be made by the user when an update session isn't in progress, or when an update or its progress is being shown to the user.
|
||||||
|
A user cannot check for updates when data (such as the feed or an update) is still being downloaded automatically in the background.
|
||||||
|
|
||||||
|
This property is suitable to use for menu item validation for seeing if `-checkForUpdates` can be invoked.
|
||||||
|
|
||||||
|
This property is also KVO-compliant.
|
||||||
|
|
||||||
|
Note this property does not reflect whether or not an update session is in progress. Please see `sessionInProgress` property instead.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL canCheckForUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating whether or not an update session is in progress.
|
||||||
|
|
||||||
|
An update session is in progress when the appcast is being downloaded, an update is being downloaded,
|
||||||
|
an update is being shown, update permission is being requested, or the installer is being started.
|
||||||
|
|
||||||
|
An active session is when Sparkle's fired scheduler is running.
|
||||||
|
|
||||||
|
Note an update session may not be running even though Sparkle's installer (ran as a separate process) may be running,
|
||||||
|
or even though the update has been downloaded but the installation has been deferred. In both of these cases, a new update session
|
||||||
|
may be activated with the update resumed at a later point (automatically or manually).
|
||||||
|
|
||||||
|
See also:
|
||||||
|
- `canCheckForUpdates` property which is more suited for menu item validation and deciding if the user can initiate update checks.
|
||||||
|
- `-[SPUUpdaterDelegate updater:didFinishUpdateCycleForUpdateCheck:error:]` which lets the updater delegate know when an update cycle and session finishes.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL sessionInProgress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating whether or not to check for updates automatically.
|
||||||
|
|
||||||
|
By default, Sparkle asks users on second launch for permission if they want automatic update checks enabled
|
||||||
|
and sets this property based on their response. If `SUEnableAutomaticChecks` is set in the Info.plist,
|
||||||
|
this permission request is not performed however.
|
||||||
|
|
||||||
|
Setting this property will persist in the host bundle's user defaults.
|
||||||
|
Only set this property if you need dynamic behavior (e.g. user preferences).
|
||||||
|
|
||||||
|
The update schedule cycle will be reset in a short delay after the property's new value is set.
|
||||||
|
This is to allow reverting this property without kicking off a schedule change immediately
|
||||||
|
*/
|
||||||
|
@property (nonatomic) BOOL automaticallyChecksForUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating the current automatic update check interval in seconds.
|
||||||
|
|
||||||
|
Setting this property will persist in the host bundle's user defaults.
|
||||||
|
For this reason, only set this property if you need dynamic behavior (eg user preferences).
|
||||||
|
Otherwise prefer to set SUScheduledCheckInterval directly in your Info.plist.
|
||||||
|
|
||||||
|
The update schedule cycle will be reset in a short delay after the property's new value is set.
|
||||||
|
This is to allow reverting this property without kicking off a schedule change immediately
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSTimeInterval updateCheckInterval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating whether or not updates can be automatically downloaded in the background.
|
||||||
|
|
||||||
|
By default, updates are not automatically downloaded.
|
||||||
|
|
||||||
|
Note that the developer can disallow automatic downloading of updates from being enabled.
|
||||||
|
In this case, this property will return NO regardless of how this property is set.
|
||||||
|
|
||||||
|
Setting this property will persist in the host bundle's user defaults.
|
||||||
|
For this reason, only set this property if you need dynamic behavior (eg user preferences).
|
||||||
|
Otherwise prefer to set SUAutomaticallyUpdate directly in your Info.plist.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) BOOL automaticallyDownloadsUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The URL of the appcast used to download update information.
|
||||||
|
|
||||||
|
If the updater's delegate implements `-[SPUUpdaterDelegate feedURLStringForUpdater:]`, this will return that feed URL.
|
||||||
|
Otherwise if the feed URL has been set before, the feed URL returned will be retrieved from the host bundle's user defaults.
|
||||||
|
Otherwise the feed URL in the host bundle's Info.plist will be returned.
|
||||||
|
If no feed URL can be retrieved, returns nil.
|
||||||
|
|
||||||
|
This property must be called on the main thread; calls from background threads will return nil.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, nullable) NSURL *feedURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the URL of the appcast used to download update information. Using this method is discouraged.
|
||||||
|
|
||||||
|
Setting this property will persist in the host bundle's user defaults.
|
||||||
|
To avoid this, you should consider implementing
|
||||||
|
`-[SPUUpdaterDelegate feedURLStringForUpdater:]` instead of using this method.
|
||||||
|
|
||||||
|
Passing nil will remove any feed URL that has been set in the host bundle's user defaults.
|
||||||
|
If you do not need to alternate between multiple feeds, set the SUFeedURL in your Info.plist instead of invoking this method.
|
||||||
|
|
||||||
|
For beta updates, you may consider migrating to `-[SPUUpdaterDelegate allowedChannelsForUpdater:]` in the future.
|
||||||
|
|
||||||
|
This method must be called on the main thread; calls from background threads will have no effect.
|
||||||
|
*/
|
||||||
|
- (void)setFeedURL:(nullable NSURL *)feedURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The host bundle that is being updated.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSBundle *hostBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The user agent used when checking for updates.
|
||||||
|
|
||||||
|
By default the user agent string returned is in the format:
|
||||||
|
$(BundleDisplayName)/$(BundleDisplayVersion) Sparkle/$(SparkleDisplayVersion)
|
||||||
|
|
||||||
|
BundleDisplayVersion is derived from the main application's Info.plist's CFBundleShortVersionString.
|
||||||
|
|
||||||
|
Note if Sparkle is being used to update another application, the bundle information retrieved is from the main application performing the updating.
|
||||||
|
|
||||||
|
This default implementation can be overrided.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, copy) NSString *userAgentString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The HTTP headers used when checking for updates, downloading release notes, and downloading updates.
|
||||||
|
|
||||||
|
The keys of this dictionary are HTTP header fields and values are corresponding values.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, copy, nullable) NSDictionary<NSString *, NSString *> *httpHeaders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A property indicating whether or not the user's system profile information is sent when checking for updates.
|
||||||
|
|
||||||
|
Setting this property will persist in the host bundle's user defaults.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) BOOL sendsSystemProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The date of the last update check or nil if no check has been performed yet.
|
||||||
|
|
||||||
|
For testing purposes, the last update check is stored in the `SULastCheckTime` key in the host bundle's user defaults.
|
||||||
|
For example, `defaults delete my-bundle-id SULastCheckTime` can be invoked to clear the last update check time and test
|
||||||
|
if update checks are automatically scheduled.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, copy, nullable) NSDate *lastUpdateCheckDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Appropriately schedules or cancels the update checking timer according to the preferences for time interval and automatic checks.
|
||||||
|
|
||||||
|
If you change the `updateCheckInterval` or `automaticallyChecksForUpdates` properties, the update cycle will be reset automatically after a short delay.
|
||||||
|
The update cycle is also started automatically after the updater is started. In all these cases, this method should not be called directly.
|
||||||
|
|
||||||
|
This call does not change the date of the next check, but only the internal timer.
|
||||||
|
*/
|
||||||
|
- (void)resetUpdateCycle;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
The system profile information that is sent when checking for updates.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, copy) NSArray<NSDictionary<NSString *, NSString *> *> *systemProfileArray;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
458
Sparkle.framework/Versions/B/Headers/SPUUpdaterDelegate.h
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
//
|
||||||
|
// SPUUpdaterDelegate.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 8/12/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
#import <Sparkle/SPUUpdateCheck.h>
|
||||||
|
|
||||||
|
@protocol SUVersionComparison;
|
||||||
|
@class SPUUpdater, SUAppcast, SUAppcastItem;
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// SUUpdater Notifications for events that might be interesting to more than just the delegate
|
||||||
|
// The updater will be the notification object
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterDidFinishLoadingAppCastNotification;
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterDidFindValidUpdateNotification;
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterDidNotFindUpdateNotification;
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterWillRestartNotification;
|
||||||
|
#define SUUpdaterWillRelaunchApplicationNotification SUUpdaterWillRestartNotification;
|
||||||
|
#define SUUpdaterWillInstallUpdateNotification SUUpdaterWillRestartNotification;
|
||||||
|
|
||||||
|
// Key for the SUAppcastItem object in the SUUpdaterDidFindValidUpdateNotification userInfo
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterAppcastItemNotificationKey;
|
||||||
|
// Key for the SUAppcast object in the SUUpdaterDidFinishLoadingAppCastNotification userInfo
|
||||||
|
SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// System Profile Keys
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerApplicationNameKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerApplicationVersionKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerCPU64bitKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerCPUCountKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerCPUFrequencyKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerCPUTypeKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerCPUSubtypeKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerHardwareModelKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerMemoryKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerOperatingSystemVersionKey;
|
||||||
|
SU_EXPORT extern NSString *const SUSystemProfilerPreferredLanguageKey;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// SPUUpdater Delegate:
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Provides delegation methods to control the behavior of an `SPUUpdater` object.
|
||||||
|
*/
|
||||||
|
@protocol SPUUpdaterDelegate <NSObject>
|
||||||
|
@optional
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether to allow Sparkle to check for updates.
|
||||||
|
|
||||||
|
For example, this may be used to prevent Sparkle from interrupting a setup assistant.
|
||||||
|
Alternatively, you may want to consider starting the updater after eg: the setup assistant finishes.
|
||||||
|
|
||||||
|
Note in Swift, this method returns Void and is marked with the throws keyword. If this method
|
||||||
|
doesn't throw an error, the updater may perform an update check. Otherwise if an error is thrown (we recommend using an NSError),
|
||||||
|
then the updater may not perform an update check.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param updateCheck The type of update check that will be performed if the updater is allowed to check for updates.
|
||||||
|
@param error The populated error object if the updater may not perform a new update check. The @c NSLocalizedDescriptionKey user info key should be populated indicating a description of the error.
|
||||||
|
@return @c YES if the updater is allowed to check for updates, otherwise @c NO
|
||||||
|
*/
|
||||||
|
- (BOOL)updater:(SPUUpdater *)updater mayPerformUpdateCheck:(SPUUpdateCheck)updateCheck error:(NSError * __autoreleasing *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the set of Sparkle channels the updater is allowed to find new updates from.
|
||||||
|
|
||||||
|
An appcast item can specify a channel the update is posted to. Without specifying a channel, the appcast item is posted to the default channel.
|
||||||
|
For instance:
|
||||||
|
```
|
||||||
|
<item>
|
||||||
|
<sparkle:version>2.0 Beta 1</sparkle:version>
|
||||||
|
<sparkle:channel>beta</sparkle:channel>
|
||||||
|
</item>
|
||||||
|
```
|
||||||
|
|
||||||
|
This example posts an update to the @c beta channel, so only updaters that are allowed to use the @c beta channel can find this update.
|
||||||
|
|
||||||
|
If the @c <sparkle:channel> element is not present, the update item is posted to the default channel and can be found by any updater.
|
||||||
|
|
||||||
|
You can pick any name you'd like for the channel. The valid characters for channel names are letters, numbers, dashes, underscores, and periods.
|
||||||
|
|
||||||
|
Note to use this feature, all app versions that your users may update from in your feed must use a version of Sparkle that supports this feature.
|
||||||
|
This feature was added in Sparkle 2.
|
||||||
|
|
||||||
|
@return The set of channel names the updater is allowed to find new updates in. An empty set is the default behavior,
|
||||||
|
which means the updater will only look for updates in the default channel.
|
||||||
|
*/
|
||||||
|
- (NSSet<NSString *> *)allowedChannelsForUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a custom appcast URL used for checking for new updates.
|
||||||
|
|
||||||
|
Override this to dynamically specify the feed URL.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return An appcast feed URL to check for new updates in, or @c nil for the default behavior and if you don't want to be delegated this task.
|
||||||
|
*/
|
||||||
|
- (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns additional parameters to append to the appcast URL's query string.
|
||||||
|
|
||||||
|
This is potentially based on whether or not Sparkle will also be sending along the system profile.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param sendingProfile Whether the system profile will also be sent.
|
||||||
|
|
||||||
|
@return An array of dictionaries with keys: `key`, `value`, `displayKey`, `displayValue`, the latter two being specifically for display to the user.
|
||||||
|
*/
|
||||||
|
- (NSArray<NSDictionary<NSString *, NSString *> *> *)feedParametersForUpdater:(SPUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether Sparkle should prompt the user about checking for new updates automatically.
|
||||||
|
|
||||||
|
Use this to override the default behavior.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return @c YES if the updater should prompt for permission to check for new updates automatically, otherwise @c NO
|
||||||
|
*/
|
||||||
|
- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an allowed list of system profile keys to be appended to the appcast URL's query string.
|
||||||
|
|
||||||
|
By default all keys will be included. This method allows overriding which keys should only be allowed.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
|
||||||
|
@return An array of system profile keys to include in the appcast URL's query string. Elements must be one of the `SUSystemProfiler*Key` constants. Return @c nil for the default behavior and if you don't want to be delegated this task.
|
||||||
|
*/
|
||||||
|
- (nullable NSArray<NSString *> *)allowedSystemProfileKeysForUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called after Sparkle has downloaded the appcast from the remote server.
|
||||||
|
|
||||||
|
Implement this if you want to do some special handling with the appcast once it finishes loading.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param appcast The appcast that was downloaded from the remote server.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when a new valid update is found by the update driver.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be installed.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when a valid new update is not found.
|
||||||
|
|
||||||
|
There are various reasons a new update is unavailable and can't be installed.
|
||||||
|
|
||||||
|
The userInfo dictionary on the error is populated with three keys:
|
||||||
|
- `SPULatestAppcastItemFoundKey`: if available, this may provide the latest `SUAppcastItem` that was found. This will be @c nil if it's unavailable.
|
||||||
|
- `SPUNoUpdateFoundReasonKey`: This will provide the `SPUNoUpdateFoundReason`.
|
||||||
|
For example the reason could be because the latest version in the feed requires a newer OS version or could be because the user is already on the latest version.
|
||||||
|
- `SPUNoUpdateFoundUserInitiatedKey`: A boolean that indicates if a new update was not found when the user intitiated an update check manually.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param error An error containing information on why a new valid update was not found
|
||||||
|
*/
|
||||||
|
- (void)updaterDidNotFindUpdate:(SPUUpdater *)updater error:(NSError *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when a valid new update is not found.
|
||||||
|
|
||||||
|
If more information is needed on why an update was not found, use `-[SPUUpdaterDelegate updaterDidNotFindUpdate:error:]` instead.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
*/
|
||||||
|
- (void)updaterDidNotFindUpdate:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the item in the appcast corresponding to the update that should be installed.
|
||||||
|
|
||||||
|
Please consider using or migrating to other supported features before adopting this method.
|
||||||
|
Specifically:
|
||||||
|
- If you want to filter out certain tagged updates (like beta updates), consider `-[SPUUpdaterDelegate allowedChannelsForUpdater:]` instead.
|
||||||
|
- If you want to treat certain updates as informational-only, consider supplying @c <sparkle:informationalUpdate> with a set of affected versions users are updating from.
|
||||||
|
|
||||||
|
If you're using special logic or extensions in your appcast, implement this to use your own logic for finding a valid update, if any, in the given appcast.
|
||||||
|
|
||||||
|
Do not base your logic by filtering out items with a minimum or maximum OS version or minimum autoupdate version
|
||||||
|
because Sparkle already has logic for determining whether or not those items should be filtered out.
|
||||||
|
|
||||||
|
Also do not return a non-top level item from the appcast such as a delta item. Delta items will be ignored.
|
||||||
|
Sparkle picks the delta item from your selection if the appropriate one is available.
|
||||||
|
|
||||||
|
This method will not be invoked with an appcast that has zero items. Pick the best item from the appcast.
|
||||||
|
If an item is available that has the same version as the application or bundle to update, do not pick an item that is worse than that version.
|
||||||
|
|
||||||
|
This method may be called multiple times for different selections and filters. This method should be efficient.
|
||||||
|
|
||||||
|
Return `+[SUAppcastItem emptyAppcastItem]` if no appcast item is valid.
|
||||||
|
|
||||||
|
Return @c nil if you don't want to be delegated this task and want to let Sparkle handle picking the best valid update.
|
||||||
|
|
||||||
|
@param appcast The appcast that was downloaded from the remote server.
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return The best valid appcast item.
|
||||||
|
*/
|
||||||
|
- (nullable SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether or not the updater should proceed with the new chosen update from the appcast.
|
||||||
|
|
||||||
|
By default, the updater will always proceed with the best selected update found in an appcast. Override this to override this behavior.
|
||||||
|
|
||||||
|
If you return @c NO and populate the @c error, the user is not shown this @c updateItem nor is the update downloaded or installed.
|
||||||
|
|
||||||
|
Note in Swift, this method returns Void and is marked with the throws keyword. If this method doesn't throw an error, the updater will proceed with the update.
|
||||||
|
Otherwise if an error is thrown (we recommend using an NSError), then the will not proceed with the update.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param updateItem The selected update item to proceed with.
|
||||||
|
@param updateCheck The type of update check that would be performed if proceeded.
|
||||||
|
@param error An error object that must be populated by the delegate if the updater should not proceed with the update. The @c NSLocalizedDescriptionKey user info key should be populated indicating a description of the error.
|
||||||
|
@return @c YES if the updater should proceed with @c updateItem, otherwise @c NO if the updater should not proceed with the update with an @c error populated.
|
||||||
|
*/
|
||||||
|
- (BOOL)updater:(SPUUpdater *)updater shouldProceedWithUpdate:(SUAppcastItem *)updateItem updateCheck:(SPUUpdateCheck)updateCheck error:(NSError * __autoreleasing *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when an update is skipped by the user.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that the user skipped.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater userDidSkipThisVersion:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether the release notes (if available) should be downloaded after an update is found and shown.
|
||||||
|
|
||||||
|
This is specifically for the @c <releaseNotesLink> element in the appcast item.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param updateItem The update item to download and show release notes from.
|
||||||
|
|
||||||
|
@return @c YES to download and show the release notes if available, otherwise @c NO. The default behavior is @c YES.
|
||||||
|
*/
|
||||||
|
- (BOOL)updater:(SPUUpdater *)updater shouldDownloadReleaseNotesForUpdate:(SUAppcastItem *)updateItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately before downloading the specified update.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be downloaded.
|
||||||
|
@param request The mutable URL request that will be used to download the update.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately after succesfull download of the specified update.
|
||||||
|
|
||||||
|
@param updater The SUUpdater instance.
|
||||||
|
@param item The appcast item corresponding to the update that has been downloaded.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didDownloadUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called after the specified update failed to download.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that failed to download.
|
||||||
|
@param error The error generated by the failed download.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when the user cancels an update while it is being downloaded.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
*/
|
||||||
|
- (void)userDidCancelDownload:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately before extracting the specified downloaded update.
|
||||||
|
|
||||||
|
@param updater The SUUpdater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be extracted.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater willExtractUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately after extracting the specified downloaded update.
|
||||||
|
|
||||||
|
@param updater The SUUpdater instance.
|
||||||
|
@param item The appcast item corresponding to the update that has been extracted.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didExtractUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately before installing the specified update.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be installed.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether the relaunch should be delayed in order to perform other tasks.
|
||||||
|
|
||||||
|
This is not called if the user didn't relaunch on the previous update,
|
||||||
|
in that case it will immediately restart.
|
||||||
|
|
||||||
|
This may also not be called if the application is not going to relaunch after it terminates.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be installed.
|
||||||
|
@param installHandler The install handler that must be completed before continuing with the relaunch.
|
||||||
|
|
||||||
|
@return @c YES to delay the relaunch until @c installHandler is invoked.
|
||||||
|
*/
|
||||||
|
- (BOOL)updater:(SPUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvokingBlock:(void (^)(void))installHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns whether the application should be relaunched at all.
|
||||||
|
|
||||||
|
Some apps **cannot** be relaunched under certain circumstances.
|
||||||
|
This method can be used to explicitly prevent a relaunch.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return @c YES if the updater should be relaunched, otherwise @c NO if it shouldn't.
|
||||||
|
*/
|
||||||
|
- (BOOL)updaterShouldRelaunchApplication:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called immediately before relaunching.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
*/
|
||||||
|
- (void)updaterWillRelaunchApplication:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns an object that compares version numbers to determine their arithmetic relation to each other.
|
||||||
|
|
||||||
|
This method allows you to provide a custom version comparator.
|
||||||
|
If you don't implement this method or return @c nil,
|
||||||
|
the standard version comparator will be used.
|
||||||
|
|
||||||
|
Note that the standard version comparator may be used during installation for preventing a downgrade,
|
||||||
|
even if you provide a custom comparator here.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return The custom version comparator or @c nil if you don't want to be delegated this task.
|
||||||
|
*/
|
||||||
|
- (nullable id<SUVersionComparison>)versionComparatorForUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when a background update will be scheduled after a delay.
|
||||||
|
|
||||||
|
Automatic update checks need to be enabled for this to trigger.
|
||||||
|
|
||||||
|
@param delay The delay in seconds until the next scheduled update will occur. This is an approximation and may vary due to system state.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater willScheduleUpdateCheckAfterDelay:(NSTimeInterval)delay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when no update checks will be scheduled in the future.
|
||||||
|
|
||||||
|
This may later change if automatic update checks become enabled.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
*/
|
||||||
|
- (void)updaterWillNotScheduleUpdateCheck:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the decryption password (if any) which is used to extract the update archive DMG.
|
||||||
|
|
||||||
|
Return @c nil if no password should be used.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@return The password used for decrypting the archive, or @c nil if no password should be used.
|
||||||
|
*/
|
||||||
|
- (nullable NSString *)decryptionPasswordForUpdater:(SPUUpdater *)updater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called when an update is scheduled to be silently installed on quit after downloading the update automatically.
|
||||||
|
|
||||||
|
If the updater is given responsibility, it can later remind the user an update is available if they have not terminated the application for a long time.
|
||||||
|
|
||||||
|
Also if the updater is given responsibility and the update item is marked critical, the new update will be presented to the user immediately after.
|
||||||
|
|
||||||
|
Even if the @c immediateInstallHandler is not invoked, the installer will attempt to install the update on termination.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param item The appcast item corresponding to the update that is proposed to be installed.
|
||||||
|
@param immediateInstallHandler The install handler to immediately install the update. No UI interaction will be shown and the application will be relaunched after installation.
|
||||||
|
@return @c YES if the delegate will handle installing the update or @c NO if the updater should be given responsibility.
|
||||||
|
*/
|
||||||
|
- (BOOL)updater:(SPUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationBlock:(void (^)(void))immediateInstallHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called after the update driver aborts due to an error.
|
||||||
|
|
||||||
|
The update driver runs when checking for updates. This delegate method is called an error occurs during this process.
|
||||||
|
|
||||||
|
Some special possible values of `error.code` are:
|
||||||
|
|
||||||
|
- `SUNoUpdateError`: No new update was found.
|
||||||
|
- `SUInstallationCanceledError`: The user canceled installing the update when requested for authorization.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param error The error that caused the update driver to abort.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didAbortWithError:(NSError *)error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Called after the update driver finishes.
|
||||||
|
|
||||||
|
The update driver runs when checking for updates. This delegate method is called when that check is finished.
|
||||||
|
|
||||||
|
An update may be scheduled to be installed during the update cycle, or no updates may be found, or an available update may be dismissed or skipped (which is the same as no error).
|
||||||
|
|
||||||
|
If the @c error is @c nil, no error has occurred.
|
||||||
|
|
||||||
|
Some special possible values of `error.code` are:
|
||||||
|
|
||||||
|
- `SUNoUpdateError`: No new update was found.
|
||||||
|
- `SUInstallationCanceledError`: The user canceled installing the update when requested for authorization.
|
||||||
|
|
||||||
|
@param updater The updater instance.
|
||||||
|
@param updateCheck The type of update check was performed.
|
||||||
|
@param error The error that caused the update driver to abort. This is @c nil if the update driver finished normally and there is no error.
|
||||||
|
*/
|
||||||
|
- (void)updater:(SPUUpdater *)updater didFinishUpdateCycleForUpdateCheck:(SPUUpdateCheck)updateCheck error:(nullable NSError *)error;
|
||||||
|
|
||||||
|
/* Deprecated methods */
|
||||||
|
|
||||||
|
- (BOOL)updaterMayCheckForUpdates:(SPUUpdater *)updater __deprecated_msg("Please use -[SPUUpdaterDelegate updater:mayPerformUpdateCheck:error:] instead.");
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
61
Sparkle.framework/Versions/B/Headers/SPUUpdaterSettings.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
//
|
||||||
|
// SPUUpdaterSettings.h
|
||||||
|
// Sparkle
|
||||||
|
//
|
||||||
|
// Created by Mayur Pawashe on 3/27/16.
|
||||||
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#if __has_feature(modules)
|
||||||
|
#if __has_warning("-Watimport-in-framework-header")
|
||||||
|
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
|
||||||
|
#endif
|
||||||
|
@import Foundation;
|
||||||
|
#else
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#endif
|
||||||
|
#import <Sparkle/SUExport.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
This class can be used for reading certain updater settings.
|
||||||
|
|
||||||
|
It retrieves the settings by first looking into the host's user defaults.
|
||||||
|
If the setting is not found in there, then the host's Info.plist file is looked at.
|
||||||
|
*/
|
||||||
|
SU_EXPORT @interface SPUUpdaterSettings : NSObject
|
||||||
|
|
||||||
|
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether or not automatic update checks are enabled.
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) BOOL automaticallyChecksForUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The regular update check interval.
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) NSTimeInterval updateCheckInterval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether or not automatically downloading updates is allowed to be turned on by the user.
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) BOOL allowsAutomaticUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether or not automatically downloading updates is enabled by the user or developer.
|
||||||
|
*
|
||||||
|
* Note this does not indicate whether or not automatic downloading of updates is allowable.
|
||||||
|
* See `-allowsAutomaticUpdates` property for that.
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) BOOL automaticallyDownloadsUpdates;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether or not anonymous system profile information is sent when checking for updates.
|
||||||
|
*/
|
||||||
|
@property (readonly, nonatomic) BOOL sendsSystemProfile;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||