From 7e5525d4e9e999b208291f11bf2f631fd79272f3 Mon Sep 17 00:00:00 2001 From: zty199 <46324746+zty199@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:47:35 +0800 Subject: [PATCH] fix: setDescription from cmdline or cfg not working when aboutDialog is not created yet, ApplicationDescription can't be set Log: merge changes from develop/qt6 branch --- debian/rules | 21 ++-- spark-webapp-runtime/application.cpp | 76 +++++--------- spark-webapp-runtime/application.h | 6 +- spark-webapp-runtime/globaldefine.h | 3 - spark-webapp-runtime/main.cpp | 38 +++---- spark-webapp-runtime/mainwindow.cpp | 32 +++--- spark-webapp-runtime/spark-webapp-runtime.pro | 13 ++- .../spark-webapp-runtime_zh_CN.ts | 98 +++++++------------ spark-webapp-runtime/webengineview.cpp | 2 +- 9 files changed, 111 insertions(+), 178 deletions(-) diff --git a/debian/rules b/debian/rules index 6b40fdf..29a8e6f 100755 --- a/debian/rules +++ b/debian/rules @@ -1,35 +1,36 @@ #!/usr/bin/make -f -export QT_SELECT=5 +export QT_SELECT = qt5 +export DEB_BUILD_MAINT_OPTIONS = hardening=+all include /usr/share/dpkg/default.mk DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH) -DH_AUTO_ARGS = --parallel --buildsystem=qmake +DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) # Uncomment this to turn on verbose mode. -# export DH_VERBOSE=1 +#export DH_VERBOSE=1 %: dh $@ --parallel override_dh_auto_clean: - rm -rf $(CURDIR)/build + rm -rf $(CURDIR)/build-$(DEB_HOST_MULTIARCH) override_dh_auto_configure: - mkdir -p $(CURDIR)/build + mkdir -p $(CURDIR)/build-$(DEB_HOST_MULTIARCH) - dh_auto_configure MAKEFLAGS=-j$(JOBS) -- spark-webapp-runtime.pro \ - -spec linux-g++ CONFIG+=qtquickcompiler \ - -o $(CURDIR)/build/ + qmake BUILD_VERSION=$(DEB_VERSION_UPSTREAM) spark-webapp-runtime.pro \ + -spec linux-g++ CONFIG+=force_debug_info \ + -o $(CURDIR)/build-$(DEB_HOST_MULTIARCH)/ override_dh_auto_build: - make -C $(CURDIR)/build -j$(JOBS) + make -C $(CURDIR)/build-$(DEB_HOST_MULTIARCH) -j$(JOBS) override_dh_auto_install: - make -C $(CURDIR)/build install \ + make -C $(CURDIR)/build-$(DEB_HOST_MULTIARCH) install \ INSTALL_ROOT=$(CURDIR)/debian/spark-webapp-runtime diff --git a/spark-webapp-runtime/application.cpp b/spark-webapp-runtime/application.cpp index 290afa7..bf2e6ed 100644 --- a/spark-webapp-runtime/application.cpp +++ b/spark-webapp-runtime/application.cpp @@ -8,6 +8,8 @@ #include +const QString websiteLinkTemplate = "%2"; + Application::Application(int &argc, char **argv) : DApplication(argc, argv) { @@ -20,23 +22,21 @@ Application::Application(int &argc, char **argv) setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); } - setApplicationVersion(QString(CURRENT_VER)); setOrganizationName(ORGANIZATION_NAME); // 添加组织名称,和商店主体的文件夹同在 ~/.local/share/spark-union 文件夹下 - setApplicationName(APPLICATION_NAME); // 这里不要翻译,否则 ~/.local/share 中文件夹名也会被翻译 - setProductName(DEFAULT_TITLE); + setApplicationName(PROJECT_NAME); // 这里不要翻译,否则 ~/.local/share 中文件夹名也会被翻译 + setApplicationVersion(APP_VERSION); setApplicationDisplayName(DEFAULT_TITLE); - setApplicationLicense(" GPLv3 "); + setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg")); + + setProductIcon(QIcon(":/images/spark-webapp-runtime.svg")); + setProductName(websiteLinkTemplate.arg("https://gitee.com/deepin-community-store/spark-web-app-runtime", DEFAULT_TITLE)); + setApplicationDescription(QObject::tr("Presented By Spark developers # HadesStudio")); + setApplicationLicense(websiteLinkTemplate.arg("https://gitee.com/spark-store-project/spark-web-app-runtime/blob/master/LICENSE", "GPLv3")); } -void Application::handleAboutAction() +void Application::triggerAboutAction() { - if (aboutDialog()) { - DApplication::handleAboutAction(); - return; - } - - initAboutDialog(); - DApplication::handleAboutAction(); + handleAboutAction(); } QStringList Application::launchParams() const @@ -54,6 +54,21 @@ MainWindow *Application::mainWindow() return m_mainWindow; } +void Application::handleAboutAction() +{ + DApplication::handleAboutAction(); + + DAboutDialog *dialog = aboutDialog(); + if (dialog) { + // CompanyLogo + dialog->setCompanyLogo(QPixmap(":/images/Logo-Spark.png")); + // WebsiteName + dialog->setWebsiteName("Spark Project"); + // WebsiteLink + dialog->setWebsiteLink("https://gitee.com/deepin-community-store/"); + } +} + void Application::saveLaunchParams(int &argc, char **argv) { m_argc = argc; @@ -66,43 +81,6 @@ void Application::saveLaunchParams(int &argc, char **argv) qDebug() << Q_FUNC_INFO << m_argc << m_argv; } -void Application::initAboutDialog() -{ - // Customized DAboutDialog - DAboutDialog *dialog = new DAboutDialog(activeWindow()); - // WindowIcon - dialog->setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg")); - // ProductIcon - dialog->setProductIcon(QIcon(":/images/spark-webapp-runtime.svg")); - // ProductName - dialog->setProductName(productName()); - // Version - dialog->setVersion(translate("DAboutDialog", "Version: %1").arg(applicationVersion())); - // CompanyLogo - dialog->setCompanyLogo(QPixmap(":/images/Logo-Spark.png")); - // Description - - QString szDefaultDesc = QString("%1
" - "%2") - .arg(DEFAULT_TITLE) - .arg(QObject::tr("Presented By Spark developers # HadesStudio")); - - dialog->setDescription(szDefaultDesc); - // WebsiteName - dialog->setWebsiteName("Spark Project"); - // WebsiteLink - dialog->setWebsiteLink("https://gitee.com/deepin-community-store/"); - // License - dialog->setLicense(translate("DAboutDialog", "%1 is released under %2").arg(productName()).arg(applicationLicense())); - - setAboutDialog(dialog); - connect(aboutDialog(), &DAboutDialog::destroyed, this, [=] { - setAboutDialog(nullptr); - }); - - dialog->hide(); -} - void Application::slotMainWindowClose() { if (aboutDialog()) { diff --git a/spark-webapp-runtime/application.h b/spark-webapp-runtime/application.h index 805699a..3e24e38 100644 --- a/spark-webapp-runtime/application.h +++ b/spark-webapp-runtime/application.h @@ -13,16 +13,18 @@ class Application : public DApplication public: Application(int &argc, char **argv); - void handleAboutAction() override; + void triggerAboutAction(); QStringList launchParams() const; void setMainWindow(MainWindow *window); MainWindow *mainWindow(); +protected: + void handleAboutAction() override; + private: void saveLaunchParams(int &argc, char **argv); - void initAboutDialog(); signals: void sigQuit(); diff --git a/spark-webapp-runtime/globaldefine.h b/spark-webapp-runtime/globaldefine.h index af86626..4a5c45f 100644 --- a/spark-webapp-runtime/globaldefine.h +++ b/spark-webapp-runtime/globaldefine.h @@ -4,7 +4,6 @@ #include #define DEFAULT_TITLE QObject::tr("SparkWebAppRuntime") -#define APPLICATION_NAME QString("spark-webapp-runtime") #define ORGANIZATION_NAME QString("spark-union") #define DEFAULT_URL QString("qrc:/help/help.html") #define DEFAULT_WIDTH (1024) @@ -18,6 +17,4 @@ #define DEFAULT_PORT 0 #define DEFAULT_GPU 1 -#define CURRENT_VER QString("1.7.0") - #endif // GLOBALDEFINE_H diff --git a/spark-webapp-runtime/main.cpp b/spark-webapp-runtime/main.cpp index 03abf09..484bccf 100644 --- a/spark-webapp-runtime/main.cpp +++ b/spark-webapp-runtime/main.cpp @@ -19,23 +19,8 @@ int main(int argc, char *argv[]) { - if (!QString(qgetenv("XDG_CURRENT_DESKTOP")).toLower().startsWith("deepin")) { - qputenv("XDG_CURRENT_DESKTOP", "Deepin"); - } - // 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE"); -// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls"); -// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security"); -#ifdef __sw_64__ - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox"); -#endif - - if (!Dtk::Core::DSysInfo::isDDE()) { -#ifndef DSTORE_NO_DXCBs - DApplication::loadDXcbPlugin(); -#endif - } // 开启 HiDPI 缩放支持 DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -51,9 +36,6 @@ int main(int argc, char *argv[]) } Application a(fakeArgc, fakeArgv.data()); - // 保存 DTK 主题 - DApplicationSettings settings; - // 解析命令行启动参数 QCommandLineParser parser; @@ -180,10 +162,7 @@ int main(int argc, char *argv[]) #if SSL_SERVER quint16 u16sslPort = 0; #endif - QString szDefaultDesc = QString("%1
" - "%2") - .arg(DEFAULT_TITLE) - .arg(QObject::tr("Presented By Spark developers # HadesStudio")); + QString szDefaultDesc = QObject::tr("Presented By Spark developers # HadesStudio"); // 解析可能存在的配置文件 QString szCfgFile = DEFAULT_CFG; @@ -258,12 +237,17 @@ int main(int argc, char *argv[]) if (parser.isSet(useGPU)) { toUseGPU = parser.value(useGPU).toUInt(); } - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security"); - if (toUseGPU == true) { - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode --disable-web-security"); -#ifdef __sw_64__ - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--ignore-gpu-blocklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --enable-accelerated-video-decode --disable-web-security --no-sandbox"); + + QStringList chromium_flags = {"--disable-web-security"}; +#if defined __sw_64__ || __loongarch__ + chromium_flags << "--no-sandbox"; #endif + if (toUseGPU == true) { + chromium_flags << "--ignore-gpu-blocklist" + << "--enable-gpu-rasterization" + << "--enable-native-gpu-memory-buffers" + << "--enable-accelerated-video-decode"; + qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromium_flags.join(" ").toUtf8()); qDebug() << "Setting GPU to True."; } // 初始化 QtWebEngine 深色模式环境变量 diff --git a/spark-webapp-runtime/mainwindow.cpp b/spark-webapp-runtime/mainwindow.cpp index e129e68..1bdeaea 100644 --- a/spark-webapp-runtime/mainwindow.cpp +++ b/spark-webapp-runtime/mainwindow.cpp @@ -1,7 +1,5 @@ #include "mainwindow.h" #include "application.h" -#include "webengineview.h" -#include "webenginepage.h" #include #include @@ -50,8 +48,8 @@ MainWindow::MainWindow(QString szTitle, , m_clearCache(new QAction(QObject::tr("Clear Cache"), this)) , t_menu(new QMenu(this)) , t_show(new QAction(QObject::tr("Show MainWindow"), this)) - , t_about(new QAction(qApp->translate("TitleBarMenu", "About"), this)) - , t_exit(new QAction(qApp->translate("TitleBarMenu", "Exit"), this)) + , t_about(new QAction(qApp->translate("TitleBarMenu", QString("About").toUtf8().data()), this)) + , t_exit(new QAction(qApp->translate("TitleBarMenu", QString("Exit").toUtf8().data()), this)) , downloadMessage(new DFloatingMessage(DFloatingMessage::ResidentType, this)) , downloadProgressWidget(new QWidget(downloadMessage)) , progressBarLayout(new QHBoxLayout(downloadProgressWidget)) @@ -75,7 +73,7 @@ MainWindow::~MainWindow() void MainWindow::setIcon(QString szIconPath) { - if (!QFileInfo(szIconPath).exists()) { + if (!QFile::exists(szIconPath)) { return; } @@ -83,19 +81,13 @@ void MainWindow::setIcon(QString szIconPath) setWindowIcon(QIcon(szIconPath)); m_tray->setIcon(QIcon(szIconPath)); - DAboutDialog *aboutDialog = qobject_cast(qApp)->aboutDialog(); - if (aboutDialog) { - aboutDialog->setWindowIcon(QIcon::fromTheme(szIconPath)); - aboutDialog->setProductIcon(QIcon::fromTheme(szIconPath)); - } + qApp->setWindowIcon(QIcon::fromTheme(szIconPath)); + qApp->setProductIcon(QIcon::fromTheme(szIconPath)); } void MainWindow::setDescription(const QString &desc) { - DAboutDialog *aboutDialog = qobject_cast(qApp)->aboutDialog(); - if (aboutDialog) { - aboutDialog->setDescription(desc); - } + qApp->setApplicationDescription(desc); } QString MainWindow::title() const @@ -187,6 +179,7 @@ void MainWindow::initUI() fixSize(); fullScreen(); + hideButtons(); // 修复指定hidebuttons之后没有生效 } void MainWindow::initTitleBar() @@ -223,8 +216,6 @@ void MainWindow::initTitleBar() if (!m_isHideButton) { m_menu->addAction(m_hideButtons); - }else{ - hideButtons(); // 修复指定hidebuttons之后没有生效 } if (m_menu->actions().size() > 0) { @@ -303,7 +294,7 @@ void MainWindow::initConnections() fixSize(); }); connect(t_about, &QAction::triggered, this, [=]() { - qobject_cast(qApp)->handleAboutAction(); + qobject_cast(qApp)->triggerAboutAction(); }); connect(t_exit, &QAction::triggered, this, [=]() { exit(0); @@ -384,7 +375,7 @@ QString MainWindow::saveAs(QString fileName) QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + fileName); if (!saveFile.isEmpty()) { // 判断上层目录是否可写入 - if (QFileInfo(QFileInfo(saveFile).absolutePath()).isWritable()) { + if (QFileInfo(QFileInfo(saveFile).absoluteDir().canonicalPath()).isWritable()) { return saveFile; } else { return saveAs(fileName); @@ -418,14 +409,13 @@ void MainWindow::on_downloadStart(QWebEngineDownloadItem *item) { // 尝试加锁互斥量,禁止同时下载多个文件 if (mutex.tryLock()) { - QString fileName = QFileInfo(item->path()).fileName(); + QString fileName = item->downloadFileName(); QString filePath = saveAs(fileName); if (filePath.isEmpty()) { mutex.unlock(); return; } - item->setPath(filePath); - filePath = QFileInfo(item->path()).absoluteFilePath(); + item->setDownloadDirectory(QFileInfo(filePath).absoluteDir().canonicalPath()); connect(item, &QWebEngineDownloadItem::downloadProgress, this, &MainWindow::on_downloadProgress); connect(item, &QWebEngineDownloadItem::finished, this, [=]() { diff --git a/spark-webapp-runtime/spark-webapp-runtime.pro b/spark-webapp-runtime/spark-webapp-runtime.pro index 0f3d749..504c113 100644 --- a/spark-webapp-runtime/spark-webapp-runtime.pro +++ b/spark-webapp-runtime/spark-webapp-runtime.pro @@ -1,4 +1,4 @@ -QT += core gui webenginewidgets svg concurrent dbus +QT += core gui webenginewidgets concurrent greaterThan(QT_MAJOR_VERSION, 5): QT += widgets @@ -6,6 +6,13 @@ TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS +DEFINES += PROJECT_NAME=\\\"'$${TARGET}'\\\" + +# Get build version from qmake +VERSION = $$BUILD_VERSION +isEmpty(VERSION): VERSION = 1.0 +DEFINES += APP_VERSION=\\\"'$${VERSION}'\\\" + CONFIG += c++11 link_pkgconfig PKGCONFIG += dtkcore dtkgui dtkwidget @@ -31,10 +38,10 @@ SOURCES += \ webengineurlrequestinterceptor.cpp RESOURCES += \ - resources/resources.qrc + resources/resources.qrc TRANSLATIONS += \ - translations/spark-webapp-runtime_zh_CN.ts + translations/$${TARGET}_zh_CN.ts # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts index dd1df84..f9fd6ec 100644 --- a/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts +++ b/spark-webapp-runtime/translations/spark-webapp-runtime_zh_CN.ts @@ -1,109 +1,96 @@ - - DAboutDialog - - - Version: %1 - 版本:%1 - - - - %1 is released under %2 - %1遵循%2协议发布 - - QObject - - + + Presented By Spark developers # HadesStudio 由 星火开发者联盟 @ 花心胡萝卜 提供 - + Description: %1 描述:%1 - + Enable CommandLineParser. Default is false. 启用参数解析方式。默认顺序解析方式。 - + The Title of Application. Default is %1. 设置程序的运行标题。默认是 %1。 - + The target URL. Default is Blank. 设置要打开的目标 URL。默认是空。 - + The Width of Application. Default is %1. 设置应用的窗口宽度。默认是 %1。 - + The Height of Application. Default is %1. 设置应用的窗口高度。默认是 %1。 - + Enable Tray Icon. Default is false. 启用托盘图标。默认不启用。 - + Run in Fullscreen Mode. Default is false. 以全屏模式运行。默认关闭该功能。 - + Fix Window Size. Default is false. 固定窗口大小。默认关闭该功能。 - + Hide Control Buttons. Default is false. 隐藏控制按钮。默认关闭该此功能。 - + The ICON of Application. 设置应用的图标。 - + The Description of Application. 设置应用的描述信息。 - + The Configuration file of Application. 设置应用的配置文件。 - + The root path of the program web service. 设置内置 WebServer 的根路径。 - + The port number of the program web service. 设置内置 WebServer 的监听端口号。 - + To use GPU instead of CPU to decoding. Default True. 启用GPU渲染,默认开启。 - + The ssl port number of the program web service. 设置内置 WebServer 的 SSL 协议的监听端口号。 @@ -113,102 +100,89 @@ 星火网页应用运行环境 - + Full Screen 全屏显示 - + Fix Size 固定大小 - + Hide Buttons 隐藏按钮 - + Clear Cache 清理缓存 - + Show MainWindow 显示主界面 - + Pause 暂停 - + Resume 继续 - + Cancel 取消 - + Save As 另存为 - + %1Start downloading %2 %1开始下载 %2 - + %1Wait for previous download to complete! %1请等待上一个下载任务完成! - + Open 打开 - + download finished. 下载完成。 - + Show in file manager? 是否在文件管理器中显示? - + %1Download canceled! %1下载取消! - + %1Load error occurred! %1加载存在错误! - + View 查看 - - TitleBarMenu - - - About - 关于 - - - - Exit - 退出 - - diff --git a/spark-webapp-runtime/webengineview.cpp b/spark-webapp-runtime/webengineview.cpp index f85e4ac..9b924bc 100644 --- a/spark-webapp-runtime/webengineview.cpp +++ b/spark-webapp-runtime/webengineview.cpp @@ -34,7 +34,7 @@ void WebEngineView::handleChromiumFlags() DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); QString env = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"); - QStringList flags = env.split(" ", QString::SkipEmptyParts); + QStringList flags = env.split(" ", Qt::SkipEmptyParts); /** * --blink-settings=preferredColorScheme=0 强制 prefers-color-scheme=dark (>= 5.14)