From 09b5055facda92e78c52a5a3bcb7d2130ff1dada Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 4 May 2019 12:43:22 +0300 Subject: [PATCH] Enabled audio player in touchbar only for songs. --- Telegram/SourceFiles/platform/mac/touchbar.h | 1 + Telegram/SourceFiles/platform/mac/touchbar.mm | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/touchbar.h b/Telegram/SourceFiles/platform/mac/touchbar.h index 9f3311d349..a981c9f873 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar.h +++ b/Telegram/SourceFiles/platform/mac/touchbar.h @@ -16,6 +16,7 @@ enum class TouchBarType { None, Main, AudioPlayer, + AudioPlayerForce, }; } // namespace diff --git a/Telegram/SourceFiles/platform/mac/touchbar.mm b/Telegram/SourceFiles/platform/mac/touchbar.mm index 86ae8dc93e..cdff336c9a 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar.mm @@ -38,8 +38,6 @@ namespace { constexpr auto kIdealIconSize = 36; constexpr auto kMaximumIconSize = 44; -constexpr auto kSavedMessages = 0x001; - constexpr auto kPlayPause = 0x002; constexpr auto kPlaylistPrevious = 0x003; constexpr auto kPlaylistNext = 0x004; @@ -370,17 +368,34 @@ NSImage *createImageFromStyleIcon(const style::icon &icon, NSSize size) { if (self.touchBarType == type) { return; } - self.touchBarType = type; if (type == TouchBarType::Main) { [self.view setTouchBar:_touchBarMain]; } else if (type == TouchBarType::AudioPlayer) { + if (!isCurrentSongExists() + || Media::Player::instance()->getActiveType() != kSongType) { + return; + } [self.view setTouchBar:_touchBarAudioPlayer]; + } else if (type == TouchBarType::AudioPlayerForce) { + [self.view setTouchBar:_touchBarAudioPlayer]; + self.touchBarType = TouchBarType::AudioPlayer; + return; } else if (type == TouchBarType::None) { [self.view setTouchBar:nil]; } + self.touchBarType = type; +} + +inline bool isCurrentSongExists() { + return Media::Player::instance()->current(kSongType).audio() != nullptr; } - (void) handlePropertyChange:(Media::Player::TrackState)property { + if (property.id.type() == kSongType) { + [self setTouchBar:TouchBarType::AudioPlayerForce]; + } else { + return; + } self.position = property.position < 0 ? 0 : property.position; self.duration = property.length; if (Media::Player::IsStoppedOrStopping(property.state)) { @@ -480,11 +495,11 @@ NSImage *createImageFromStyleIcon(const style::icon &icon, NSSize size) { Core::Sandbox::Instance().customEnterFromEventLoop([=] { if (command == kPlayPause) { - Media::Player::instance()->playPause(); + Media::Player::instance()->playPause(kSongType); } else if (command == kPlaylistPrevious) { - Media::Player::instance()->previous(); + Media::Player::instance()->previous(kSongType); } else if (command == kPlaylistNext) { - Media::Player::instance()->next(); + Media::Player::instance()->next(kSongType); } else if (command == kClosePlayer) { App::main()->closeBothPlayers(); }