diff --git a/src/main.cpp b/src/main.cpp index 100922a..51526ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char *argv[]) QString arg1 = argv[1]; if (arg1.trimmed().startsWith("spk://")) { - w.openUrl(QUrl(argv[1])); + w.openUrl(arg1); } } w.show(); diff --git a/src/mainwindow-dtk.cpp b/src/mainwindow-dtk.cpp index 0fa509a..6b1480d 100644 --- a/src/mainwindow-dtk.cpp +++ b/src/mainwindow-dtk.cpp @@ -200,11 +200,18 @@ MainWindow::MainWindow(QWidget *parent) QString searchtext = searchEdit->text(); if (!searchtext.isEmpty()) { if (searchtext.startsWith("spk://")) { - openUrl(QUrl(searchtext)); + openUrl(searchtext); searchEdit->clearEdit(); } else { - ui->applistpage_1->getSearchList(searchtext); - switchPage(AppPageSearchlist); + if (searchtext == "%") + { + qWarning() << "keyword '%' matches too many results, which will cause QtWebEngine crash."; + } + else + { + ui->applistpage_1->getSearchList(searchtext); + switchPage(AppPageSearchlist); + } } } this->setFocus(); }); @@ -213,11 +220,11 @@ MainWindow::MainWindow(QWidget *parent) { downloadButton->setProgress(i); }); // 列表点击事件 connect(ui->applistpage, &AppListPage::clicked, this, [=](QUrl spk) - { openUrl(spk); }); + { openUrl(spk.toString()); }); connect(ui->applistpage_1, &AppListPage::clicked, this, [=](QUrl spk) - { openUrl(spk); }); + { openUrl(spk.toString()); }); connect(ui->settingspage, &SettingsPage::openUrl, this, [=](QUrl spk) - { openUrl(spk); }); + { openUrl(spk.toString()); }); emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::instance()->themeType()); connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::newProcessInstance, this, &MainWindow::onNewProcessInstance); @@ -246,7 +253,7 @@ void MainWindow::onGetUrl(const QString &url) { if (url.trimmed().startsWith("spk://")) { - openUrl(QUrl(url)); + openUrl(url); } activateWindow(); } @@ -261,16 +268,27 @@ void MainWindow::onNewProcessInstance(qint64 pid, const QStringList &arguments) } } -void MainWindow::openUrl(QUrl url) +void MainWindow::openUrl(const QString &url) { - if (url.toString().startsWith("spk://")) + if (url.startsWith("spk://search/")) { - ui->appintopage->openUrl(QUrl(url.toString().replace("+", "%2B"))); + QString keyword = url.mid(13); + if (keyword == "%") + { + qWarning() << "keyword '%' is not valid, which will cause QtWebEngine crash."; + return; + } + ui->applistpage_1->getSearchList(keyword); + switchPage(AppPageSearchlist); + } + else if (url.startsWith("spk://")) + { + ui->appintopage->openUrl(QUrl::fromUserInput(url)); switchPage(AppPageAppdetail); } else { - QDesktopServices::openUrl(QUrl(url.toString().replace("+", "%2B"))); + QDesktopServices::openUrl(QUrl::fromUserInput(url)); } } @@ -355,5 +373,5 @@ void MainWindow::on_pushButton_14_clicked() upgradeP->waitForFinished(-1); upgradeP->deleteLater(); }); } - } + } } diff --git a/src/mainwindow-dtk.h b/src/mainwindow-dtk.h index 3eab079..c1dad7e 100644 --- a/src/mainwindow-dtk.h +++ b/src/mainwindow-dtk.h @@ -31,7 +31,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - void openUrl(QUrl); + void openUrl(const QString &url); private: void initDbus(); diff --git a/src/pages/applistpage.cpp b/src/pages/applistpage.cpp index 43d56b5..3e166d5 100644 --- a/src/pages/applistpage.cpp +++ b/src/pages/applistpage.cpp @@ -56,7 +56,7 @@ void AppListPage::getAppList(QString type) delete api; } -void AppListPage::getSearchList(QString keyword) +void AppListPage::getSearchList(const QString &keyword) { isSearch = true; nowType = keyword; @@ -71,7 +71,7 @@ void AppListPage::getSearchList(QString keyword) { theme = "theme=light"; } - url = api->getServerUrl() + "store/#/flamescion/search?keywords=" + keyword + "&" + theme; + url = api->getServerUrl() + "store/#/flamescion/search?keywords=" + QUrl::toPercentEncoding(keyword) + "&" + theme; ui->webEngineView->setUrl(url); delete api; } diff --git a/src/pages/applistpage.h b/src/pages/applistpage.h index 9715088..cb8c0cb 100644 --- a/src/pages/applistpage.h +++ b/src/pages/applistpage.h @@ -14,7 +14,7 @@ class AppListPage : public QWidget public: void setTheme(bool dark); - void getSearchList(QString keyword); + void getSearchList(const QString &keyword); void getAppList(QString type); explicit AppListPage(QWidget *parent = nullptr); ~AppListPage();