2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Detach SystemMediaControls from Window::Controller.

This commit is contained in:
John Preston
2023-01-19 09:38:52 +04:00
parent 6b8f80bd63
commit cdfdccbb66
12 changed files with 67 additions and 53 deletions

View File

@@ -287,6 +287,11 @@ MainWidget::MainWidget(
_exportTopBar->finishAnimating();
}
Media::Player::instance()->closePlayerRequests(
) | rpl::start_with_next([=] {
closeBothPlayers();
}, lifetime());
Media::Player::instance()->updatedNotifier(
) | rpl::start_with_next([=](const Media::Player::TrackState &state) {
handleAudioUpdate(state);
@@ -357,14 +362,16 @@ MainWidget::MainWidget(
Media::Player::instance()->tracksFinished(
) | rpl::start_with_next([=](AudioMsgId::Type type) {
if (type == AudioMsgId::Type::Voice) {
const auto songState = Media::Player::instance()->getState(AudioMsgId::Type::Song);
const auto songState = Media::Player::instance()->getState(
AudioMsgId::Type::Song);
if (!songState.id || IsStoppedOrStopping(songState.state)) {
closeBothPlayers();
Media::Player::instance()->stopAndClose();
}
} else if (type == AudioMsgId::Type::Song) {
const auto songState = Media::Player::instance()->getState(AudioMsgId::Type::Song);
const auto songState = Media::Player::instance()->getState(
AudioMsgId::Type::Song);
if (!songState.id) {
closeBothPlayers();
Media::Player::instance()->stopAndClose();
}
}
}, lifetime());
@@ -767,7 +774,7 @@ void MainWidget::handleAudioUpdate(const Media::Player::TrackState &state) {
if (!Media::Player::IsStoppedOrStopping(state.state)) {
createPlayer();
} else if (state.state == State::StoppedAtStart) {
closeBothPlayers();
Media::Player::instance()->stopAndClose();
}
if (const auto item = session().data().message(state.id.contextId())) {
@@ -788,12 +795,7 @@ void MainWidget::closeBothPlayers() {
if (_player) {
_player->hide(anim::type::normal);
}
_playerPlaylist->hideIgnoringEnterEvents();
Media::Player::instance()->stop(AudioMsgId::Type::Voice);
Media::Player::instance()->stop(AudioMsgId::Type::Song);
Shortcuts::ToggleMediaShortcuts(false);
}
void MainWidget::stopAndClosePlayer() {
@@ -814,7 +816,9 @@ void MainWidget::createPlayer() {
) | rpl::start_with_next(
[this] { playerHeightUpdated(); },
_player->lifetime());
_player->entity()->setCloseCallback([=] { closeBothPlayers(); });
_player->entity()->setCloseCallback([=] {
Media::Player::instance()->stopAndClose();
});
_player->entity()->setShowItemCallback([=](
not_null<const HistoryItem*> item) {
_controller->showMessage(item);