Fixed auto restart sometimes cause GUI crash #4901

This commit is contained in:
Xinyu Hou 2015-07-29 14:34:21 -07:00 committed by Jerry (Xinyu Hou)
parent 94664e413b
commit 67fbecb825
2 changed files with 25 additions and 42 deletions

View File

@ -493,11 +493,8 @@ void MainWindow::startSynergy()
bool desktopMode = appConfig().processMode() == Desktop;
bool serviceMode = appConfig().processMode() == Service;
if (desktopMode)
{
stopSynergy();
}
appendLogDebug("starting process");
m_ExpectedRunningState = kStarted;
setSynergyState(synergyConnecting);
QString app;
@ -587,7 +584,6 @@ void MainWindow::startSynergy()
synergyProcess()->start(app, args);
if (!synergyProcess()->waitForStarted())
{
stopSynergy();
show();
QMessageBox::warning(this, tr("Program can not be started"), QString(tr("The executable<br><br>%1<br><br>could not be successfully started, although it does exist. Please check if you have sufficient permissions to run this program.").arg(app)));
return;
@ -729,6 +725,10 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
void MainWindow::stopSynergy()
{
appendLogDebug("stopping process");
m_ExpectedRunningState = kStopped;
if (appConfig().processMode() == Service)
{
stopService();
@ -757,6 +757,7 @@ void MainWindow::stopService()
void MainWindow::stopDesktop()
{
QMutexLocker locker(&m_StopDesktopMutex);
if (!synergyProcess()) {
return;
}
@ -772,27 +773,21 @@ void MainWindow::stopDesktop()
void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus)
{
// on Windows, we always seem to have an exit code != 0.
#if !defined(Q_OS_WIN)
if (exitCode != 0)
{
QMessageBox::critical(this, tr("Synergy terminated with an error"), QString(tr("Synergy terminated unexpectedly with an exit code of %1.<br><br>Please see the log output for details.")).arg(exitCode));
stopSynergy();
if (exitCode == 0) {
appendLogInfo(QString("process exited normally"));
}
else {
appendLogError(QString("process exited with error code: %1").arg(exitCode));
}
if (appConfig().processMode() == Desktop) {
if (m_ExpectedRunningState == kStarted) {
stopSynergy();
delay(1);
startSynergy();
}
if (m_ExpectedRunningState == kStarted) {
delay(1);
appendLogInfo(QString("detected process not running, auto restarting"));
startSynergy();
}
else {
setSynergyState(synergyDisconnected);
}
#else
Q_UNUSED(exitCode);
#endif
setSynergyState(synergyDisconnected);
}
void MainWindow::setSynergyState(qSynergyState state)
@ -834,7 +829,6 @@ void MainWindow::setSynergyState(qSynergyState state)
}
setStatus(tr("Synergy is running."));
m_ExpectedRunningState = kStarted;
break;
}
@ -1350,14 +1344,3 @@ void MainWindow::delay(unsigned int s)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
}
void MainWindow::on_m_pButtonToggleStart_clicked()
{
if (m_SynergyState != synergyConnected) {
m_ExpectedRunningState = kStarted;
}
else {
m_ExpectedRunningState = kStopped;
}
}

View File

@ -206,13 +206,13 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
CommandProcess* m_BonjourInstall;
bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pButtonApply_clicked();
void installBonjour();
void on_m_pButtonToggleStart_clicked();
};
#endif