diff options
author | 2023-01-27 02:57:48 +0530 | |
---|---|---|
committer | 2023-01-27 10:10:17 +0530 | |
commit | 011db4495d98932cbffa5fc2268ee1a3e2984aa6 (patch) | |
tree | a071bf7c135d254bb7976e022839c49475d7552c | |
parent | 56c55a949854f9dd73b60e353be35bd31407cee0 (diff) | |
download | whatsie-011db4495d98932cbffa5fc2268ee1a3e2984aa6.tar.gz whatsie-011db4495d98932cbffa5fc2268ee1a3e2984aa6.zip |
chore: cleanup
- move methods to page
Diffstat (limited to '')
-rw-r--r-- | src/WhatsApp.pro | 10 | ||||
-rw-r--r-- | src/automatictheme.cpp | 2 | ||||
-rw-r--r-- | src/downloadwidget.h | 2 | ||||
-rw-r--r-- | src/downloadwidget.ui | 3 | ||||
-rw-r--r-- | src/mainwindow.cpp | 147 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-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.cpp | 113 | ||||
-rw-r--r-- | src/webenginepage.h | 5 | ||||
-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 |
12 files changed, 146 insertions, 143 deletions
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/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/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/mainwindow.cpp b/src/mainwindow.cpp index 3d01ba0..ae8fdbe 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -205,11 +205,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 +316,7 @@ void MainWindow::initSettingWidget() { webSettings->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, checked); - this->webEngine->page()->profile()->settings()->setAttribute( + webEngine->page()->profile()->settings()->setAttribute( QWebEngineSettings::PlaybackRequiresUserGesture, checked); }); @@ -357,7 +357,7 @@ void MainWindow::initSettingWidget() { connect(settingsWidget, &SettingsWidget::notificationPopupTimeOutChanged, settingsWidget, [=]() { - setNotificationPresenter(this->webEngine->page()->profile()); + setNotificationPresenter(webEngine->page()->profile()); }); connect(settingsWidget, &SettingsWidget::notify, settingsWidget, @@ -479,7 +479,7 @@ void MainWindow::showSettings(bool isAskedByCLI) { void MainWindow::updateSettingsUserAgentWidget() { settingsWidget->updateDefaultUAButton( - this->webEngine->page()->profile()->httpUserAgent()); + webEngine->page()->profile()->httpUserAgent()); } void MainWindow::askToReloadPage() { @@ -806,16 +806,16 @@ void MainWindow::createWebEngine() { m_dictionaries = Dictionaries::GetDictionaries(); - WebView *webEngine = new WebView(this, m_dictionaries); - setCentralWidget(webEngine); - webEngine->setSizePolicy(widgetSize); - webEngine->show(); + WebView *webEngineView = new WebView(this, m_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); } @@ -964,119 +964,14 @@ 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()) { @@ -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,7 +1107,7 @@ void MainWindow::triggerNewChat(QString phone, QString text) { void MainWindow::doReload(bool byPassCache, bool isAskedByCLI, bool byLoadingQuirk) { if (byLoadingQuirk) { - this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, + webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, byPassCache); } else { if (lockWidget && !lockWidget->getIsLocked()) { @@ -1229,13 +1124,13 @@ void MainWindow::doReload(bool byPassCache, bool isAskedByCLI, this->show(); return; } - this->webEngine->triggerPageAction(QWebEnginePage::ReloadAndBypassCache, + 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..f6346ad 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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..e27d928 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/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 |