Skip to content

Commit

Permalink
chore: dynamically find qwebengine_convert_dict binary (#214)
Browse files Browse the repository at this point in the history
fixes: #213
  • Loading branch information
keshavbhatt authored Nov 1, 2024
1 parent 2370015 commit a40d1b8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
27 changes: 17 additions & 10 deletions src/WhatsApp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
16 changes: 16 additions & 0 deletions src/tools/find_qwebengine_convert_dict.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 16 additions & 13 deletions src/webenginepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<QWebEngineCertificateError&>(error);
auto handler = const_cast<QWebEngineCertificateError &>(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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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%';
Expand All @@ -420,7 +423,7 @@ void WebEnginePage::injectFullWidthJavaScript() {
subtree: true
});
)";
this->runJavaScript(js);
this->runJavaScript(js);
}

void WebEnginePage::injectNewChatJavaScript() {
Expand Down

0 comments on commit a40d1b8

Please sign in to comment.