From c94fe31da8f424cc46cfe79f453c8beb0bdcd656 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sat, 3 Apr 2021 12:21:42 +0300 Subject: [PATCH] UI: Restart when needed. --- src/ui/form/opt/pages/optionspage.cpp | 10 +--------- src/ui/form/opt/pages/optionspage.h | 2 -- src/ui/fortmanager.cpp | 16 +++++++++++++++- src/ui/fortmanager.h | 2 ++ src/ui/fortsettings.cpp | 8 ++++---- src/ui/fortsettings.h | 11 ++++++----- src/ui/main.cpp | 2 +- 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index 3ab1c9ba..a5f6f481 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -57,7 +57,7 @@ void OptionsPage::onSaved() const bool isServiceMode = StartupUtil::isServiceMode(m_currentStartMode); if (isServiceMode != wasServiceMode) { QMetaObject::invokeMethod( - this, &OptionsPage::processRestartRequired, Qt::QueuedConnection); + fortManager(), &FortManager::processRestartRequired, Qt::QueuedConnection); } } @@ -480,11 +480,3 @@ void OptionsPage::setupNewVersionUpdate() connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged, this, refreshNewVersion); } - -void OptionsPage::processRestartRequired() -{ - if (!fortManager()->showYesNoBox(tr("Restart Required"), tr("Restart Now"), tr("Later"))) - return; - - // TODO: Restart the app with args -} diff --git a/src/ui/form/opt/pages/optionspage.h b/src/ui/form/opt/pages/optionspage.h index 4076cb3b..152cd58c 100644 --- a/src/ui/form/opt/pages/optionspage.h +++ b/src/ui/form/opt/pages/optionspage.h @@ -40,8 +40,6 @@ private: void setupNewVersionBox(); void setupNewVersionUpdate(); - void processRestartRequired(); - private: uint m_iniEdited : 1; uint m_currentStartMode : 4; diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index fac24287..e3988126 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -557,6 +558,19 @@ void FortManager::closeConnectionsWindow() m_connWindow = nullptr; } +void FortManager::processRestartRequired() +{ + if (!showYesNoBox(tr("Restart Required"), tr("Restart Now"), tr("Later"))) + return; + + const QString appFilePath = QCoreApplication::applicationFilePath(); + const QStringList args = settings()->appArguments(); + + connect(this, &QObject::destroyed, [=] { QProcess::startDetached(appFilePath, args); }); + + exit(0); +} + void FortManager::exit(int retcode) { if (!checkPassword()) @@ -620,7 +634,7 @@ bool FortManager::showYesNoBox( box.addButton(yesText, QMessageBox::YesRole); box.addButton(noText, QMessageBox::NoRole); - return box.exec() == QMessageBox::Yes; + return box.exec() == 0; } bool FortManager::saveOriginConf(const QString &message, bool onlyFlags) diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index 8a696e53..4798aa66 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -109,6 +109,8 @@ public slots: void showConnectionsWindow(); void closeConnectionsWindow(); + void processRestartRequired(); + void exit(int retcode = 0); bool checkPassword(); diff --git a/src/ui/fortsettings.cpp b/src/ui/fortsettings.cpp index 829679a4..70ca44f3 100644 --- a/src/ui/fortsettings.cpp +++ b/src/ui/fortsettings.cpp @@ -28,7 +28,7 @@ QString expandPath(const QString &path, EnvManager *envManager = nullptr) } -FortSettings::FortSettings(int argc, char *argv[], QObject *parent) : +FortSettings::FortSettings(QObject *parent) : QObject(parent), m_iniExists(false), m_noCache(false), @@ -36,9 +36,7 @@ FortSettings::FortSettings(int argc, char *argv[], QObject *parent) : m_hasService(false), m_isWindowControl(false), m_bulkUpdating(false), - m_bulkIniChanged(false), - m_argc(argc), - m_argv(argv) + m_bulkIniChanged(false) { } @@ -186,6 +184,8 @@ void FortSettings::processArguments(const QStringList &args, EnvManager *envMana // Other Arguments m_args = parser.positionalArguments(); + + m_appArguments = args.mid(1); } void FortSettings::setupIni() diff --git a/src/ui/fortsettings.h b/src/ui/fortsettings.h index dc3174e4..0c927801 100644 --- a/src/ui/fortsettings.h +++ b/src/ui/fortsettings.h @@ -15,7 +15,7 @@ class FortSettings : public QObject Q_OBJECT public: - explicit FortSettings(int argc = 0, char *argv[] = nullptr, QObject *parent = nullptr); + explicit FortSettings(QObject *parent = nullptr); bool debug() const { return iniBool("base/debug"); } void setDebug(bool on) { setIniValue("base/debug", on); } @@ -219,7 +219,9 @@ public: bool isWindowControl() const { return m_isWindowControl; } QString controlCommand() const { return m_controlCommand; } - QStringList args() const { return m_args; } + const QStringList &args() const { return m_args; } + + const QStringList &appArguments() const { return m_appArguments; } QString errorMessage() const { return m_errorMessage; } @@ -287,9 +289,6 @@ private: bool m_bulkUpdating : 1; bool m_bulkIniChanged : 1; - int m_argc = 0; - char **m_argv = nullptr; - QString m_defaultLanguage; QString m_profilePath; QString m_statPath; @@ -298,6 +297,8 @@ private: QString m_controlCommand; QStringList m_args; + QStringList m_appArguments; + QString m_errorMessage; QSettings *m_ini = nullptr; diff --git a/src/ui/main.cpp b/src/ui/main.cpp index 5706ca59..36c9347d 100644 --- a/src/ui/main.cpp +++ b/src/ui/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) } // Process global settings required before QApplication costruction - FortSettings fortSettings(argc, argv); + FortSettings fortSettings; fortSettings.setHasService(StartupUtil::isServiceInstalled()); fortSettings.setupGlobal();