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 desktopMode = appConfig().processMode() == Desktop;
bool serviceMode = appConfig().processMode() == Service; bool serviceMode = appConfig().processMode() == Service;
if (desktopMode) appendLogDebug("starting process");
{ m_ExpectedRunningState = kStarted;
stopSynergy();
}
setSynergyState(synergyConnecting); setSynergyState(synergyConnecting);
QString app; QString app;
@ -587,7 +584,6 @@ void MainWindow::startSynergy()
synergyProcess()->start(app, args); synergyProcess()->start(app, args);
if (!synergyProcess()->waitForStarted()) if (!synergyProcess()->waitForStarted())
{ {
stopSynergy();
show(); 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))); 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; return;
@ -729,6 +725,10 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
void MainWindow::stopSynergy() void MainWindow::stopSynergy()
{ {
appendLogDebug("stopping process");
m_ExpectedRunningState = kStopped;
if (appConfig().processMode() == Service) if (appConfig().processMode() == Service)
{ {
stopService(); stopService();
@ -757,6 +757,7 @@ void MainWindow::stopService()
void MainWindow::stopDesktop() void MainWindow::stopDesktop()
{ {
QMutexLocker locker(&m_StopDesktopMutex);
if (!synergyProcess()) { if (!synergyProcess()) {
return; return;
} }
@ -772,27 +773,21 @@ void MainWindow::stopDesktop()
void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus) void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus)
{ {
// on Windows, we always seem to have an exit code != 0. if (exitCode == 0) {
#if !defined(Q_OS_WIN) appendLogInfo(QString("process exited normally"));
if (exitCode != 0) }
{ else {
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)); appendLogError(QString("process exited with error code: %1").arg(exitCode));
stopSynergy();
} }
if (appConfig().processMode() == Desktop) {
if (m_ExpectedRunningState == kStarted) { if (m_ExpectedRunningState == kStarted) {
stopSynergy();
delay(1); delay(1);
appendLogInfo(QString("detected process not running, auto restarting"));
startSynergy(); startSynergy();
} }
} else {
#else
Q_UNUSED(exitCode);
#endif
setSynergyState(synergyDisconnected); setSynergyState(synergyDisconnected);
}
} }
void MainWindow::setSynergyState(qSynergyState state) void MainWindow::setSynergyState(qSynergyState state)
@ -834,7 +829,6 @@ void MainWindow::setSynergyState(qSynergyState state)
} }
setStatus(tr("Synergy is running.")); setStatus(tr("Synergy is running."));
m_ExpectedRunningState = kStarted;
break; break;
} }
@ -1350,14 +1344,3 @@ void MainWindow::delay(unsigned int s)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); 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; CommandProcess* m_BonjourInstall;
bool m_SuppressEmptyServerWarning; bool m_SuppressEmptyServerWarning;
qRuningState m_ExpectedRunningState; qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
private slots: private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked); void on_m_pCheckBoxAutoConfig_toggled(bool checked);
void on_m_pComboServerList_currentIndexChanged(QString ); void on_m_pComboServerList_currentIndexChanged(QString );
void on_m_pButtonApply_clicked(); void on_m_pButtonApply_clicked();
void installBonjour(); void installBonjour();
void on_m_pButtonToggleStart_clicked();
}; };
#endif #endif