How get an item in control center of Touch Bar on the right?

雨燕双飞 提交于 2019-11-27 20:26:58

问题


The app TouchSwitcher add item beside lightscreen and volume items : https://hazeover.com/touchswitcher.html

Is there a solution to display an item into the control strip on the right region of touch bar ?

I can't find any help in official documentation about it... Please help me !


回答1:


Here's what I use. Pass an NSView and an identifier of your choice to the controlStrippify() function. My attempts at doing the exact same thing using Swift have resulted in crashes, ports welcome :). Inspiration from https://github.com/a2/touch-baer.

@import Cocoa;
@import Foundation;

// See: https://github.com/a2/touch-baer
extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
extern void DFRElementSetControlStripPresenceForIdentifier(NSString *string, BOOL enabled);

@interface NSTouchBarItem ()
+ (void)addSystemTrayItem:(NSTouchBarItem *)item;
@end

@interface NSTouchBar ()
+ (void)presentSystemModalFunctionBar:(NSTouchBar *)touchBar systemTrayItemIdentifier:(NSString *)identifier;
@end

void controlStrippify(NSView *view, NSString *identifier) {
  if (@available(macOS 10.12.2, *)) {
    DFRSystemModalShowsCloseBoxWhenFrontMost(YES);

    NSCustomTouchBarItem *touchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
    touchBarItem.view = view;
    [NSTouchBarItem addSystemTrayItem:touchBarItem];
    DFRElementSetControlStripPresenceForIdentifier(identifier, YES);
  } else {
    // Fail!
  }
}



回答2:


After decompiling, I discovered some APIs in a framework called DFRFoundation located under /System/Library/PrivateFrameworks, and a related method DFRElementSetControlStripPresenceForIdentifier. I find it quite difficult to get further, so I answer here only to let you know that the API for this is in a private framework. Hope someone would reveal the secrets someday.



来源:https://stackoverflow.com/questions/40920204/how-get-an-item-in-control-center-of-touch-bar-on-the-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!