Skip to content

Commit ff575c4

Browse files
committed
chore: some enhancements
- webengine multiprocess - webengine disable sandbox - minor memory usage improvements
1 parent d03e9fc commit ff575c4

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

src/lock.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
1313
ui->wrong->hide();
1414

1515
passcodeLoginAction = ui->passcodeLogin->addAction(
16-
QIcon(":/icons/green_arrow-right-line.png"),
17-
QLineEdit::TrailingPosition);
16+
QIcon(":/icons/green_arrow-right-line.png"), QLineEdit::TrailingPosition);
1817
passcodeLoginAction->setEnabled(false);
1918
connect(passcodeLoginAction, &QAction::triggered, passcodeLoginAction,
2019
[this]() {
@@ -219,7 +218,7 @@ void Lock::lock_app() {
219218
ui->passcodeLogin->setFocus();
220219
}
221220

222-
void Lock::on_passcodeLogin_returnPressed() {passcodeLoginAction->trigger(); }
221+
void Lock::on_passcodeLogin_returnPressed() { passcodeLoginAction->trigger(); }
223222

224223
bool Lock::getCapsLockOn() {
225224
Display *d = XOpenDisplay((char *)0);

src/lock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ class Lock : public QWidget {
1515
public:
1616
explicit Lock(QWidget *parent = nullptr);
1717
~Lock();
18+
1819
bool getIsLocked() const;
1920

2021
private slots:
2122
void on_passcode1_textChanged(const QString &arg1);
2223
void on_passcode2_textChanged(const QString &arg1);
2324
void on_setPass_clicked();
2425
bool check_password_set();
25-
void on_passcodeLogin_textChanged(const QString &arg1);
26+
void on_passcodeLogin_textChanged(const QString &arg1);
2627
void on_passcodeLogin_returnPressed();
2728
bool getCapsLockOn();
2829
void checkCaps();

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ int main(int argc, char *argv[]) {
1616
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
1717

1818
#ifdef QT_DEBUG
19-
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--remote-debugging-port=9421");
19+
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--remote-debugging-port=9421 --ignore-gpu-blocklist --no-sandbox");
2020
#else
21-
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --single-process");
21+
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --ignore-gpu-blocklist --no-sandbox"); //--single-process
2222
#endif
2323

2424
SingleApplication instance(argc, argv, true);

src/mainwindow.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ void MainWindow::updateWindowTheme() {
206206
}
207207

208208
QList<QWidget *> widgets = this->findChildren<QWidget *>();
209-
foreach (QWidget *w, widgets) { w->setPalette(qApp->palette()); }
209+
foreach (QWidget *w, widgets) {
210+
w->setPalette(qApp->palette());
211+
}
210212
setNotificationPresenter(webEngine->page()->profile());
211213

212214
if (lockWidget != nullptr) {
@@ -534,6 +536,7 @@ void MainWindow::notify(QString title, QString message) {
534536
});
535537
} else {
536538
auto popup = new NotificationPopup(webEngine);
539+
popup->setAttribute(Qt::WA_DeleteOnClose, true);
537540
connect(popup, &NotificationPopup::notification_clicked, popup, [=]() {
538541
if (windowState().testFlag(Qt::WindowMinimized) ||
539542
!windowState().testFlag(Qt::WindowActive) || this->isHidden()) {
@@ -826,6 +829,8 @@ void MainWindow::createWebPage(bool offTheRecord) {
826829
settings.value("useragent", defaultUserAgentStr).toString());
827830

828831
setNotificationPresenter(profile);
832+
//profile->setHttpCacheMaximumSize(209715200/2);
833+
//profile->setHttpCacheType(QWebEngineProfile::MemoryHttpCache);
829834

830835
QWebEnginePage *page = new WebEnginePage(profile, webEngine);
831836
if (settings.value("windowTheme", "light").toString() == "dark") {
@@ -838,8 +843,6 @@ void MainWindow::createWebPage(bool offTheRecord) {
838843
// Release of profile requested but WebEnginePage still not deleted. Expect
839844
// troubles !
840845
profile->setParent(page);
841-
// RequestInterceptor *interceptor = new RequestInterceptor(profile);
842-
// profile->setUrlRequestInterceptor(interceptor);
843846
auto randomValue = QRandomGenerator::global()->generateDouble() * 300;
844847
page->setUrl(
845848
QUrl("https://web.whatsapp.com?v=" + QString::number(randomValue)));
@@ -862,6 +865,7 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) {
862865
}
863866

864867
auto popup = new NotificationPopup(webEngine);
868+
popup->setAttribute(Qt::WA_DeleteOnClose, true);
865869
popup->setObjectName("engineNotifier");
866870
connect(popup, &NotificationPopup::notification_clicked, popup, [=]() {
867871
if (windowState().testFlag(Qt::WindowMinimized) ||
@@ -1035,7 +1039,7 @@ void MainWindow::injectNewChatJavaScript() {
10351039

10361040
void MainWindow::checkLoadedCorrectly() {
10371041
if (webEngine && webEngine->page()) {
1038-
// test 1 based on the class name of body of the page
1042+
// test 1 based on the class name of body tag of the page
10391043
webEngine->page()->runJavaScript(
10401044
"document.querySelector('body').className",
10411045
[this](const QVariant &result) {
@@ -1050,12 +1054,10 @@ void MainWindow::checkLoadedCorrectly() {
10501054
utils::delete_cache(
10511055
webEngine->page()->profile()->persistentStoragePath());
10521056
settings.setValue("useragent", defaultUserAgentStr);
1053-
utils *util = new utils(this);
1054-
util->DisplayExceptionErrorDialog(
1057+
utils::DisplayExceptionErrorDialog(
10551058
"test1 handleWebViewTitleChanged(title) title: Error, "
10561059
"Resetting UA, Quiting!\nUA: " +
10571060
settings.value("useragent", "DefaultUA").toString());
1058-
10591061
quitAction->trigger();
10601062
} else {
10611063
qDebug() << "Test 1 loaded correctly, value:" << result.toString();
@@ -1075,8 +1077,7 @@ void MainWindow::loadingQuirk(QString test) {
10751077
utils::delete_cache(webEngine->page()->profile()->cachePath());
10761078
utils::delete_cache(webEngine->page()->profile()->persistentStoragePath());
10771079
settings.setValue("useragent", defaultUserAgentStr);
1078-
utils *util = new utils(this);
1079-
util->DisplayExceptionErrorDialog(
1080+
utils::DisplayExceptionErrorDialog(
10801081
test +
10811082
" checkLoadedCorrectly()/loadingQuirk() reload retries 0, Resetting "
10821083
"UA, Quiting!\nUA: " +
@@ -1110,7 +1111,8 @@ void MainWindow::handleDownloadRequested(QWebEngineDownloadItem *download) {
11101111

11111112
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) {
11121113
Q_UNUSED(reason);
1113-
if (settings.value("minimizeOnTrayIconClick", false).toBool() == false || reason == QSystemTrayIcon::Context)
1114+
if (settings.value("minimizeOnTrayIconClick", false).toBool() == false ||
1115+
reason == QSystemTrayIcon::Context)
11141116
return;
11151117
if (isVisible()) {
11161118
hide();
@@ -1181,7 +1183,7 @@ bool MainWindow::isPhoneNumber(const QString &phoneNumber) {
11811183
void MainWindow::doReload(bool byPassCache, bool isAskedByCLI,
11821184
bool byLoadingQuirk) {
11831185
if (byLoadingQuirk) {
1184-
this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
1186+
this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
11851187
byPassCache);
11861188
} else {
11871189
if (lockWidget && !lockWidget->getIsLocked()) {

src/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public slots:
3636
static QString htmlToPlainText(QString str);
3737
static QString GetEnvironmentVar(const QString &variable_name);
3838
static float RoundToOneDecimal(float number);
39-
void DisplayExceptionErrorDialog(const QString &error_info);
39+
static void DisplayExceptionErrorDialog(const QString &error_info);
4040
static QString appDebugInfo();
4141
static void desktopOpenUrl(const QString str);
4242

src/webenginepage.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent)
88
: QWebEnginePage(profile, parent) {
99

1010
auto userAgent = profile->httpUserAgent();
11-
auto webengineversion = userAgent.split("QtWebEngine").last().split(" ").first();
12-
auto toRemove = "QtWebEngine"+webengineversion;
11+
qDebug() << "WebEnginePage::Profile::UserAgent" << userAgent;
12+
auto webengineversion =
13+
userAgent.split("QtWebEngine").last().split(" ").first();
14+
auto toRemove = "QtWebEngine" + webengineversion;
1315
auto cleanUserAgent = userAgent.remove(toRemove).replace(" ", " ");
1416
profile->setHttpUserAgent(cleanUserAgent);
1517

@@ -149,15 +151,14 @@ QStringList WebEnginePage::chooseFiles(QWebEnginePage::FileSelectionMode mode,
149151
}
150152

151153
QFileDialog *dialog = new QFileDialog();
154+
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
152155
bool usenativeFileDialog =
153156
settings.value("useNativeFileDialog", false).toBool();
154157

155158
if (usenativeFileDialog == false) {
156159
dialog->setOption(QFileDialog::DontUseNativeDialog, true);
157160
}
158-
159161
dialog->setFileMode(dialogMode);
160-
161162
QStringList mimeFilters;
162163
mimeFilters.append("application/octet-stream"); // to show All files(*)
163164
mimeFilters.append(acceptedMimeTypes);
@@ -182,6 +183,7 @@ bool WebEnginePage::certificateError(const QWebEngineCertificateError &error) {
182183
QWidget *mainWindow = view()->window();
183184
if (error.isOverridable()) {
184185
QDialog dialog(mainWindow);
186+
dialog.setAttribute(Qt::WA_DeleteOnClose, true);
185187
dialog.setModal(true);
186188
dialog.setWindowFlags(dialog.windowFlags() &
187189
~Qt::WindowContextHelpButtonHint);

src/webview.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ WebView::WebView(QWidget *parent, QStringList dictionaries)
5151
void WebView::contextMenuEvent(QContextMenuEvent *event) {
5252

5353
QMenu *menu = page()->createStandardContextMenu();
54+
menu->setAttribute(Qt::WA_DeleteOnClose, true);
5455
// hide reload, back, forward, savepage, copyimagelink menus
5556
foreach (auto *action, menu->actions()) {
56-
if (action == page()->action(QWebEnginePage::SavePage)
57-
|| action == page()->action(QWebEnginePage::Reload)
58-
|| action == page()->action(QWebEnginePage::Back)
59-
|| action == page()->action(QWebEnginePage::Forward)
60-
|| action == page()->action(QWebEnginePage::CopyImageUrlToClipboard)) {
57+
if (action == page()->action(QWebEnginePage::SavePage) ||
58+
action == page()->action(QWebEnginePage::Reload) ||
59+
action == page()->action(QWebEnginePage::Back) ||
60+
action == page()->action(QWebEnginePage::Forward) ||
61+
action == page()->action(QWebEnginePage::CopyImageUrlToClipboard)) {
6162
action->setVisible(false);
6263
}
6364
}

0 commit comments

Comments
 (0)