如何获得右边Touch Bar控制中心的项目?

Mat*_*tOZ 16 macos cocoa nstouchbar macbookpro-touch-bar

应用程序TouchSwitcher在灯光屏幕和卷项旁边添加项目:https://hazeover.com/touchswitcher.html 在此输入图像描述

是否有解决方案将项目显示在触摸栏右侧区域的控制条中?

我在官方文档中找不到任何帮助...请帮助我!

小智 5

反编译后,在/System/Library/PrivateFrameworks下的一个叫DFRFoundation的框架中发现了一些API,以及一个相关的方法DFRElementSetControlStripPresenceForIdentifier。我发现很难再进一步,所以我在这里回答只是为了让你知道这个 API 是在一个私有框架中。希望有一天有人能揭开这些秘密。


Joh*_*les 5

是我用的。将NSView和选择的标识符传递给controlStrippify()函数。我尝试使用Swift进行完全相同的操作导致崩溃,欢迎使用端口:)。来自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!
  }
}
Run Code Online (Sandbox Code Playgroud)