From b3925a3bec8163d03c57763da3a774dac94fa31e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 12 Oct 2020 22:30:14 +0300 Subject: [PATCH] Added touchbar hiding while recording voice message. --- .../SourceFiles/media/audio/media_audio_capture.cpp | 5 +++++ .../SourceFiles/media/audio/media_audio_capture.h | 5 +++++ .../platform/mac/touchbar/mac_touchbar_manager.mm | 11 ++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/media/audio/media_audio_capture.cpp b/Telegram/SourceFiles/media/audio/media_audio_capture.cpp index 20795f14a1..06df89bb2b 100644 --- a/Telegram/SourceFiles/media/audio/media_audio_capture.cpp +++ b/Telegram/SourceFiles/media/audio/media_audio_capture.cpp @@ -96,6 +96,9 @@ void Instance::start() { _updates.fire_error({}); }); }); + crl::on_main(this, [=] { + _started = true; + }); }); } @@ -103,11 +106,13 @@ void Instance::stop(Fn callback) { InvokeQueued(_inner.get(), [=] { if (!callback) { _inner->stop(); + crl::on_main(this, [=] { _started = false; }); return; } _inner->stop([=](Result &&result) { crl::on_main([=, result = std::move(result)]() mutable { callback(std::move(result)); + _started = false; }); }); }); diff --git a/Telegram/SourceFiles/media/audio/media_audio_capture.h b/Telegram/SourceFiles/media/audio/media_audio_capture.h index 10ad66abc3..a6db3606ba 100644 --- a/Telegram/SourceFiles/media/audio/media_audio_capture.h +++ b/Telegram/SourceFiles/media/audio/media_audio_capture.h @@ -42,6 +42,10 @@ public: return _updates.events(); } + [[nodiscard]] rpl::producer startedChanges() const { + return _started.changes(); + } + void start(); void stop(Fn callback = nullptr); @@ -50,6 +54,7 @@ private: friend class Inner; bool _available = false; + rpl::variable _started = false;; rpl::event_stream _updates; QThread _thread; std::unique_ptr _inner; diff --git a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm index c26850176c..2136d6783b 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar/mac_touchbar_manager.mm @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_domain.h" #include "main/main_session.h" #include "mainwidget.h" // MainWidget::closeBothPlayers +#include "media/audio/media_audio_capture.h" #include "media/player/media_player_instance.h" #include "platform/mac/touchbar/mac_touchbar_audio.h" #include "platform/mac/touchbar/mac_touchbar_common.h" @@ -91,20 +92,24 @@ const auto kAudioItemIdentifier = @"touchbarAudio"; Media::Player::instance()->startsPlay(type) | rpl::map_to(true) ); + auto voiceRecording = ::Media::Capture::instance()->startedChanges(); + rpl::combine( std::move(sessionChanges), rpl::single(false) | rpl::then(Core::App().passcodeLockChanges()), - rpl::single(false) | rpl::then(std::move(audioPlayer)) + rpl::single(false) | rpl::then(std::move(audioPlayer)), + rpl::single(false) | rpl::then(std::move(voiceRecording)) ) | rpl::start_with_next([=]( Main::Session *session, bool lock, - bool audio) { + bool audio, + bool recording) { TouchBar::CustomEnterToCocoaEventLoop([=] { _touchBarSwitches.fire({}); if (!audio) { self.defaultItemIdentifiers = @[]; } - self.defaultItemIdentifiers = lock + self.defaultItemIdentifiers = (lock || recording) ? @[] : audio ? @[kAudioItemIdentifier]