diff options
author | 2022-05-10 17:34:33 +0530 | |
---|---|---|
committer | 2022-05-10 17:34:33 +0530 | |
commit | 391171583a00d04b3f2fcfb57b9c9743ae286728 (patch) | |
tree | 393876014ff06371bdff7acabe97b3eb6fc86afc /src | |
parent | 1d950cd8bd6fbe3ad7dde1f78fd984dff6d7d25d (diff) | |
download | whatsie-391171583a00d04b3f2fcfb57b9c9743ae286728.tar.gz whatsie-391171583a00d04b3f2fcfb57b9c9743ae286728.zip |
chore: restore window directly when another instance is launched
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 56 | ||||
-rw-r--r-- | src/mainwindow.h | 2 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0303f3a..db07711 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) { "whatsapp://" + messageStr.split("whatsapp://").last(); window.loadAppWithArgument(urlStr); } else { - window.alreadyRunning(); + window.alreadyRunning(true); } }); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 23bfb44..13bfe5f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -146,7 +146,7 @@ void MainWindow::loadAppWithArgument(const QString &arg) { newArg = newArg.replace("?", "&"); QUrlQuery query(newArg); - QString phone, text; + QString phone, text; phone = query.queryItemValue("phone"); text = query.queryItemValue("text"); triggerNewChat(phone, text); @@ -188,9 +188,7 @@ void MainWindow::updateWindowTheme() { } QList<QWidget *> widgets = this->findChildren<QWidget *>(); - foreach (QWidget *w, widgets) { - w->setPalette(qApp->palette()); - } + foreach (QWidget *w, widgets) { w->setPalette(qApp->palette()); } setNotificationPresenter(webEngine->page()->profile()); if (lockWidget != nullptr) { @@ -549,7 +547,6 @@ void MainWindow::quitApp() { settings.setValue("geometry", saveGeometry()); getPageTheme(); QTimer::singleShot(500, &settings, [=]() { - qWarning() << "THEME" << settings.value("windowTheme").toString(); settings.setValue("firstrun_tray", true); qApp->quit(); }); @@ -1021,25 +1018,24 @@ void MainWindow::newChat() { } } -void MainWindow::triggerNewChat(QString phone, QString text){ - static QString phoneStr, textStr; - webEngine->page()->runJavaScript( - "openNewChatWhatsieDefined()", [this, phone, text](const QVariant &result) { - if (result.toString().contains("true")) { - this->webEngine->page()->runJavaScript( - QString("openNewChatWhatsie(\"%1\",\"%2\")").arg(phone, text)); - this->notify(QApplication::applicationName(), - "New chat with " + phone + - " is ready. Click to Open."); - } else { - // create send url equivalent - phoneStr = phone.isEmpty() ? "" : "phone=" + phone; - textStr = text.isEmpty() ? "" : "text=" + text; - QString urlStr = - "https://web.whatsapp.com/send?" + phoneStr + "&" + textStr; - this->webEngine->page()->load(QUrl(urlStr)); - } - }); +void MainWindow::triggerNewChat(QString phone, QString text) { + static QString phoneStr, textStr; + webEngine->page()->runJavaScript( + "openNewChatWhatsieDefined()", + [this, phone, text](const QVariant &result) { + if (result.toString().contains("true")) { + this->webEngine->page()->runJavaScript( + QString("openNewChatWhatsie(\"%1\",\"%2\")").arg(phone, text)); + } else { + // create send url equivalent + phoneStr = phone.isEmpty() ? "" : "phone=" + phone; + textStr = text.isEmpty() ? "" : "text=" + text; + QString urlStr = + "https://web.whatsapp.com/send?" + phoneStr + "&" + textStr; + this->webEngine->page()->load(QUrl(urlStr)); + } + this->alreadyRunning(); + }); } bool MainWindow::isPhoneNumber(const QString &phoneNumber) { @@ -1085,10 +1081,10 @@ void MainWindow::tryLock() { } } -void MainWindow::alreadyRunning() { - QString appname = QApplication::applicationName(); - this->notify( - appname, - QString("An instance of %1 is already Running, click to restore.") - .arg(appname)); +void MainWindow::alreadyRunning(bool notify) { + this->show(); + if (notify) { + QString appname = QApplication::applicationName(); + this->notify(appname, "Restored an already running instance."); + } } diff --git a/src/mainwindow.h b/src/mainwindow.h index c925697..2c580b6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -50,7 +50,7 @@ public slots: void handleDownloadRequested(QWebEngineDownloadItem *download); void loadAppWithArgument(const QString &arg); void runMinimized(); - void alreadyRunning(); + void alreadyRunning(bool notify = false); protected slots: void closeEvent(QCloseEvent *event) override; void resizeEvent(QResizeEvent *event) override; |