From 8e35d38b59a7a9648fc2f52ad78fea87a677a7f4 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Fri, 8 Jun 2018 00:08:15 +0100 Subject: [PATCH] prepare for 10.14 --- MTMR.xcodeproj/project.pbxproj | 4 ++++ MTMR/CBridge/TouchBarPrivateApi.h | 11 +++++++---- MTMR/SupportNSTouchBar.swift | 31 +++++++++++++++++++++++++++++++ MTMR/TouchBarController.swift | 16 ++++++++-------- MTMR/Widgets/GroupBarItem.swift | 4 ++-- 5 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 MTMR/SupportNSTouchBar.swift diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index d22c61e..d431b04 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ B0B17438207D6B590004B740 /* Vox.next.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0B1742E207D6B590004B740 /* Vox.next.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 */; }; + B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */; }; B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; }; /* End PBXBuildFile section */ @@ -107,6 +108,7 @@ B0B1742E207D6B590004B740 /* Vox.next.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.next.scpt; sourceTree = ""; }; B0B1742F207D6B590004B740 /* Vox.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Vox.nowPlaying.scpt; sourceTree = ""; }; B0B17430207D6B590004B740 /* iTunes.nowPlaying.scpt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iTunes.nowPlaying.scpt; sourceTree = ""; }; + B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportNSTouchBar.swift; sourceTree = ""; }; B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = ""; }; B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -183,6 +185,7 @@ 368EDDE620812A1D00E10953 /* ScrollViewItem.swift */, B05600D22083E9BB00EB218D /* CustomSlider.swift */, 36A778BD20A6C27100B38714 /* GeneralExtensions.swift */, + B0F3112420C9E35F0076BB88 /* SupportNSTouchBar.swift */, ); path = MTMR; sourceTree = ""; @@ -375,6 +378,7 @@ 60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */, 6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */, 607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */, + B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */, 6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */, B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */, 60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */, diff --git a/MTMR/CBridge/TouchBarPrivateApi.h b/MTMR/CBridge/TouchBarPrivateApi.h index 7873691..a787647 100644 --- a/MTMR/CBridge/TouchBarPrivateApi.h +++ b/MTMR/CBridge/TouchBarPrivateApi.h @@ -17,13 +17,16 @@ extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL); @interface NSTouchBar (PrivateMethods) -// presentSystemModalFunctionBar:placement:systemTrayItemIdentifier: +// macOS 10.14 ++ (void)presentSystemModalTouchBar:(NSTouchBar *)touchBar placement:(long long)placement systemTrayItemIdentifier:(NSTouchBarItemIdentifier)identifier; ++ (void)presentSystemModalTouchBar:(NSTouchBar *)touchBar systemTrayItemIdentifier:(NSTouchBarItemIdentifier)identifier; ++ (void)dismissSystemModalTouchBar:(NSTouchBar *)touchBar; ++ (void)minimizeSystemModalTouchBar:(NSTouchBar *)touchBar; + +// macOS 10.13 + (void)presentSystemModalFunctionBar:(NSTouchBar *)touchBar placement:(long long)placement systemTrayItemIdentifier:(NSTouchBarItemIdentifier)identifier; - + (void)presentSystemModalFunctionBar:(NSTouchBar *)touchBar systemTrayItemIdentifier:(NSTouchBarItemIdentifier)identifier; - + (void)dismissSystemModalFunctionBar:(NSTouchBar *)touchBar; - + (void)minimizeSystemModalFunctionBar:(NSTouchBar *)touchBar; @end diff --git a/MTMR/SupportNSTouchBar.swift b/MTMR/SupportNSTouchBar.swift new file mode 100644 index 0000000..506e0bd --- /dev/null +++ b/MTMR/SupportNSTouchBar.swift @@ -0,0 +1,31 @@ +// +// ExtendNSTouchBar.swift +// MTMR +// +// Created by Anton Palgunov on 07/06/2018. +// Copyright © 2018 Anton Palgunov. All rights reserved. +// + +func presentSystemModal(_ touchBar: NSTouchBar!, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) -> Void { + if #available(OSX 10.14, *) { + NSTouchBar.presentSystemModalTouchBar(touchBar, systemTrayItemIdentifier: identifier) + } else { + NSTouchBar.presentSystemModalFunctionBar(touchBar, systemTrayItemIdentifier: identifier) + } +} + +func presentSystemModal(_ touchBar: NSTouchBar!, placement: Int64, systemTrayItemIdentifier identifier: NSTouchBarItem.Identifier!) -> Void { + if #available(OSX 10.14, *) { + NSTouchBar.presentSystemModalTouchBar(touchBar, placement: placement, systemTrayItemIdentifier: identifier) + } else { + NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: placement, systemTrayItemIdentifier: identifier) + } +} + +func minimizeSystemModal(_ touchBar: NSTouchBar!) -> Void { + if #available(OSX 10.14, *) { + NSTouchBar.minimizeSystemModalTouchBar(touchBar) + } else { + NSTouchBar.minimizeSystemModalFunctionBar(touchBar) + } +} diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 6aa8a60..c62085f 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -113,7 +113,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { func createAndUpdatePreset(newJsonItems: [BarItemDefinition]) { if let oldBar = self.touchBar { - NSTouchBar.minimizeSystemModalFunctionBar(oldBar) + minimizeSystemModal(oldBar) } self.touchBar = NSTouchBar() self.jsonItems = newJsonItems @@ -213,23 +213,23 @@ class TouchBarController: NSObject, NSTouchBarDelegate { @objc private func presentTouchBar() { if touchbarNeedRefresh { if self.controlStripState { - NSTouchBar.presentSystemModalFunctionBar(touchBar, systemTrayItemIdentifier: .controlStripItem) + presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem) } else { - NSTouchBar.presentSystemModalFunctionBar(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) + presentSystemModal(touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) } } } + + @objc private func dismissTouchBar() { + self.touchbarNeedRefresh = true + minimizeSystemModal(touchBar) + } @objc func resetControlStrip() { dismissTouchBar() presentTouchBar() } - @objc private func dismissTouchBar() { - self.touchbarNeedRefresh = true - NSTouchBar.minimizeSystemModalFunctionBar(touchBar) - } - func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { if identifier == centerScrollArea { return self.scrollArea diff --git a/MTMR/Widgets/GroupBarItem.swift b/MTMR/Widgets/GroupBarItem.swift index aa10e9a..3eac647 100644 --- a/MTMR/Widgets/GroupBarItem.swift +++ b/MTMR/Widgets/GroupBarItem.swift @@ -56,9 +56,9 @@ class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate { TouchBarController.shared.touchBar.defaultItemIdentifiers = self.leftIdentifiers + [centerScrollArea] + self.rightIdentifiers if TouchBarController.shared.controlStripState { - NSTouchBar.presentSystemModalFunctionBar(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem) + presentSystemModal(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem) } else { - NSTouchBar.presentSystemModalFunctionBar(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) + presentSystemModal(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem) } }