aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2023-01-26 20:25:34 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2023-01-26 20:25:34 +0530
commitf31197a4ef9c49a5658d283011455832d0bf9038 (patch)
tree1020bb1debf53119890f71c72c3fc5fbce0662ef
parent32b0e5ca1f64f5d5329be2dab69a035063b03ae4 (diff)
downloadwhatsie-f31197a4ef9c49a5658d283011455832d0bf9038.tar.gz
whatsie-f31197a4ef9c49a5658d283011455832d0bf9038.zip
chore: cleanup + inhancements
- clean lock screen logic - fix: utilise page localstorage to persist & restore theme state
-rw-r--r--src/mainwindow.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index cd28707..a238b96 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -172,12 +172,18 @@ void MainWindow::loadSchemaUrl(const QString &arg) {
void MainWindow::updatePageTheme() {
if (webEngine && webEngine->page()) {
- QString webPageTheme = "web";
+
QString windowTheme = settings.value("windowTheme", "light").toString();
+
+ if(windowTheme == "dark"){
+ webEngine->page()->runJavaScript("localStorage['system-theme-mode']='false'; localStorage.theme='\"dark\"'; ");
+ }else{
+ webEngine->page()->runJavaScript("localStorage['system-theme-mode']='false'; localStorage.theme='\"light\"'; ");
+ }
+
if (windowTheme == "dark") {
- webPageTheme = "dark";
webEngine->page()->runJavaScript(
- "document.querySelector('body').classList.add('" + webPageTheme +
+ "document.querySelector('body').classList.add('" + windowTheme +
"');");
} else {
webEngine->page()->runJavaScript(
@@ -952,6 +958,7 @@ void MainWindow::handleWebViewTitleChanged(QString title) {
void MainWindow::handleLoadFinished(bool loaded) {
if (loaded) {
+ qDebug()<<"Loaded";
checkLoadedCorrectly();
updatePageTheme();
handleZoom();
@@ -970,16 +977,18 @@ void MainWindow::injectClassChangeObserver() {
const observer = new MutationObserver(() => {
var haveFullView = document.body.classList.contains('whatsie-full-view');
var container = document.querySelector('#app > .app-wrapper-web > div');
- 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;
+ 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, {
@@ -1009,7 +1018,7 @@ void MainWindow::injectMutationObserver() {
subtree: true
});
});
- })";
+ };)";
webEngine->page()->runJavaScript(js);
}
@@ -1220,8 +1229,7 @@ QString MainWindow::getPageTheme() {
}
void MainWindow::tryLock() {
- if (settings.value("asdfg").isValid() &&
- settings.value("lockscreen", false).toBool()) {
+ if (settings.value("asdfg").isValid()) {
initLock();
return;
}