From a40d1b884be706895716beecd614170ae71975fa Mon Sep 17 00:00:00 2001 From: Keshav Bhatt Date: Fri, 1 Nov 2024 22:55:03 +0530 Subject: [PATCH] chore: dynamically find qwebengine_convert_dict binary (#214) fixes: #213 --- src/WhatsApp.pro | 27 +++++++++++++-------- src/tools/find_qwebengine_convert_dict.sh | 16 +++++++++++++ src/webenginepage.cpp | 29 +++++++++++++---------- 3 files changed, 49 insertions(+), 23 deletions(-) create mode 100755 src/tools/find_qwebengine_convert_dict.sh diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro index 5d5ed16..ee5de2e 100644 --- a/src/WhatsApp.pro +++ b/src/WhatsApp.pro @@ -157,30 +157,37 @@ DATADIR = $$PREFIX/share target.path = $$BINDIR -CONFIG(FLATPAK){ - message("This is a flatpak build, assuming dicts are not required.") -}else{ - qtPrepareTool(CONVERT_TOOL, qwebengine_convert_dict) +CONFIG(FLATPAK) { + message("This is a Flatpak build, assuming dictionaries are not required.") +} else { + greaterThan(QT_MAJOR_VERSION, 5) { + QMAKE_PATH_QWEBENGINE_CONVERT_DICT = $$PWD/tools/find_qwebengine_convert_dict.sh + } else { + qtPrepareTool(CONVERT_TOOL, qwebengine_convert_dict) + } DICTIONARIES_DIR = qtwebengine_dictionaries - dict.files = $$files($$PWD/dictionaries/*.dic, true) dictoolbuild.input = dict.files dictoolbuild.output = $${DICTIONARIES_DIR}/${QMAKE_FILE_BASE}.bdic dictoolbuild.depends = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.aff - dictoolbuild.commands = $${CONVERT_TOOL} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} dictoolbuild.name = Build ${QMAKE_FILE_IN_BASE} dictoolbuild.CONFIG = no_link target_predeps + + greaterThan(QT_MAJOR_VERSION, 5) { + dictoolbuild.commands = $${QMAKE_PATH_QWEBENGINE_CONVERT_DICT} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} + } else { + dictoolbuild.commands = $${CONVERT_TOOL} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} + } + QMAKE_EXTRA_COMPILERS += dictoolbuild - + dictionaries.files = $${DICTIONARIES_DIR}/ - dictionaries.path = $$DATADIR/org.keshavnrj.ubuntu/WhatSie/ - + dictionaries.path = $$DATADIR/org.keshavnrj.ubuntu/WhatSie/ unix:INSTALLS += dictionaries } - icon16.path = $$PREFIX/share/icons/hicolor/16x16/apps/ icon16.files = ../dist/linux/hicolor/16x16/apps/com.ktechpit.whatsie.png icon32.path = $$PREFIX/share/icons/hicolor/32x32/apps/ diff --git a/src/tools/find_qwebengine_convert_dict.sh b/src/tools/find_qwebengine_convert_dict.sh new file mode 100755 index 0000000..e278cad --- /dev/null +++ b/src/tools/find_qwebengine_convert_dict.sh @@ -0,0 +1,16 @@ +#!/bin/bash +POSSIBLE_PATHS=( + "/usr/lib/qt6/libexec/qwebengine_convert_dict" + "/usr/lib/qt6/qwebengine_convert_dict" + "/usr/lib/qt6/bin/qwebengine_convert_dict" +) + +for path in "${POSSIBLE_PATHS[@]}"; do + if [[ -x "$path" ]]; then + exec "$path" "$@" + exit 0 + fi +done + +echo "qwebengine_convert_dict not found in any specified paths" >&2 +exit 1 diff --git a/src/webenginepage.cpp b/src/webenginepage.cpp index fca21f8..0d31b66 100644 --- a/src/webenginepage.cpp +++ b/src/webenginepage.cpp @@ -202,7 +202,8 @@ QStringList WebEnginePage::chooseFiles(QWebEnginePage::FileSelectionMode mode, } #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) -void WebEnginePage::handleCertificateError(const QWebEngineCertificateError &error) { +void WebEnginePage::handleCertificateError( + const QWebEngineCertificateError &error) { QString description = error.description(); #else bool WebEnginePage::certificateError(const QWebEngineCertificateError &error) { @@ -224,18 +225,17 @@ bool WebEnginePage::certificateError(const QWebEngineCertificateError &error) { dialog.setWindowTitle(tr("Certificate Error")); bool accepted = dialog.exec() == QDialog::Accepted; #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - auto handler = const_cast(error); + auto handler = const_cast(error); if (accepted) - handler.acceptCertificate(); + handler.acceptCertificate(); else - handler.rejectCertificate(); + handler.rejectCertificate(); #else return accepted; #endif } - QMessageBox::critical(mainWindow, tr("Certificate Error"), - description); + QMessageBox::critical(mainWindow, tr("Certificate Error"), description); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return false; @@ -325,7 +325,7 @@ void WebEnginePage::handleSelectClientCertificate( qDebug() << __FUNCTION__; auto certificates = selection.certificates(); - for (const QSslCertificate &cert : qAsConst(certificates)) { + for (const QSslCertificate &cert : std::as_const(certificates)) { qDebug() << cert; selection.select(cert); // select the first available cert break; @@ -393,15 +393,18 @@ void WebEnginePage::injectClassChangeObserver() { characterData: false }); )"; - this->runJavaScript(js); + this->runJavaScript(js); } void WebEnginePage::injectFullWidthJavaScript() { - if (!SettingsManager::instance().settings().value("fullWidthView", true).toBool()) - return; + if (!SettingsManager::instance() + .settings() + .value("fullWidthView", true) + .toBool()) + return; - QString js = - R"(function updateFullWidthView(element) { + QString js = + R"(function updateFullWidthView(element) { var container = document.querySelector('#app > .app-wrapper-web > .two'); container.style.width = '100%'; container.style.height = '100%'; @@ -420,7 +423,7 @@ void WebEnginePage::injectFullWidthJavaScript() { subtree: true }); )"; - this->runJavaScript(js); + this->runJavaScript(js); } void WebEnginePage::injectNewChatJavaScript() {