aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md21
-rw-r--r--src/WhatsApp.pro10
-rw-r--r--src/about.cpp8
-rw-r--r--src/about.h3
-rw-r--r--src/automatictheme.cpp2
-rw-r--r--src/downloadmanagerwidget.cpp8
-rw-r--r--src/downloadmanagerwidget.h2
-rw-r--r--src/downloadwidget.h2
-rw-r--r--src/downloadwidget.ui3
-rw-r--r--src/main.cpp1
-rw-r--r--src/mainwindow.cpp187
-rw-r--r--src/mainwindow.h13
-rw-r--r--src/sunclock.cpp (renamed from src/SunClock.cpp)2
-rw-r--r--src/sunclock.hpp (renamed from src/SunClock.hpp)0
-rw-r--r--src/webenginepage.cpp113
-rw-r--r--src/webenginepage.h5
-rw-r--r--src/webview.cpp41
-rw-r--r--src/webview.h2
-rw-r--r--src/widgets/elidedlabel/elidedlabel.cpp (renamed from src/elidedlabel.cpp)0
-rw-r--r--src/widgets/elidedlabel/elidedlabel.h (renamed from src/elidedlabel.h)0
20 files changed, 236 insertions, 187 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e42b09d..4cfcd40 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,24 @@
+## 4.12.0 (2023-01-26)
+
+#### 🎁 Feature
+
+* close permission dialog with esc key (ee519bcc)
+* close with esc button (2119c3d1)
+
+#### 🐞 Bug Fixes
+
+* prevent zoom with ctrl+mouse (0eb7ea05)
+
+#### 📄 Documentation
+
+* **changelog:** update cl & ver after release (b3e2a2be)
+
+#### 🚧 Chores
+
+* bump version 4.12 (12bce6d2)
+* cleanup (c78394d1)
+
+
## 4.11.0 (2023-01-26)
#### 🎁 Feature
diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro
index 36b1ca2..844c000 100644
--- a/src/WhatsApp.pro
+++ b/src/WhatsApp.pro
@@ -59,29 +59,27 @@ DEFINES += VERSIONSTR=\\\"$${VERSION}\\\"
# DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
- SunClock.cpp \
about.cpp \
automatictheme.cpp \
dictionaries.cpp \
downloadmanagerwidget.cpp \
downloadwidget.cpp \
- elidedlabel.cpp \
lock.cpp \
main.cpp \
mainwindow.cpp \
permissiondialog.cpp \
rateapp.cpp \
settingswidget.cpp \
+ sunclock.cpp \
utils.cpp \
webenginepage.cpp \
webview.cpp \
+ widgets/elidedlabel/elidedlabel.cpp \
widgets/scrolltext/scrolltext.cpp
-
RESOURCES += \
icons.qrc
HEADERS += \
- SunClock.hpp \
about.h \
autolockeventfilter.h \
automatictheme.h \
@@ -90,7 +88,6 @@ HEADERS += \
dictionaries.h \
downloadmanagerwidget.h \
downloadwidget.h \
- elidedlabel.h \
lock.h \
mainwindow.h \
notificationpopup.h \
@@ -98,11 +95,12 @@ HEADERS += \
rateapp.h \
requestinterceptor.h \
settingswidget.h \
+ sunclock.hpp \
utils.h \
webenginepage.h \
webview.h \
+ widgets/elidedlabel/elidedlabel.h \
widgets/scrolltext/scrolltext.h
-
FORMS += \
about.ui \
automatictheme.ui \
diff --git a/src/about.cpp b/src/about.cpp
index ba54a7e..81657e8 100644
--- a/src/about.cpp
+++ b/src/about.cpp
@@ -92,6 +92,14 @@ void About::on_debugInfoButton_clicked() {
}
}
+void About::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ this->close();
+
+ QWidget::keyPressEvent(e);
+}
+
void About::on_donate_2_clicked() {
QDesktopServices::openUrl(QUrl("https://opencollective.com/whatsie"));
}
diff --git a/src/about.h b/src/about.h
index 74bfe0d..cd9e978 100644
--- a/src/about.h
+++ b/src/about.h
@@ -2,6 +2,7 @@
#define ABOUT_H
#include <QWidget>
+#include <QKeyEvent>
namespace Ui {
class About;
@@ -15,6 +16,8 @@ public:
explicit About(QWidget *parent = nullptr);
~About();
+protected slots:
+ void keyPressEvent(QKeyEvent *e);
private slots:
void on_debugInfoButton_clicked();
diff --git a/src/automatictheme.cpp b/src/automatictheme.cpp
index 6e14623..3cf33c8 100644
--- a/src/automatictheme.cpp
+++ b/src/automatictheme.cpp
@@ -1,7 +1,7 @@
#include "automatictheme.h"
#include "ui_automatictheme.h"
-#include "SunClock.hpp"
+#include "sunclock.hpp"
#include <QMessageBox>
AutomaticTheme::AutomaticTheme(QWidget *parent)
diff --git a/src/downloadmanagerwidget.cpp b/src/downloadmanagerwidget.cpp
index 2d75287..e9865c8 100644
--- a/src/downloadmanagerwidget.cpp
+++ b/src/downloadmanagerwidget.cpp
@@ -56,3 +56,11 @@ void DownloadManagerWidget::on_open_download_dir_clicked() {
QApplication::applicationName())
.toString());
}
+
+void DownloadManagerWidget::keyPressEvent(QKeyEvent *e)
+{
+ if (e->key() == Qt::Key_Escape)
+ this->close();
+
+ QWidget::keyPressEvent(e);
+}
diff --git a/src/downloadmanagerwidget.h b/src/downloadmanagerwidget.h
index 7fa0950..4a8d059 100644
--- a/src/downloadmanagerwidget.h
+++ b/src/downloadmanagerwidget.h
@@ -75,6 +75,8 @@ public:
// will be shown on the screen.
void downloadRequested(QWebEngineDownloadItem *webItem);
+protected slots:
+ void keyPressEvent(QKeyEvent *e);
private slots:
void on_open_download_dir_clicked();
diff --git a/src/downloadwidget.h b/src/downloadwidget.h
index ff9e488..074a979 100644
--- a/src/downloadwidget.h
+++ b/src/downloadwidget.h
@@ -52,7 +52,7 @@
#define DOWNLOADWIDGET_H
#include "ui_downloadwidget.h"
-#include "elidedlabel.h"
+#include "widgets/elidedlabel/elidedlabel.h"
#include <QFrame>
diff --git a/src/downloadwidget.ui b/src/downloadwidget.ui
index d405b8f..45d16e9 100644
--- a/src/downloadwidget.ui
+++ b/src/downloadwidget.ui
@@ -47,7 +47,6 @@
<widget class="ElidedLabel" name="m_dstName">
<property name="font">
<font>
- <weight>75</weight>
<bold>true</bold>
</font>
</property>
@@ -72,7 +71,7 @@
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
- <header>elidedlabel.h</header>
+ <header>widgets/elidedlabel/elidedlabel.h</header>
</customwidget>
</customwidgets>
<resources/>
diff --git a/src/main.cpp b/src/main.cpp
index 7e0c5cd..5a17d78 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,6 +25,7 @@ int main(int argc, char *argv[]) {
instance.setQuitOnLastWindowClosed(false);
instance.setWindowIcon(QIcon(":/icons/app/icon-128.png"));
QApplication::setApplicationName("WhatSie");
+ QApplication::setDesktopFileName("com.ktechpit.whatsie");
QApplication::setOrganizationDomain("com.ktechpit");
QApplication::setOrganizationName("org.keshavnrj.ubuntu");
QApplication::setApplicationVersion(VERSIONSTR);
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 3d01ba0..c8d688e 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -39,7 +39,8 @@ void MainWindow::restoreMainWindow() {
if (settings.value("geometry").isValid()) {
restoreGeometry(settings.value("geometry").toByteArray());
QPoint pos = QCursor::pos();
- for (QScreen *screen : QGuiApplication::screens()) {
+ auto localScreens = QGuiApplication::screens();
+ for (auto screen : qAsConst(localScreens)) {
QRect screenRect = screen->geometry();
if (screenRect.contains(pos)) {
this->move(screenRect.center() - this->rect().center());
@@ -205,11 +206,11 @@ void MainWindow::updateWindowTheme() {
settings.value("widgetStyle", "Fusion").toString()));
if (settings.value("windowTheme", "light").toString() == "dark") {
qApp->setPalette(darkPalette);
- this->webEngine->setStyleSheet(
+ webEngine->setStyleSheet(
"QWebEngineView{background:rgb(17, 27, 33);}"); // whatsapp dark color
} else {
qApp->setPalette(lightPalette);
- this->webEngine->setStyleSheet(
+ webEngine->setStyleSheet(
"QWebEngineView{background:#F0F0F0;}"); // whatsapp light color
}
@@ -316,7 +317,7 @@ void MainWindow::initSettingWidget() {
webSettings->setAttribute(
QWebEngineSettings::PlaybackRequiresUserGesture, checked);
- this->webEngine->page()->profile()->settings()->setAttribute(
+ webEngine->page()->profile()->settings()->setAttribute(
QWebEngineSettings::PlaybackRequiresUserGesture, checked);
});
@@ -356,9 +357,8 @@ void MainWindow::initSettingWidget() {
});
connect(settingsWidget, &SettingsWidget::notificationPopupTimeOutChanged,
- settingsWidget, [=]() {
- setNotificationPresenter(this->webEngine->page()->profile());
- });
+ settingsWidget,
+ [=]() { setNotificationPresenter(webEngine->page()->profile()); });
connect(settingsWidget, &SettingsWidget::notify, settingsWidget,
[=](QString message) { notify("", message); });
@@ -381,7 +381,7 @@ void MainWindow::initSettingWidget() {
settings.value("lockscreen", false).toBool());
// spell checker
- settingsWidget->loadDictionaries(m_dictionaries);
+ settingsWidget->loadDictionaries(dictionaries);
}
}
@@ -392,7 +392,8 @@ void MainWindow::changeEvent(QEvent *e) {
QMainWindow::changeEvent(e);
}
-void MainWindow::handleZoomOnWindowStateChange(QWindowStateChangeEvent *ev) {
+void MainWindow::handleZoomOnWindowStateChange(
+ const QWindowStateChangeEvent *ev) {
if (settingsWidget != nullptr) {
if (ev->oldState().testFlag(Qt::WindowMaximized) &&
windowState().testFlag(Qt::WindowNoState)) {
@@ -479,7 +480,7 @@ void MainWindow::showSettings(bool isAskedByCLI) {
void MainWindow::updateSettingsUserAgentWidget() {
settingsWidget->updateDefaultUAButton(
- this->webEngine->page()->profile()->httpUserAgent());
+ webEngine->page()->profile()->httpUserAgent());
}
void MainWindow::askToReloadPage() {
@@ -743,17 +744,18 @@ void MainWindow::appAutoLockChanged() {
void MainWindow::checkWindowState() {
QObject *tray_icon_menu = this->findChild<QObject *>("trayIconMenu");
if (tray_icon_menu != nullptr) {
+ QMenu *menu = qobject_cast<QMenu *>(tray_icon_menu);
if (this->isVisible()) {
- ((QMenu *)(tray_icon_menu))->actions().at(0)->setDisabled(false);
- ((QMenu *)(tray_icon_menu))->actions().at(1)->setDisabled(true);
+ menu->actions().at(0)->setDisabled(false);
+ menu->actions().at(1)->setDisabled(true);
} else {
- ((QMenu *)(tray_icon_menu))->actions().at(0)->setDisabled(true);
- ((QMenu *)(tray_icon_menu))->actions().at(1)->setDisabled(false);
+ menu->actions().at(0)->setDisabled(true);
+ menu->actions().at(1)->setDisabled(false);
}
if (lockWidget && lockWidget->getIsLocked()) {
- ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(true);
+ menu->actions().at(4)->setDisabled(true);
} else {
- ((QMenu *)(tray_icon_menu))->actions().at(4)->setDisabled(false);
+ menu->actions().at(4)->setDisabled(false);
}
}
}
@@ -804,18 +806,18 @@ void MainWindow::createWebEngine() {
widgetSize.setHorizontalStretch(1);
widgetSize.setVerticalStretch(1);
- m_dictionaries = Dictionaries::GetDictionaries();
+ dictionaries = Dictionaries::GetDictionaries();
- WebView *webEngine = new WebView(this, m_dictionaries);
- setCentralWidget(webEngine);
- webEngine->setSizePolicy(widgetSize);
- webEngine->show();
+ WebView *webEngineView = new WebView(this, dictionaries);
+ setCentralWidget(webEngineView);
+ webEngineView->setSizePolicy(widgetSize);
+ webEngineView->show();
- this->webEngine = webEngine;
+ this->webEngine = webEngineView;
- webEngine->addAction(minimizeAction);
- webEngine->addAction(lockAction);
- webEngine->addAction(quitAction);
+ webEngineView->addAction(minimizeAction);
+ webEngineView->addAction(lockAction);
+ webEngineView->addAction(quitAction);
createWebPage(false);
}
@@ -832,11 +834,11 @@ const QIcon MainWindow::getTrayIcon(const int &notificationCount) const {
}
void MainWindow::createWebPage(bool offTheRecord) {
- if (offTheRecord && !m_otrProfile) {
- m_otrProfile.reset(new QWebEngineProfile);
+ if (offTheRecord && !otrProfile) {
+ otrProfile.reset(new QWebEngineProfile);
}
auto profile =
- offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
+ offTheRecord ? otrProfile.get() : QWebEngineProfile::defaultProfile();
QStringList dict_names;
dict_names.append(settings.value("sc_dict", "en-US").toString());
@@ -864,7 +866,7 @@ void MainWindow::createWebPage(bool offTheRecord) {
QUrl("https://web.whatsapp.com?v=" + QString::number(randomValue)));
connect(profile, &QWebEngineProfile::downloadRequested,
- &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
+ &downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
connect(page, SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), this,
SLOT(fullScreenRequested(QWebEngineFullScreenRequest)));
@@ -964,120 +966,13 @@ void MainWindow::handleLoadFinished(bool loaded) {
checkLoadedCorrectly();
updatePageTheme();
handleZoom();
- injectMutationObserver();
- injectPreventScrollWheelZoomHelper();
- injectFullWidthJavaScript();
- injectClassChangeObserver();
- injectNewChatJavaScript();
+
if (settingsWidget != nullptr) {
settingsWidget->refresh();
}
}
}
-void MainWindow::injectPreventScrollWheelZoomHelper() {
- QString js = R"(
- (function () {
- const SSWZ = function () {
- this.keyScrollHandler = function (e) {
- if (e.ctrlKey) {
- e.preventDefault();
- return false;
- }
- }
- };
- if (window === top) {
- const sswz = new SSWZ();
- window.addEventListener('wheel', sswz.keyScrollHandler, {
- passive: false
- });
- }
- })();
- )";
- webEngine->page()->runJavaScript(js);
-}
-
-void MainWindow::injectClassChangeObserver() {
- QString js = R"(
- const observer = new MutationObserver(() => {
- var haveFullView = document.body.classList.contains('whatsie-full-view');
- var container = document.querySelector('#app > .app-wrapper-web > div');
- if(container){
- if(haveFullView){
- container.style.width = '100%';
- container.style.height = '100%';
- container.style.top = '0';
- container.style.maxWidth = 'unset';
- }else{
- container.style.width = null;
- container.style.height = null;
- container.style.top = null;
- container.style.maxWidth = null;
- }
- }
- });
- observer.observe(document.body, {
- attributes: true,
- attributeFilter: ['class'],
- childList: false,
- characterData: false
- });)";
- webEngine->page()->runJavaScript(js);
-}
-
-void MainWindow::injectMutationObserver() {
- QString js =
- R"(function waitForElement(selector) {
- return new Promise(resolve => {
- if (document.querySelector(selector)) {
- return resolve(document.querySelector(selector));
- }
- const observer = new MutationObserver(mutations => {
- if (document.querySelector(selector)) {
- resolve(document.querySelector(selector));
- observer.disconnect();
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- });
- };)";
- webEngine->page()->runJavaScript(js);
-}
-
-void MainWindow::injectFullWidthJavaScript() {
- if (!settings.value("fullWidthView", true).toBool())
- return;
- QString js =
- R"(waitForElement('#pane-side').then( () => {
- var container = document.querySelector('#app > .app-wrapper-web > div');
- container.style.width = '100%';
- container.style.height = '100%';
- container.style.top = '0';
- container.style.maxWidth = 'unset';
- });
- )";
- webEngine->page()->runJavaScript(js);
-}
-
-void MainWindow::injectNewChatJavaScript() {
- QString js = R"(const openNewChatWhatsie = (phone,text) => {
- const link = document.createElement('a');
- link.setAttribute('href',
- `whatsapp://send/?phone=${phone}&text=${text}`);
- document.body.append(link);
- link.click();
- document.body.removeChild(link);
- };
- function openNewChatWhatsieDefined()
- {
- return (openNewChatWhatsie != 'undefined');
- })";
- webEngine->page()->runJavaScript(js);
-}
-
void MainWindow::checkLoadedCorrectly() {
if (webEngine && webEngine->page()) {
// test 1 based on the class name of body tag of the page
@@ -1172,8 +1067,8 @@ void MainWindow::messageClicked() {
void MainWindow::doAppReload() {
- if (this->webEngine->page()) {
- this->webEngine->page()->disconnect();
+ if (webEngine->page()) {
+ webEngine->page()->disconnect();
}
createWebPage(false);
}
@@ -1195,7 +1090,7 @@ void MainWindow::triggerNewChat(QString phone, QString text) {
"openNewChatWhatsieDefined()",
[this, phone, text](const QVariant &result) {
if (result.toString().contains("true")) {
- this->webEngine->page()->runJavaScript(
+ webEngine->page()->runJavaScript(
QString("openNewChatWhatsie(\"%1\",\"%2\")").arg(phone, text));
} else {
// create send url equivalent
@@ -1203,7 +1098,7 @@ void MainWindow::triggerNewChat(QString phone, QString text) {
textStr = text.isEmpty() ? "" : "text=" + text;
QString urlStr =
"https://web.whatsapp.com/send?" + phoneStr + "&" + textStr;
- this->webEngine->page()->load(QUrl(urlStr));
+ webEngine->page()->load(QUrl(urlStr));
}
this->alreadyRunning();
});
@@ -1212,8 +1107,8 @@ void MainWindow::triggerNewChat(QString phone, QString text) {
void MainWindow::doReload(bool byPassCache, bool isAskedByCLI,
bool byLoadingQuirk) {
if (byLoadingQuirk) {
- this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
- byPassCache);
+ webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
+ byPassCache);
} else {
if (lockWidget && !lockWidget->getIsLocked()) {
this->notify(QApplication::applicationName(),
@@ -1229,13 +1124,13 @@ void MainWindow::doReload(bool byPassCache, bool isAskedByCLI,
this->show();
return;
}
- this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
- byPassCache);
+ webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache,
+ byPassCache);
}
}
void MainWindow::toggleMute(const bool &checked) {
- this->webEngine->page()->setAudioMuted(checked);
+ webEngine->page()->setAudioMuted(checked);
}
// get value of page theme when page is loaded
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 98dbf8b..4ca25d5 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -91,11 +91,11 @@ private:
QSystemTrayIcon *trayIcon;
QWebEngineView *webEngine;
SettingsWidget *settingsWidget = nullptr;
- DownloadManagerWidget m_downloadManagerWidget;
- QScopedPointer<QWebEngineProfile> m_otrProfile;
+ DownloadManagerWidget downloadManagerWidget;
+ QScopedPointer<QWebEngineProfile> otrProfile;
Lock *lockWidget = nullptr;
int correctlyLoaderRetries = 4;
- QStringList m_dictionaries;
+ QStringList dictionaries;
AutoLockEventFilter *autoLockEventFilter = nullptr;
private slots:
@@ -121,7 +121,7 @@ private slots:
void quitApp();
void initRateWidget();
void initThemes();
- void handleZoomOnWindowStateChange(QWindowStateChangeEvent *ev);
+ void handleZoomOnWindowStateChange(const QWindowStateChangeEvent *ev);
void handleZoom();
void changeLockPassword();
void forceLogOut();
@@ -129,13 +129,8 @@ private slots:
bool isLoggedIn();
void initAutoLock();
void appAutoLockChanged();
- void injectNewChatJavaScript();
void triggerNewChat(QString phone, QString text);
void restoreMainWindow();
- void injectFullWidthJavaScript();
- void injectMutationObserver();
- void injectClassChangeObserver();
- void injectPreventScrollWheelZoomHelper();
};
#endif // MAINWINDOW_H
diff --git a/src/SunClock.cpp b/src/sunclock.cpp
index 132c0a6..29400f1 100644
--- a/src/SunClock.cpp
+++ b/src/sunclock.cpp
@@ -1,4 +1,4 @@
-#include <SunClock.hpp>
+#include <sunclock.hpp>
#include <cmath>
#include <stdexcept>
diff --git a/src/SunClock.hpp b/src/sunclock.hpp
index 4cfad57..4cfad57 100644
--- a/src/SunClock.hpp
+++ b/src/sunclock.hpp
diff --git a/src/webenginepage.cpp b/src/webenginepage.cpp
index 6cd5f44..849895e 100644
--- a/src/webenginepage.cpp
+++ b/src/webenginepage.cpp
@@ -116,7 +116,7 @@ void WebEnginePage::handleFeaturePermissionRequested(const QUrl &securityOrigin,
}
void WebEnginePage::handleLoadFinished(bool ok) {
- Q_UNUSED(ok);
+
// turn on Notification settings by default
if (settings.value("permissions/Notifications").isValid() == false) {
settings.beginGroup("permissions");
@@ -132,6 +132,14 @@ void WebEnginePage::handleLoadFinished(bool ok) {
QWebEnginePage::Feature::Notifications,
QWebEnginePage::PermissionPolicy::PermissionGrantedByUser);
}
+
+ if (ok) {
+ injectMutationObserver();
+ injectPreventScrollWheelZoomHelper();
+ injectFullWidthJavaScript();
+ injectClassChangeObserver();
+ injectNewChatJavaScript();
+ }
}
void WebEnginePage::fullScreenRequestedByPage(
@@ -301,3 +309,106 @@ void WebEnginePage::javaScriptConsoleMessage(
Q_UNUSED(lineId);
Q_UNUSED(sourceId);
}
+
+void WebEnginePage::injectPreventScrollWheelZoomHelper() {
+ QString js = R"(
+ (function () {
+ const SSWZ = function () {
+ this.keyScrollHandler = function (e) {
+ if (e.ctrlKey) {
+ e.preventDefault();
+ return false;
+ }
+ }
+ };
+ if (window === top) {
+ const sswz = new SSWZ();
+ window.addEventListener('wheel', sswz.keyScrollHandler, {
+ passive: false
+ });
+ }
+ })();
+ )";
+ this->runJavaScript(js);
+}
+
+void WebEnginePage::injectClassChangeObserver() {
+ QString js = R"(
+ const observer = new MutationObserver(() => {
+ var haveFullView = document.body.classList.contains('whatsie-full-view');
+ var container = document.querySelector('#app > .app-wrapper-web > div');
+ if(container){
+ if(haveFullView){
+ container.style.width = '100%';
+ container.style.height = '100%';
+ container.style.top = '0';
+ container.style.maxWidth = 'unset';
+ }else{
+ container.style.width = null;
+ container.style.height = null;
+ container.style.top = null;
+ container.style.maxWidth = null;
+ }
+ }
+ });
+ observer.observe(document.body, {
+ attributes: true,
+ attributeFilter: ['class'],
+ childList: false,
+ characterData: false
+ });)";
+ this->runJavaScript(js);
+}
+
+void WebEnginePage::injectMutationObserver() {
+ QString js =
+ R"(function waitForElement(selector) {
+ return new Promise(resolve => {
+ if (document.querySelector(selector)) {
+ return resolve(document.querySelector(selector));
+ }
+ const observer = new MutationObserver(mutations => {
+ if (document.querySelector(selector)) {
+ resolve(document.querySelector(selector));
+ observer.disconnect();
+ }
+ });
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+ });
+ };)";
+ this->runJavaScript(js);
+}
+
+void WebEnginePage::injectFullWidthJavaScript() {
+ if (!settings.value("fullWidthView", true).toBool())
+ return;
+ QString js =
+ R"(waitForElement('#pane-side').then( () => {
+ var container = document.querySelector('#app > .app-wrapper-web > div');
+ container.style.width = '100%';
+ container.style.height = '100%';
+ container.style.top = '0';
+ container.style.maxWidth = 'unset';
+ });
+ )";
+ this->runJavaScript(js);
+}
+
+void WebEnginePage::injectNewChatJavaScript() {
+ QString js = R"(const openNewChatWhatsie = (phone,text) => {
+ const link = document.createElement('a');
+ link.setAttribute('href',
+ `whatsapp://send/?phone=${phone}&text=${text}`);
+ document.body.append(link);
+ link.click();
+ document.body.removeChild(link);
+ };
+ function openNewChatWhatsieDefined()
+ {
+ return (openNewChatWhatsie != 'undefined');
+ })";
+ this->runJavaScript(js);
+}
diff --git a/src/webenginepage.h b/src/webenginepage.h
index e2684f3..d039288 100644
--- a/src/webenginepage.h
+++ b/src/webenginepage.h
@@ -61,6 +61,11 @@ private slots:
QWebEngineClientCertificateSelection clientCertSelection);
#endif
void fullScreenRequestedByPage(QWebEngineFullScreenRequest request);
+ void injectPreventScrollWheelZoomHelper();
+ void injectClassChangeObserver();
+ void injectMutationObserver();
+ void injectFullWidthJavaScript();
+ void injectNewChatJavaScript();
};
#endif // WEBENGINEPAGE_H
diff --git a/src/webview.cpp b/src/webview.cpp
index cfd9af9..8029ffd 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -8,7 +8,7 @@
WebView::WebView(QWidget *parent, QStringList dictionaries)
: QWebEngineView(parent) {
- m_dictionaries = dictionaries;
+ dictionaries = dictionaries;
QObject *parentMainWindow = this->parent();
while (!parentMainWindow->objectName().contains("MainWindow")) {
@@ -49,18 +49,23 @@ WebView::WebView(QWidget *parent, QStringList dictionaries)
}
void WebView::wheelEvent(QWheelEvent *event) {
- if (event->modifiers().testFlag(Qt::ControlModifier)) {
+ bool controlKeyIsHeld =
+ QGuiApplication::keyboardModifiers().testFlag(Qt::ControlModifier);
+ // this doesn't work, (even after checking the global QApplication keyboard
+ // modifiers) as expected, the Ctrl+wheel is managed by Chromium
+ // WebenginePage directly. So, we manage it by injecting js to page using
+ // WebEnginePage::injectPreventScrollWheelZoomHelper
+ if ((event->modifiers() & Qt::ControlModifier) != 0 || controlKeyIsHeld) {
qDebug() << "skipped ctrl + m_wheel event on webengineview";
- // do nothing
+ event->ignore();
} else {
- qDebug() << "wheel event on webengine view";
QWebEngineView::wheelEvent(event);
}
}
void WebView::contextMenuEvent(QContextMenuEvent *event) {
- QMenu *menu = page()->createStandardContextMenu();
+ auto menu = page()->createStandardContextMenu();
menu->setAttribute(Qt::WA_DeleteOnClose, true);
// hide reload, back, forward, savepage, copyimagelink menus
foreach (auto *action, menu->actions()) {
@@ -87,29 +92,27 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) {
return;
}
- QWebEngineProfile *profile = page()->profile();
- const QStringList &languages = profile->spellCheckLanguages();
-
+ auto pageWebengineProfile = page()->profile();
+ const QStringList &languages = pageWebengineProfile->spellCheckLanguages();
menu->addSeparator();
-
- QAction *spellcheckAction = new QAction(tr("Check Spelling"), menu);
+ auto *spellcheckAction = new QAction(tr("Check Spelling"), menu);
spellcheckAction->setCheckable(true);
- spellcheckAction->setChecked(profile->isSpellCheckEnabled());
+ spellcheckAction->setChecked(pageWebengineProfile->isSpellCheckEnabled());
connect(spellcheckAction, &QAction::toggled, this,
- [profile, this](bool toogled) {
- profile->setSpellCheckEnabled(toogled);
+ [pageWebengineProfile, this](bool toogled) {
+ pageWebengineProfile->setSpellCheckEnabled(toogled);
settings.setValue("sc_enabled", toogled);
});
menu->addAction(spellcheckAction);
- if (profile->isSpellCheckEnabled()) {
- QMenu *subMenu = menu->addMenu(tr("Select Language"));
- for (const QString &dict : qAsConst(m_dictionaries)) {
- QAction *action = subMenu->addAction(dict);
+ if (pageWebengineProfile->isSpellCheckEnabled()) {
+ auto subMenu = menu->addMenu(tr("Select Language"));
+ for (const QString &dict : qAsConst(dictionaries)) {
+ auto action = subMenu->addAction(dict);
action->setCheckable(true);
action->setChecked(languages.contains(dict));
- connect(action, &QAction::triggered, this, [profile, dict, this]() {
- profile->setSpellCheckLanguages(QStringList() << dict);
+ connect(action, &QAction::triggered, this, [pageWebengineProfile, dict, this]() {
+ pageWebengineProfile->setSpellCheckLanguages(QStringList() << dict);
settings.setValue("sc_dict", dict);
});
}
diff --git a/src/webview.h b/src/webview.h
index 81f5f43..e03fa49 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -18,7 +18,7 @@ protected slots:
void wheelEvent(QWheelEvent *event);
private:
- QStringList m_dictionaries;
+ QStringList dictionaries;
QSettings settings;
};
diff --git a/src/elidedlabel.cpp b/src/widgets/elidedlabel/elidedlabel.cpp
index e870959..e870959 100644
--- a/src/elidedlabel.cpp
+++ b/src/widgets/elidedlabel/elidedlabel.cpp
diff --git a/src/elidedlabel.h b/src/widgets/elidedlabel/elidedlabel.h
index 7dc610a..7dc610a 100644
--- a/src/elidedlabel.h
+++ b/src/widgets/elidedlabel/elidedlabel.h