From d197bd3a04cfeb647f6cba3db8673cf08ed94156 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Sat, 19 Oct 2024 22:54:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E4=B8=AA=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=85=B1=E7=94=A8=E5=90=8C=E4=B8=80=E4=B8=AA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=AF=BC=E8=87=B4=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88https://gitee.com/spark-sto?= =?UTF-8?q?re-project/spark-web-app-runtime/issues/IA759Q=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spark-webapp-runtime/mainwindow.cpp | 2 +- spark-webapp-runtime/widget.cpp | 14 +++++++++++++- spark-webapp-runtime/widget.h | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spark-webapp-runtime/mainwindow.cpp b/spark-webapp-runtime/mainwindow.cpp index 446013f..2e51f26 100644 --- a/spark-webapp-runtime/mainwindow.cpp +++ b/spark-webapp-runtime/mainwindow.cpp @@ -38,7 +38,7 @@ MainWindow::MainWindow(QString szTitle, , m_isFullScreen(nFullScreen) , m_isFixedSize(nFixSize) , m_isHideButton(nHideButtons) - , m_widget(new Widget(m_url, this)) + , m_widget(new Widget(m_url, this, m_title)) , m_tray(new QSystemTrayIcon(this)) , btnBack(new DToolButton(titlebar())) , btnForward(new DToolButton(titlebar())) diff --git a/spark-webapp-runtime/widget.cpp b/spark-webapp-runtime/widget.cpp index 61399f6..aae2e42 100644 --- a/spark-webapp-runtime/widget.cpp +++ b/spark-webapp-runtime/widget.cpp @@ -2,16 +2,19 @@ #include "webengineview.h" #include "webenginepage.h" +#include <QDir> +#include <QWebEngineProfile> #include <DApplication> DWIDGET_USE_NAMESPACE -Widget::Widget(QString szUrl, QWidget *parent) +Widget::Widget(QString szUrl, QWidget *parent, QString szTitle) : QWidget(parent) , m_webEngineView(new WebEngineView(this)) , m_spinner(new DSpinner(this)) , mainLayout(new QStackedLayout(this)) , m_szUrl(szUrl) + , m_szTitle(szTitle) { initUI(); initConnections(); @@ -54,6 +57,15 @@ void Widget::initUI() page->setUrl(QUrl()); if (!m_szUrl.isEmpty()) { page->setUrl(QUrl(m_szUrl)); + // 设置新的 cookie 路径以防止冲突(https://gitee.com/spark-store-project/spark-web-app-runtime/issues/IA759Q) + QString cookiePath = QDir::homePath() + + "/.config/spark-webapp-runtime/" + + QUrl::toPercentEncoding(m_szTitle); // 使用 url 转移以便正确将标题做为文件名 + QWebEngineProfile *profile = page->profile(); + if (!QDir(cookiePath).exists()) { + QDir().mkpath(cookiePath); + } + profile->setPersistentStoragePath(cookiePath); } QWidget *spinnerWidget = new QWidget(this); diff --git a/spark-webapp-runtime/widget.h b/spark-webapp-runtime/widget.h index 0c80a15..706dc96 100644 --- a/spark-webapp-runtime/widget.h +++ b/spark-webapp-runtime/widget.h @@ -17,7 +17,7 @@ class Widget : public QWidget Q_OBJECT public: - explicit Widget(QString szUrl = nullptr, QWidget *parent = nullptr); + explicit Widget(QString szUrl = nullptr, QWidget *parent = nullptr, QString szTitle = nullptr); ~Widget(); QWebEnginePage *getPage(); @@ -46,6 +46,7 @@ private: QStackedLayout *mainLayout = nullptr; QString m_szUrl; + QString m_szTitle; }; #endif // WIDGET_H