aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp50
-rw-r--r--src/mainwindow.h3
2 files changed, 50 insertions, 3 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b9ec4f5..1893448 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -199,6 +199,42 @@ void MainWindow::handleCookieAdded(const QNetworkCookie &cookie) {
qDebug() << cookie.toRawForm() << "\n\n\n";
}
+void MainWindow::forceLogOut() {
+ if (webEngine && webEngine->page()) {
+ webEngine->page()->runJavaScript(
+ "window.localStorage.clear();",
+ [=](const QVariant &result) { qDebug() << result; });
+ }
+}
+
+bool MainWindow::isLoggedIn(){
+ static bool loggedIn = false;
+ if (webEngine && webEngine->page()) {
+ webEngine->page()->runJavaScript(
+ "window.localStorage.getItem('WAToken2')",
+ [=](const QVariant &result) { qDebug() <<Q_FUNC_INFO << result;
+ if(result.isValid() && result.toString().isEmpty() == false){
+ loggedIn = true;
+ }
+ });
+ qDebug() << "isLoggedIn" <<loggedIn;
+ return loggedIn;
+ }else{
+ qDebug() << "isLoggedIn" <<loggedIn;
+ return loggedIn;
+ }
+}
+
+void MainWindow::tryLogOut() {
+ if (webEngine && webEngine->page()) {
+ webEngine->page()->runJavaScript(
+ "document.querySelector(\"span[data-testid|='menu']\").click();"
+ "document.querySelector(\"#side > header > div > div > span > div > "
+ "span > div > ul > li:nth-child(5) > div\").click()",
+ [=](const QVariant &result) { qDebug() << Q_FUNC_INFO << result; });
+ }
+}
+
void MainWindow::init_settingWidget() {
if (settingsWidget == nullptr) {
settingsWidget = new SettingsWidget(
@@ -597,9 +633,17 @@ void MainWindow::init_lock() {
void MainWindow::change_lock_password() {
settings.remove("asdfg");
settingsWidget->appLockSetChecked(false);
- settingsWidget->clearAllData();
- doAppReload();
- init_lock();
+
+ tryLogOut();
+ QTimer::singleShot(2000, this, [=]() {
+ if(isLoggedIn()){
+ forceLogOut();
+ doAppReload();
+ }
+ init_lock();
+ });
+
+
}
// check window state and set tray menus
diff --git a/src/mainwindow.h b/src/mainwindow.h
index e1298b0..1f966bd 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -118,6 +118,9 @@ private slots:
void handleZoom();
void change_lock_password();
void tryLock();
+ void forceLogOut();
+ void tryLogOut();
+ bool isLoggedIn();
};
#endif // MAINWINDOW_H