Added initial implementation of switching between touch bars.

This commit is contained in:
23rd 2019-04-29 19:55:11 +03:00 committed by John Preston
parent 58604406f8
commit c9f56abce5
3 changed files with 248 additions and 205 deletions

View File

@ -111,8 +111,8 @@ public:
void willExitFullScreen(); void willExitFullScreen();
bool clipboardHasText(); bool clipboardHasText();
TouchBar *_touchBar; TouchBar *_touchBar;
~Private(); ~Private();
@ -189,9 +189,6 @@ MainWindow::Private::Private(MainWindow *window)
, _observer([[MainWindowObserver alloc] init:this]) { , _observer([[MainWindowObserver alloc] init:this]) {
_generalPasteboard = [NSPasteboard generalPasteboard]; _generalPasteboard = [NSPasteboard generalPasteboard];
_touchBar = [[TouchBar alloc] init];
[_touchBar setTouchBarType:Platform::TouchBarType::AudioPlayer];
@autoreleasepool { @autoreleasepool {
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:_observer selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil]; [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:_observer selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
@ -217,10 +214,6 @@ void MainWindow::Private::setWindowBadge(const QString &str) {
void MainWindow::Private::setWindowTitle(const QString &str) { void MainWindow::Private::setWindowTitle(const QString &str) {
_public->setWindowTitle(str); _public->setWindowTitle(str);
if ([[NSApplication sharedApplication] respondsToSelector:@selector(isAutomaticCustomizeTouchBarMenuItemEnabled)]) {
[NSApplication sharedApplication].automaticCustomizeTouchBarMenuItemEnabled = YES;
}
[NSApplication sharedApplication].mainWindow.touchBar = [_touchBar makeTouchBar];
updateNativeTitle(); updateNativeTitle();
} }
@ -401,11 +394,11 @@ MainWindow::MainWindow()
_private->updateNativeTitle(); _private->updateNativeTitle();
} }
}); });
subscribe(Media::Player::instance()->updatedNotifier(), subscribe(Media::Player::instance()->updatedNotifier(),
[=](const Media::Player::TrackState &state) { [=](const Media::Player::TrackState &state) {
[_private->_touchBar handlePropertyChange:state]; [_private->_touchBar handlePropertyChange:state];
}); });
} }
void MainWindow::closeWithoutDestroy() { void MainWindow::closeWithoutDestroy() {
@ -590,6 +583,10 @@ void MainWindow::psFirstShow() {
setPositionInited(); setPositionInited();
createGlobalMenu(); createGlobalMenu();
// Create TouchBar.
[NSApplication sharedApplication].automaticCustomizeTouchBarMenuItemEnabled = YES;
_private->_touchBar = [[TouchBar alloc] init];
} }
void MainWindow::createGlobalMenu() { void MainWindow::createGlobalMenu() {

View File

@ -11,8 +11,17 @@
#include "media/player/media_player_instance.h" #include "media/player/media_player_instance.h"
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
namespace {
enum class TouchBarType {
Main,
AudioPlayer,
};
} // namespace
static NSString * _Nullable BASE_ID = @"telegram.touchbar"; static NSString * _Nullable BASE_ID = @"telegram.touchbar";
static NSTouchBarCustomizationIdentifier _Nullable customID = @"telegram.touchbar"; static NSTouchBarCustomizationIdentifier _Nullable customID = @"telegram.touchbar";
static NSTouchBarCustomizationIdentifier _Nullable customIDMain = @"telegram.touchbar.main";
static NSTouchBarItemIdentifier _Nullable savedMessages = [NSString stringWithFormat:@"%@.savedMessages", BASE_ID];
static NSTouchBarItemIdentifier _Nullable seekBar = [NSString stringWithFormat:@"%@.seekbar", BASE_ID]; static NSTouchBarItemIdentifier _Nullable seekBar = [NSString stringWithFormat:@"%@.seekbar", BASE_ID];
static NSTouchBarItemIdentifier _Nullable play = [NSString stringWithFormat:@"%@.play", BASE_ID]; static NSTouchBarItemIdentifier _Nullable play = [NSString stringWithFormat:@"%@.play", BASE_ID];
static NSTouchBarItemIdentifier _Nullable nextItem = [NSString stringWithFormat:@"%@.nextItem", BASE_ID]; static NSTouchBarItemIdentifier _Nullable nextItem = [NSString stringWithFormat:@"%@.nextItem", BASE_ID];
@ -25,9 +34,11 @@ static NSTouchBarItemIdentifier _Nullable currentPosition = [NSString stringWith
static NSTouchBarItemIdentifier _Nullable timeLeft = [NSString stringWithFormat:@"%@.timeLeft", BASE_ID]; static NSTouchBarItemIdentifier _Nullable timeLeft = [NSString stringWithFormat:@"%@.timeLeft", BASE_ID];
@interface TouchBar : NSTouchBar @interface TouchBar : NSTouchBar
@property Platform::TouchBarType touchBarType; @property TouchBarType touchBarType;
@property(retain) NSDictionary * _Nullable touchbarItems; @property(retain) NSDictionary * _Nullable touchbarItems;
@property(retain) NSTouchBar * _Nullable touchBarMain;
@property(retain) NSTouchBar * _Nullable touchBarAudioPlayer;
@property(nonatomic, assign) double duration; @property(nonatomic, assign) double duration;
@property(nonatomic, assign) double position; @property(nonatomic, assign) double position;

View File

@ -29,12 +29,12 @@ namespace {
constexpr auto kPlayPause = 0x000; constexpr auto kPlayPause = 0x000;
constexpr auto kPlaylistPrevious = 0x001; constexpr auto kPlaylistPrevious = 0x001;
constexpr auto kPlaylistNext = 0x002; constexpr auto kPlaylistNext = 0x002;
constexpr auto kSavedMessages = 0x002; constexpr auto kSavedMessages = 0x003;
constexpr auto kMs = 1000; constexpr auto kMs = 1000;
constexpr auto kSongType = AudioMsgId::Type::Song; constexpr auto kSongType = AudioMsgId::Type::Song;
} } // namespace
@interface TouchBar()<NSTouchBarDelegate> @interface TouchBar()<NSTouchBarDelegate>
@end @end
@ -42,234 +42,269 @@ constexpr auto kSongType = AudioMsgId::Type::Song;
@implementation TouchBar @implementation TouchBar
- (instancetype)init { - (instancetype)init {
self = [super init]; self = [super init];
if (self) { if (self) {
self.touchBarType = Platform::TouchBarType::None; self.touchbarItems = @{
savedMessages: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Saved Messages",
@"cmd": [NSNumber numberWithInt:kSavedMessages],
@"image": [NSImage imageNamed:NSImageNameTouchBarBookmarksTemplate],
}],
seekBar: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"slider",
@"name": @"Seek Bar"
}],
play: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Play Button",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarPauseTemplate],
@"imageAlt": [NSImage imageNamed:NSImageNameTouchBarPlayTemplate]
}],
previousItem: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Previous Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistPrevious],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoBackTemplate]
}],
nextItem: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Next Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistNext],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoForwardTemplate]
}],
previousChapter: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Previous Chapter",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarSkipBackTemplate]
}],
nextChapter: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Next Chapter",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarSkipAheadTemplate]
}],
cycleAudio: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Cycle Audio",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarAudioInputTemplate]
}],
cycleSubtitle: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Cycle Subtitle",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarComposeTemplate]
}],
currentPosition: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"text",
@"name": @"Current Position"
}]
};
}
[self createTouchBar];
[self setTouchBar:TouchBarType::Main];
return self;
}
self.touchbarItems = @{ - (void) createTouchBar{
seekBar: [NSMutableDictionary dictionaryWithDictionary:@{ _touchBarAudioPlayer = [[NSTouchBar alloc] init];
@"type": @"slider", _touchBarAudioPlayer.delegate = self;
@"name": @"Seek Bar",
@"cmd": [NSNumber numberWithInt:kPlayPause] _touchBarAudioPlayer.customizationIdentifier = customID;
}], _touchBarAudioPlayer.defaultItemIdentifiers = @[savedMessages, play, previousItem, nextItem, seekBar];
play: [NSMutableDictionary dictionaryWithDictionary:@{ _touchBarAudioPlayer.customizationAllowedItemIdentifiers = @[savedMessages, play, previousItem,
@"type": @"button", nextItem, currentPosition, seekBar];
@"name": @"Play Button",
@"cmd": [NSNumber numberWithInt:kPlayPause], _touchBarMain = [[NSTouchBar alloc] init];
@"image": [NSImage imageNamed:NSImageNameTouchBarPauseTemplate], _touchBarMain.delegate = self;
@"imageAlt": [NSImage imageNamed:NSImageNameTouchBarPlayTemplate]
}], _touchBarMain.customizationIdentifier = customIDMain;
previousItem: [NSMutableDictionary dictionaryWithDictionary:@{ _touchBarMain.defaultItemIdentifiers = @[savedMessages];
@"type": @"button", _touchBarMain.customizationAllowedItemIdentifiers = @[savedMessages];
@"name": @"Previous Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistPrevious],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoBackTemplate]
}],
nextItem: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Next Playlist Item",
@"cmd": [NSNumber numberWithInt:kPlaylistNext],
@"image": [NSImage imageNamed:NSImageNameTouchBarGoForwardTemplate]
}],
previousChapter: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Previous Chapter",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarSkipBackTemplate]
}],
nextChapter: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Next Chapter",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarSkipAheadTemplate]
}],
cycleAudio: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Cycle Audio",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarAudioInputTemplate]
}],
cycleSubtitle: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"button",
@"name": @"Cycle Subtitle",
@"cmd": [NSNumber numberWithInt:kPlayPause],
@"image": [NSImage imageNamed:NSImageNameTouchBarComposeTemplate]
}],
currentPosition: [NSMutableDictionary dictionaryWithDictionary:@{
@"type": @"text",
@"name": @"Current Position"
}]
};
}
return self;
} }
- (nullable NSTouchBar *) makeTouchBar{ - (nullable NSTouchBar *) makeTouchBar{
NSTouchBar *touchBar = [[NSTouchBar alloc] init]; return [NSApplication sharedApplication].mainWindow.touchBar;
touchBar.delegate = self; // [NSApplication sharedApplication].mainWindow.touchBar = touchBar;
touchBar.customizationIdentifier = @"TOUCH_BAR";
touchBar.customizationIdentifier = customID;
touchBar.defaultItemIdentifiers = @[play, previousItem, nextItem, seekBar];
touchBar.customizationAllowedItemIdentifiers = @[play, seekBar, previousItem,
nextItem, previousChapter, nextChapter, cycleAudio, cycleSubtitle,
currentPosition];
return touchBar;
} }
- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"slider"]) { if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"slider"]) {
NSSliderTouchBarItem *item = [[NSSliderTouchBarItem alloc] initWithIdentifier:identifier]; NSSliderTouchBarItem *item = [[NSSliderTouchBarItem alloc] initWithIdentifier:identifier];
item.slider.minValue = 0.0f; item.slider.minValue = 0.0f;
item.slider.maxValue = 1.0f; item.slider.maxValue = 1.0f;
item.target = self; item.target = self;
item.action = @selector(seekbarChanged:); item.action = @selector(seekbarChanged:);
item.customizationLabel = self.touchbarItems[identifier][@"name"]; item.customizationLabel = self.touchbarItems[identifier][@"name"];
[self.touchbarItems[identifier] setObject:item.slider forKey:@"view"]; [self.touchbarItems[identifier] setObject:item.slider forKey:@"view"];
return item; return item;
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"button"]) { } else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"button"]) {
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
NSImage *image = self.touchbarItems[identifier][@"image"]; NSImage *image = self.touchbarItems[identifier][@"image"];
NSButton *button = [NSButton buttonWithImage:image target:self action:@selector(buttonAction:)]; NSButton *button = [NSButton buttonWithImage:image target:self action:@selector(buttonAction:)];
item.view = button; item.view = button;
item.customizationLabel = self.touchbarItems[identifier][@"name"]; item.customizationLabel = self.touchbarItems[identifier][@"name"];
[self.touchbarItems[identifier] setObject:button forKey:@"view"]; [self.touchbarItems[identifier] setObject:button forKey:@"view"];
return item; return item;
} else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"text"]) { } else if ([self.touchbarItems[identifier][@"type"] isEqualToString:@"text"]) {
NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier];
NSTextField *text = [NSTextField labelWithString:@"0:00"]; NSTextField *text = [NSTextField labelWithString:@"0:00"];
text.alignment = NSTextAlignmentCenter; text.alignment = NSTextAlignmentCenter;
item.view = text; item.view = text;
item.customizationLabel = self.touchbarItems[identifier][@"name"]; item.customizationLabel = self.touchbarItems[identifier][@"name"];
[self.touchbarItems[identifier] setObject:text forKey:@"view"]; [self.touchbarItems[identifier] setObject:text forKey:@"view"];
return item; return item;
} }
return nil; return nil;
}
- (void)setTouchBar:(TouchBarType)type {
if (self.touchBarType == type) {
return;
}
self.touchBarType = type;
if (type == TouchBarType::Main) {
[NSApplication sharedApplication].mainWindow.touchBar = _touchBarMain;
} else if (type == TouchBarType::AudioPlayer) {
[NSApplication sharedApplication].mainWindow.touchBar = _touchBarAudioPlayer;
}
} }
- (void)handlePropertyChange:(Media::Player::TrackState)property { - (void)handlePropertyChange:(Media::Player::TrackState)property {
self.position = property.position < 0 ? 0 : property.position; if (property.state == Media::Player::State::Stopped) {
self.duration = property.length; [self setTouchBar:TouchBarType::Main];
[self updateTouchBarTimeItems]; return;
NSButton *playButton = self.touchbarItems[play][@"view"]; } else {
if (property.state == Media::Player::State::Playing) { [self setTouchBar:TouchBarType::AudioPlayer];
playButton.image = self.touchbarItems[play][@"image"]; }
} else {
playButton.image = self.touchbarItems[play][@"imageAlt"]; self.position = property.position < 0 ? 0 : property.position;
} self.duration = property.length;
[self updateTouchBarTimeItems];
[self.touchbarItems[nextItem][@"view"] NSButton *playButton = self.touchbarItems[play][@"view"];
setEnabled:Media::Player::instance()->nextAvailable(kSongType)]; if (property.state == Media::Player::State::Playing) {
[self.touchbarItems[previousItem][@"view"] playButton.image = self.touchbarItems[play][@"image"];
setEnabled:Media::Player::instance()->previousAvailable(kSongType)]; } else {
playButton.image = self.touchbarItems[play][@"imageAlt"];
}
[self.touchbarItems[nextItem][@"view"]
setEnabled:Media::Player::instance()->nextAvailable(kSongType)];
[self.touchbarItems[previousItem][@"view"]
setEnabled:Media::Player::instance()->previousAvailable(kSongType)];
} }
- (NSString *)formatTime:(int)time { - (NSString *)formatTime:(int)time {
const int seconds = time % 60; const int seconds = time % 60;
const int minutes = (time / 60) % 60; const int minutes = (time / 60) % 60;
const int hours = time / (60 * 60); const int hours = time / (60 * 60);
NSString *stime = hours > 0 ? [NSString stringWithFormat:@"%d:", hours] : @""; NSString *stime = hours > 0 ? [NSString stringWithFormat:@"%d:", hours] : @"";
stime = (stime.length > 0 || minutes > 9) ? stime = (stime.length > 0 || minutes > 9) ?
[NSString stringWithFormat:@"%@%02d:", stime, minutes] : [NSString stringWithFormat:@"%@%02d:", stime, minutes] :
[NSString stringWithFormat:@"%d:", minutes]; [NSString stringWithFormat:@"%d:", minutes];
stime = [NSString stringWithFormat:@"%@%02d", stime, seconds]; stime = [NSString stringWithFormat:@"%@%02d", stime, seconds];
return stime; return stime;
} }
- (void)removeConstraintForIdentifier:(NSTouchBarItemIdentifier)identifier { - (void)removeConstraintForIdentifier:(NSTouchBarItemIdentifier)identifier {
NSTextField *field = self.touchbarItems[identifier][@"view"]; NSTextField *field = self.touchbarItems[identifier][@"view"];
[field removeConstraint:self.touchbarItems[identifier][@"constrain"]]; [field removeConstraint:self.touchbarItems[identifier][@"constrain"]];
} }
- (void)applyConstraintFromString:(NSString *)string - (void)applyConstraintFromString:(NSString *)string
forIdentifier:(NSTouchBarItemIdentifier)identifier { forIdentifier:(NSTouchBarItemIdentifier)identifier {
NSTextField *field = self.touchbarItems[identifier][@"view"]; NSTextField *field = self.touchbarItems[identifier][@"view"];
if (field) { if (field) {
NSString *fString = [[string componentsSeparatedByCharactersInSet: NSString *fString = [[string componentsSeparatedByCharactersInSet:
[NSCharacterSet decimalDigitCharacterSet]] componentsJoinedByString:@"0"]; [NSCharacterSet decimalDigitCharacterSet]] componentsJoinedByString:@"0"];
NSTextField *textField = [NSTextField labelWithString:fString]; NSTextField *textField = [NSTextField labelWithString:fString];
NSSize size = [textField frame].size; NSSize size = [textField frame].size;
NSLayoutConstraint *con = NSLayoutConstraint *con =
[NSLayoutConstraint constraintWithItem:field [NSLayoutConstraint constraintWithItem:field
attribute:NSLayoutAttributeWidth attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual relatedBy:NSLayoutRelationEqual
toItem:nil toItem:nil
attribute:NSLayoutAttributeNotAnAttribute attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0 multiplier:1.0
constant:(int)ceil(size.width * 1.5)]; constant:(int)ceil(size.width * 1.5)];
[field addConstraint:con]; [field addConstraint:con];
[self.touchbarItems[identifier] setObject:con forKey:@"constrain"]; [self.touchbarItems[identifier] setObject:con forKey:@"constrain"];
} }
} }
- (void)updateTouchBarTimeItemConstrains { - (void)updateTouchBarTimeItemConstrains {
[self removeConstraintForIdentifier:currentPosition]; [self removeConstraintForIdentifier:currentPosition];
if (self.duration <= 0) { if (self.duration <= 0) {
[self applyConstraintFromString:[self formatTime:self.position] [self applyConstraintFromString:[self formatTime:self.position]
forIdentifier:currentPosition]; forIdentifier:currentPosition];
} else { } else {
NSString *durFormat = [self formatTime:self.duration]; NSString *durFormat = [self formatTime:self.duration];
[self applyConstraintFromString:durFormat forIdentifier:currentPosition]; [self applyConstraintFromString:durFormat forIdentifier:currentPosition];
} }
} }
- (void)updateTouchBarTimeItems { - (void)updateTouchBarTimeItems {
NSSlider *seekSlider = self.touchbarItems[seekBar][@"view"]; NSSlider *seekSlider = self.touchbarItems[seekBar][@"view"];
NSTextField *curPosItem = self.touchbarItems[currentPosition][@"view"]; NSTextField *curPosItem = self.touchbarItems[currentPosition][@"view"];
if (self.duration <= 0) { if (self.duration <= 0) {
seekSlider.enabled = NO; seekSlider.enabled = NO;
seekSlider.doubleValue = 0; seekSlider.doubleValue = 0;
} else { } else {
seekSlider.enabled = YES; seekSlider.enabled = YES;
if (!seekSlider.highlighted) { if (!seekSlider.highlighted) {
seekSlider.doubleValue = (self.position / self.duration) * seekSlider.maxValue; seekSlider.doubleValue = (self.position / self.duration) * seekSlider.maxValue;
} }
} }
const auto timeToString = [&](int t) { const auto timeToString = [&](int t) {
return [self formatTime:(int)floor(t / kMs)]; return [self formatTime:(int)floor(t / kMs)];
}; };
curPosItem.stringValue = [NSString stringWithFormat:@"%@ / %@", curPosItem.stringValue = [NSString stringWithFormat:@"%@ / %@",
timeToString(self.position), timeToString(self.position),
timeToString(self.duration)]; timeToString(self.duration)];
[self updateTouchBarTimeItemConstrains]; [self updateTouchBarTimeItemConstrains];
} }
- (NSString *)getIdentifierFromView:(id)view { - (NSString *)getIdentifierFromView:(id)view {
NSString *identifier; NSString *identifier;
for (identifier in self.touchbarItems) for (identifier in self.touchbarItems)
if([self.touchbarItems[identifier][@"view"] isEqual:view]) if([self.touchbarItems[identifier][@"view"] isEqual:view])
break; break;
return identifier; return identifier;
} }
- (void)buttonAction:(NSButton *)sender { - (void)buttonAction:(NSButton *)sender {
NSString *identifier = [self getIdentifierFromView:sender]; NSString *identifier = [self getIdentifierFromView:sender];
const auto command = [self.touchbarItems[identifier][@"cmd"] intValue]; const auto command = [self.touchbarItems[identifier][@"cmd"] intValue];
LOG(("BUTTON %1").arg(command));
Core::Sandbox::Instance().customEnterFromEventLoop([=] { Core::Sandbox::Instance().customEnterFromEventLoop([=] {
if (command == kPlayPause) { if (command == kPlayPause) {
Media::Player::instance()->playPause(); Media::Player::instance()->playPause();
} else if (command == kPlaylistPrevious) { } else if (command == kPlaylistPrevious) {
Media::Player::instance()->previous(); Media::Player::instance()->previous();
} else if (command == kPlaylistNext) { } else if (command == kPlaylistNext) {
Media::Player::instance()->next(); Media::Player::instance()->next();
} else if (command == kSavedMessages) {
App::main()->choosePeer(Auth().userPeerId(), ShowAtUnreadMsgId);
} }
}); });
} }
- (void)seekbarChanged:(NSSliderTouchBarItem *)sender { - (void)seekbarChanged:(NSSliderTouchBarItem *)sender {
Core::Sandbox::Instance().customEnterFromEventLoop([&] { Core::Sandbox::Instance().customEnterFromEventLoop([&] {
Media::Player::instance()->finishSeeking(kSongType, sender.slider.doubleValue); Media::Player::instance()->finishSeeking(kSongType, sender.slider.doubleValue);
}); });
} }
@end @end