From 710c07f05f54af7d6d615cb2eb3aa795590626a6 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Fri, 14 Jun 2024 21:38:51 +0800 Subject: [PATCH] fix: auto pronounce audio does not play --- src/ui/mainwindow.cc | 16 +++++----------- src/ui/scanpopup.cc | 11 +++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 6ba6b8b0..372ae169 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -705,18 +705,12 @@ MainWindow::MainWindow( Config::Class & cfg_ ): &PronounceEngine::emitAudio, this, [ this ]( auto audioUrl ) { + if ( !isActiveWindow() ) + return; auto view = getCurrentArticleView(); - if ( ( cfg.preferences.pronounceOnLoadMain || cfg.preferences.pronounceOnLoadPopup ) && view != nullptr ) { - if ( cfg.preferences.pronounceOnLoadPopup ) { - if ( !scanPopup || !scanPopup->isActiveWindow() ) - return; - view->openLink( QUrl::fromEncoded( audioUrl.toUtf8() ), {} ); - } - else if ( cfg.preferences.pronounceOnLoadMain ) { - if ( scanPopup && scanPopup->isActiveWindow() ) - return; - view->openLink( QUrl::fromEncoded( audioUrl.toUtf8() ), {} ); - } + if ( ( cfg.preferences.pronounceOnLoadMain ) && view != nullptr ) { + + view->openLink( QUrl::fromEncoded( audioUrl.toUtf8() ), {} ); } } ); applyProxySettings(); diff --git a/src/ui/scanpopup.cc b/src/ui/scanpopup.cc index f44d86b4..9e3009f2 100644 --- a/src/ui/scanpopup.cc +++ b/src/ui/scanpopup.cc @@ -157,6 +157,17 @@ ScanPopup::ScanPopup( QWidget * parent, connect( &dictionaryBar, &DictionaryBar::showDictionaryInfo, this, &ScanPopup::showDictionaryInfo ); connect( &dictionaryBar, &DictionaryBar::openDictionaryFolder, this, &ScanPopup::openDictionaryFolder ); + connect( &GlobalBroadcaster::instance()->pronounce_engine, + &PronounceEngine::emitAudio, + this, + [ this ]( auto audioUrl ) { + if ( !isActiveWindow() ) + return; + if ( cfg.preferences.pronounceOnLoadPopup ) { + + definition->openLink( QUrl::fromEncoded( audioUrl.toUtf8() ), {} ); + } + } ); pinnedGeometry = cfg.popupWindowGeometry; if ( cfg.popupWindowGeometry.size() ) restoreGeometry( cfg.popupWindowGeometry );