diff options
author | 2022-08-31 14:28:58 +0530 | |
---|---|---|
committer | 2022-08-31 14:28:58 +0530 | |
commit | ff575c452bf68f8ecc739979b2638f2a06d1acce (patch) | |
tree | 575cc7417c75b41ea69665f537254d7875af4ce8 /src | |
parent | d03e9fc67023375d36cba3daeb11fe1e56b82257 (diff) | |
download | whatsie-ff575c452bf68f8ecc739979b2638f2a06d1acce.tar.gz whatsie-ff575c452bf68f8ecc739979b2638f2a06d1acce.zip |
chore: some enhancements
- webengine multiprocess
- webengine disable sandbox
- minor memory usage improvements
Diffstat (limited to 'src')
-rw-r--r-- | src/lock.cpp | 5 | ||||
-rw-r--r-- | src/lock.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/mainwindow.cpp | 24 | ||||
-rw-r--r-- | src/utils.h | 2 | ||||
-rw-r--r-- | src/webenginepage.cpp | 10 | ||||
-rw-r--r-- | src/webview.cpp | 11 |
7 files changed, 32 insertions, 27 deletions
diff --git a/src/lock.cpp b/src/lock.cpp index a854a61..62c4604 100644 --- a/src/lock.cpp +++ b/src/lock.cpp @@ -13,8 +13,7 @@ Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) { ui->wrong->hide(); passcodeLoginAction = ui->passcodeLogin->addAction( - QIcon(":/icons/green_arrow-right-line.png"), - QLineEdit::TrailingPosition); + QIcon(":/icons/green_arrow-right-line.png"), QLineEdit::TrailingPosition); passcodeLoginAction->setEnabled(false); connect(passcodeLoginAction, &QAction::triggered, passcodeLoginAction, [this]() { @@ -219,7 +218,7 @@ void Lock::lock_app() { ui->passcodeLogin->setFocus(); } -void Lock::on_passcodeLogin_returnPressed() {passcodeLoginAction->trigger(); } +void Lock::on_passcodeLogin_returnPressed() { passcodeLoginAction->trigger(); } bool Lock::getCapsLockOn() { Display *d = XOpenDisplay((char *)0); @@ -15,6 +15,7 @@ class Lock : public QWidget { public: explicit Lock(QWidget *parent = nullptr); ~Lock(); + bool getIsLocked() const; private slots: @@ -22,7 +23,7 @@ private slots: void on_passcode2_textChanged(const QString &arg1); void on_setPass_clicked(); bool check_password_set(); - void on_passcodeLogin_textChanged(const QString &arg1); + void on_passcodeLogin_textChanged(const QString &arg1); void on_passcodeLogin_returnPressed(); bool getCapsLockOn(); void checkCaps(); diff --git a/src/main.cpp b/src/main.cpp index 84720ef..19cbcad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,9 +16,9 @@ int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #ifdef QT_DEBUG - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--remote-debugging-port=9421"); + qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--remote-debugging-port=9421 --ignore-gpu-blocklist --no-sandbox"); #else - qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --single-process"); + qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --ignore-gpu-blocklist --no-sandbox"); //--single-process #endif SingleApplication instance(argc, argv, true); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f4d70a2..a37e558 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -206,7 +206,9 @@ void MainWindow::updateWindowTheme() { } QList<QWidget *> widgets = this->findChildren<QWidget *>(); - foreach (QWidget *w, widgets) { w->setPalette(qApp->palette()); } + foreach (QWidget *w, widgets) { + w->setPalette(qApp->palette()); + } setNotificationPresenter(webEngine->page()->profile()); if (lockWidget != nullptr) { @@ -534,6 +536,7 @@ void MainWindow::notify(QString title, QString message) { }); } else { auto popup = new NotificationPopup(webEngine); + popup->setAttribute(Qt::WA_DeleteOnClose, true); connect(popup, &NotificationPopup::notification_clicked, popup, [=]() { if (windowState().testFlag(Qt::WindowMinimized) || !windowState().testFlag(Qt::WindowActive) || this->isHidden()) { @@ -826,6 +829,8 @@ void MainWindow::createWebPage(bool offTheRecord) { settings.value("useragent", defaultUserAgentStr).toString()); setNotificationPresenter(profile); + //profile->setHttpCacheMaximumSize(209715200/2); + //profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache); QWebEnginePage *page = new WebEnginePage(profile, webEngine); if (settings.value("windowTheme", "light").toString() == "dark") { @@ -838,8 +843,6 @@ void MainWindow::createWebPage(bool offTheRecord) { // Release of profile requested but WebEnginePage still not deleted. Expect // troubles ! profile->setParent(page); - // RequestInterceptor *interceptor = new RequestInterceptor(profile); - // profile->setUrlRequestInterceptor(interceptor); auto randomValue = QRandomGenerator::global()->generateDouble() * 300; page->setUrl( QUrl("https://web.whatsapp.com?v=" + QString::number(randomValue))); @@ -862,6 +865,7 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) { } auto popup = new NotificationPopup(webEngine); + popup->setAttribute(Qt::WA_DeleteOnClose, true); popup->setObjectName("engineNotifier"); connect(popup, &NotificationPopup::notification_clicked, popup, [=]() { if (windowState().testFlag(Qt::WindowMinimized) || @@ -1035,7 +1039,7 @@ void MainWindow::injectNewChatJavaScript() { void MainWindow::checkLoadedCorrectly() { if (webEngine && webEngine->page()) { - // test 1 based on the class name of body of the page + // test 1 based on the class name of body tag of the page webEngine->page()->runJavaScript( "document.querySelector('body').className", [this](const QVariant &result) { @@ -1050,12 +1054,10 @@ void MainWindow::checkLoadedCorrectly() { utils::delete_cache( webEngine->page()->profile()->persistentStoragePath()); settings.setValue("useragent", defaultUserAgentStr); - utils *util = new utils(this); - util->DisplayExceptionErrorDialog( + utils::DisplayExceptionErrorDialog( "test1 handleWebViewTitleChanged(title) title: Error, " "Resetting UA, Quiting!\nUA: " + settings.value("useragent", "DefaultUA").toString()); - quitAction->trigger(); } else { qDebug() << "Test 1 loaded correctly, value:" << result.toString(); @@ -1075,8 +1077,7 @@ void MainWindow::loadingQuirk(QString test) { utils::delete_cache(webEngine->page()->profile()->cachePath()); utils::delete_cache(webEngine->page()->profile()->persistentStoragePath()); settings.setValue("useragent", defaultUserAgentStr); - utils *util = new utils(this); - util->DisplayExceptionErrorDialog( + utils::DisplayExceptionErrorDialog( test + " checkLoadedCorrectly()/loadingQuirk() reload retries 0, Resetting " "UA, Quiting!\nUA: " + @@ -1110,7 +1111,8 @@ void MainWindow::handleDownloadRequested(QWebEngineDownloadItem *download) { void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) { Q_UNUSED(reason); - if (settings.value("minimizeOnTrayIconClick", false).toBool() == false || reason == QSystemTrayIcon::Context) + if (settings.value("minimizeOnTrayIconClick", false).toBool() == false || + reason == QSystemTrayIcon::Context) return; if (isVisible()) { hide(); @@ -1181,7 +1183,7 @@ bool MainWindow::isPhoneNumber(const QString &phoneNumber) { void MainWindow::doReload(bool byPassCache, bool isAskedByCLI, bool byLoadingQuirk) { if (byLoadingQuirk) { - this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, + this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, byPassCache); } else { if (lockWidget && !lockWidget->getIsLocked()) { diff --git a/src/utils.h b/src/utils.h index 10629e9..363dbe9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -36,7 +36,7 @@ public slots: static QString htmlToPlainText(QString str); static QString GetEnvironmentVar(const QString &variable_name); static float RoundToOneDecimal(float number); - void DisplayExceptionErrorDialog(const QString &error_info); + static void DisplayExceptionErrorDialog(const QString &error_info); static QString appDebugInfo(); static void desktopOpenUrl(const QString str); diff --git a/src/webenginepage.cpp b/src/webenginepage.cpp index 9a35761..2694c20 100644 --- a/src/webenginepage.cpp +++ b/src/webenginepage.cpp @@ -8,8 +8,10 @@ WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent) : QWebEnginePage(profile, parent) { auto userAgent = profile->httpUserAgent(); - auto webengineversion = userAgent.split("QtWebEngine").last().split(" ").first(); - auto toRemove = "QtWebEngine"+webengineversion; + qDebug() << "WebEnginePage::Profile::UserAgent" << userAgent; + auto webengineversion = + userAgent.split("QtWebEngine").last().split(" ").first(); + auto toRemove = "QtWebEngine" + webengineversion; auto cleanUserAgent = userAgent.remove(toRemove).replace(" ", " "); profile->setHttpUserAgent(cleanUserAgent); @@ -149,15 +151,14 @@ QStringList WebEnginePage::chooseFiles(QWebEnginePage::FileSelectionMode mode, } QFileDialog *dialog = new QFileDialog(); + dialog->setAttribute(Qt::WA_DeleteOnClose, true); bool usenativeFileDialog = settings.value("useNativeFileDialog", false).toBool(); if (usenativeFileDialog == false) { dialog->setOption(QFileDialog::DontUseNativeDialog, true); } - dialog->setFileMode(dialogMode); - QStringList mimeFilters; mimeFilters.append("application/octet-stream"); // to show All files(*) mimeFilters.append(acceptedMimeTypes); @@ -182,6 +183,7 @@ bool WebEnginePage::certificateError(const QWebEngineCertificateError &error) { QWidget *mainWindow = view()->window(); if (error.isOverridable()) { QDialog dialog(mainWindow); + dialog.setAttribute(Qt::WA_DeleteOnClose, true); dialog.setModal(true); dialog.setWindowFlags(dialog.windowFlags() & ~Qt::WindowContextHelpButtonHint); diff --git a/src/webview.cpp b/src/webview.cpp index 38de330..15958db 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -51,13 +51,14 @@ WebView::WebView(QWidget *parent, QStringList dictionaries) void WebView::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = page()->createStandardContextMenu(); + menu->setAttribute(Qt::WA_DeleteOnClose, true); // hide reload, back, forward, savepage, copyimagelink menus foreach (auto *action, menu->actions()) { - if (action == page()->action(QWebEnginePage::SavePage) - || action == page()->action(QWebEnginePage::Reload) - || action == page()->action(QWebEnginePage::Back) - || action == page()->action(QWebEnginePage::Forward) - || action == page()->action(QWebEnginePage::CopyImageUrlToClipboard)) { + if (action == page()->action(QWebEnginePage::SavePage) || + action == page()->action(QWebEnginePage::Reload) || + action == page()->action(QWebEnginePage::Back) || + action == page()->action(QWebEnginePage::Forward) || + action == page()->action(QWebEnginePage::CopyImageUrlToClipboard)) { action->setVisible(false); } } |