fix: 修复 UOS 上加载 RC 页面始终处于加载中的问题

页面加载始终未触发 loadFinished 信号,判断加载未完成

Log: 添加 loadProgressChanged 信号处理,加载进度到 100% 就显示页面;loadFinished 信号如果报错,在窗口中提示“加载存在错误”
This commit is contained in:
zty199 2022-11-21 14:38:57 +08:00
parent eb2bdaca63
commit 4a81898cd3
7 changed files with 43 additions and 9 deletions

2
.gitignore vendored
View File

@ -43,7 +43,7 @@ target_wrapper.*
CMakeLists.txt.user*
# Qt qm files
translations/*.qm
*.qm
# Debian dpkg-buildpackage
debian/*.debhelper*

View File

@ -265,8 +265,8 @@ void MainWindow::initConnections()
});
connect(m_tray, &QSystemTrayIcon::activated, this, &MainWindow::on_trayIconActivated);
connect(m_widget, &Widget::sigLoadErrorOccurred, this, &MainWindow::slotLoadErrorOccurred);
connect(m_widget->getPage()->profile(), &QWebEngineProfile::downloadRequested, this, &MainWindow::on_downloadStart);
connect(m_widget->getPage(), &QWebEnginePage::windowCloseRequested, this, [=]() {
this->close();
});
@ -476,3 +476,8 @@ void MainWindow::on_downloadCancel(QWebEngineDownloadItem *item)
downloadMessage->hide();
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-error").pixmap(64, 64), QString(QObject::tr("%1Download canceled!")).arg(" "));
}
void MainWindow::slotLoadErrorOccurred()
{
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-warning").pixmap(64, 64), QString(QObject::tr("%1Load error occurred!")).arg(" "));
}

View File

@ -71,6 +71,8 @@ private slots:
void on_downloadResume(QWebEngineDownloadItem *item);
void on_downloadCancel(QWebEngineDownloadItem *item);
void slotLoadErrorOccurred();
private:
QString m_title, m_url;
int m_width, m_height;

View File

@ -187,6 +187,11 @@
<source>%1Download canceled!</source>
<translation>%1</translation>
</message>
<message>
<location filename="../mainwindow.cpp" line="482"/>
<source>%1Load error occurred!</source>
<translation>%1</translation>
</message>
</context>
<context>
<name>TitleBarMenu</name>

View File

@ -71,8 +71,9 @@ void Widget::initUI()
void Widget::initConnections()
{
connect(m_webEngineView, &QWebEngineView::loadStarted, this, &Widget::on_loadStarted, Qt::UniqueConnection);
connect(m_webEngineView, &QWebEngineView::loadFinished, this, &Widget::on_loadFinished, Qt::UniqueConnection);
connect(m_webEngineView, &QWebEngineView::loadStarted, this, &Widget::slotLoadStarted, Qt::UniqueConnection);
connect(m_webEngineView, &QWebEngineView::loadProgress, this, &Widget::slotLoadProgress, Qt::UniqueConnection);
connect(m_webEngineView, &QWebEngineView::loadFinished, this, &Widget::slotLoadFinished, Qt::UniqueConnection);
// FIXME: DTK 主题切换时,动态修改 QtWebEngine prefers-color-scheme
// connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &Widget::slotPaletteTypeChanged, Qt::UniqueConnection);
@ -80,7 +81,7 @@ void Widget::initConnections()
void Widget::updateLayout()
{
on_loadStarted();
slotLoadStarted();
mainLayout->removeWidget(m_webEngineView);
QUrl url = m_webEngineView->url();
@ -98,16 +99,33 @@ void Widget::updateLayout()
page->setUrl(url);
}
void Widget::on_loadStarted()
void Widget::slotLoadStarted()
{
mainLayout->setCurrentIndex(0);
m_spinner->start();
}
void Widget::on_loadFinished()
void Widget::slotLoadProgress(int value)
{
if (value == 100) {
slotLoadFinished(-1);
}
}
void Widget::slotLoadFinished(int status)
{
m_spinner->stop();
mainLayout->setCurrentIndex(1);
if (status < 0) {
qDebug() << Q_FUNC_INFO << "Load progress: 100%";
return;
}
if (!status) {
qWarning() << Q_FUNC_INFO << "Load finished, error occurred!";
emit sigLoadErrorOccurred();
}
}
void Widget::slotPaletteTypeChanged(DGuiApplicationHelper::ColorType paletteType)

View File

@ -30,9 +30,13 @@ private:
void initConnections();
void updateLayout();
signals:
void sigLoadErrorOccurred();
private slots:
void on_loadStarted();
void on_loadFinished();
void slotLoadStarted();
void slotLoadProgress(int value);
void slotLoadFinished(int status);
void slotPaletteTypeChanged(DGuiApplicationHelper::ColorType paletteType);