UI: Restart when needed.

This commit is contained in:
Nodir Temirkhodjaev 2021-04-03 12:21:42 +03:00
parent 033e253e01
commit c94fe31da8
7 changed files with 29 additions and 22 deletions

View File

@ -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
}

View File

@ -40,8 +40,6 @@ private:
void setupNewVersionBox();
void setupNewVersionUpdate();
void processRestartRequired();
private:
uint m_iniEdited : 1;
uint m_currentStartMode : 4;

View File

@ -5,6 +5,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
#include <QProcess>
#include <QStyle>
#include <QStyleFactory>
#include <QSystemTrayIcon>
@ -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)

View File

@ -109,6 +109,8 @@ public slots:
void showConnectionsWindow();
void closeConnectionsWindow();
void processRestartRequired();
void exit(int retcode = 0);
bool checkPassword();

View File

@ -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()

View File

@ -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;

View File

@ -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();