fixed: service process was being stopped when gui exited and in other scenarios.

This commit is contained in:
Nick Bolton 2012-07-28 22:13:14 +00:00
parent 24e2feab5f
commit a26e6886ba
2 changed files with 50 additions and 30 deletions

View File

@ -97,14 +97,18 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
stopSynergy(); if (appConfig().processMode() == Desktop)
{
stopDesktop();
}
saveSettings(); saveSettings();
delete m_SetupWizard; delete m_SetupWizard;
} }
void MainWindow::start(bool firstRun) void MainWindow::start(bool firstRun)
{ {
onModeChanged(firstRun, false); onModeChanged(!firstRun && appConfig().autoConnect(), false);
createTrayIcon(); createTrayIcon();
@ -116,15 +120,13 @@ void MainWindow::start(bool firstRun)
void MainWindow::wizardFinished() void MainWindow::wizardFinished()
{ {
onModeChanged(false, true); onModeChanged(true, true);
} }
void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply) void MainWindow::onModeChanged(bool startDesktop, bool applyService)
{ {
refreshApplyButton(); refreshApplyButton();
stopSynergy();
if (appConfig().processMode() == Service) if (appConfig().processMode() == Service)
{ {
// ensure that the apply button actually does something, since desktop // ensure that the apply button actually does something, since desktop
@ -132,19 +134,15 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply)
disconnect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); disconnect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger()));
connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger())); connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger()));
if (forceServiceApply) if (applyService)
{ {
stopDesktop();
startSynergy(); startSynergy();
} }
} }
else else if ((appConfig().processMode() == Desktop) && startDesktop)
{
// cause the service to stop creating processes.
m_IpcClient.sendCommand("", false);
}
if ((appConfig().processMode() == Desktop) && !firstRun && appConfig().autoConnect())
{ {
stopService();
startSynergy(); startSynergy();
} }
@ -567,18 +565,13 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
void MainWindow::stopSynergy() void MainWindow::stopSynergy()
{ {
if (appConfig().processMode() == Service) { if (appConfig().processMode() == Service)
// send empty command to stop service from laucning anything.
m_IpcClient.sendCommand("", m_ElevateProcess);
}
else if (synergyProcess())
{ {
appendLogNote("stopping synergy"); stopService();
}
if (synergyProcess()->isOpen()) else if (appConfig().processMode() == Desktop)
synergyProcess()->close(); {
delete synergyProcess(); stopDesktop();
setSynergyProcess(NULL);
} }
setSynergyState(synergyDisconnected); setSynergyState(synergyDisconnected);
@ -592,6 +585,27 @@ void MainWindow::stopSynergy()
m_alreadyHidden = false; m_alreadyHidden = false;
} }
void MainWindow::stopService()
{
// send empty command to stop service from laucning anything.
m_IpcClient.sendCommand("", m_ElevateProcess);
}
void MainWindow::stopDesktop()
{
if (!synergyProcess()) {
return;
}
appendLogNote("stopping synergy desktop process");
if (synergyProcess()->isOpen())
synergyProcess()->close();
delete synergyProcess();
setSynergyProcess(NULL);
}
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. // on Windows, we always seem to have an exit code != 0.
@ -629,10 +643,14 @@ void MainWindow::setSynergyState(qSynergyState state)
m_pButtonToggleStart->setText(tr("&Start")); m_pButtonToggleStart->setText(tr("&Start"));
} }
m_pGroupClient->setEnabled(state == synergyDisconnected); // only disable controls in desktop mode. in service mode, we can use the apply button.
m_pGroupServer->setEnabled(state == synergyDisconnected); if (appConfig().processMode() == Desktop)
m_pActionStartSynergy->setEnabled(state == synergyDisconnected); {
m_pActionStopSynergy->setEnabled(state == synergyConnected); m_pGroupClient->setEnabled(state == synergyDisconnected);
m_pGroupServer->setEnabled(state == synergyDisconnected);
m_pActionStartSynergy->setEnabled(state == synergyDisconnected);
m_pActionStopSynergy->setEnabled(state == synergyConnected);
}
switch (state) switch (state)
{ {

View File

@ -134,10 +134,12 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
bool serverArgs(QStringList& args, QString& app); bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status); void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors); void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void onModeChanged(bool firstRun, bool forceServiceApply); void onModeChanged(bool startDesktop, bool applyService);
void updateStateFromLogLine(const QString& line); void updateStateFromLogLine(const QString& line);
QString getIPAddresses(); QString getIPAddresses();
QString getScreenName(); QString getScreenName();
void stopService();
void stopDesktop();
private: private:
QSettings& m_Settings; QSettings& m_Settings;