made switching between desktop and service mode more robust.
This commit is contained in:
parent
aec76ce083
commit
db3ea4ab9c
|
@ -24,7 +24,8 @@
|
||||||
#include "Ipc.h"
|
#include "Ipc.h"
|
||||||
|
|
||||||
IpcClient::IpcClient() :
|
IpcClient::IpcClient() :
|
||||||
m_ReaderStarted(false)
|
m_ReaderStarted(false),
|
||||||
|
m_Enabled(false)
|
||||||
{
|
{
|
||||||
m_Socket = new QTcpSocket(this);
|
m_Socket = new QTcpSocket(this);
|
||||||
connect(m_Socket, SIGNAL(connected()), this, SLOT(connected()));
|
connect(m_Socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||||
|
@ -49,6 +50,8 @@ void IpcClient::connected()
|
||||||
|
|
||||||
void IpcClient::connectToHost()
|
void IpcClient::connectToHost()
|
||||||
{
|
{
|
||||||
|
m_Enabled = true;
|
||||||
|
|
||||||
infoMessage("connecting to service...");
|
infoMessage("connecting to service...");
|
||||||
m_Socket->connectToHost(QHostAddress(QHostAddress::LocalHost), IPC_PORT);
|
m_Socket->connectToHost(QHostAddress(QHostAddress::LocalHost), IPC_PORT);
|
||||||
|
|
||||||
|
@ -58,6 +61,13 @@ void IpcClient::connectToHost()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IpcClient::disconnectFromHost()
|
||||||
|
{
|
||||||
|
infoMessage("service disconnect");
|
||||||
|
m_Reader->stop();
|
||||||
|
m_Socket->close();
|
||||||
|
}
|
||||||
|
|
||||||
void IpcClient::error(QAbstractSocket::SocketError error)
|
void IpcClient::error(QAbstractSocket::SocketError error)
|
||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
|
@ -69,7 +79,14 @@ void IpcClient::error(QAbstractSocket::SocketError error)
|
||||||
|
|
||||||
errorMessage(QString("ipc connection error, %1").arg(text));
|
errorMessage(QString("ipc connection error, %1").arg(text));
|
||||||
|
|
||||||
QTimer::singleShot(1000, this, SLOT(connectToHost()));
|
QTimer::singleShot(1000, this, SLOT(retryConnect()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcClient::retryConnect()
|
||||||
|
{
|
||||||
|
if (m_Enabled) {
|
||||||
|
connectToHost();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IpcClient::write(int code, int length, const char* data)
|
void IpcClient::write(int code, int length, const char* data)
|
||||||
|
|
|
@ -32,9 +32,11 @@ public:
|
||||||
virtual ~IpcClient();
|
virtual ~IpcClient();
|
||||||
|
|
||||||
void write(int code, int length, const char* data);
|
void write(int code, int length, const char* data);
|
||||||
|
void connectToHost();
|
||||||
|
void disconnectFromHost();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void connectToHost();
|
void retryConnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void intToBytes(int value, char* buffer, int size);
|
void intToBytes(int value, char* buffer, int size);
|
||||||
|
@ -53,4 +55,5 @@ private:
|
||||||
QTcpSocket* m_Socket;
|
QTcpSocket* m_Socket;
|
||||||
IpcReader* m_Reader;
|
IpcReader* m_Reader;
|
||||||
bool m_ReaderStarted;
|
bool m_ReaderStarted;
|
||||||
|
bool m_Enabled;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,6 +36,11 @@ void IpcReader::start()
|
||||||
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
|
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IpcReader::stop()
|
||||||
|
{
|
||||||
|
disconnect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
|
||||||
|
}
|
||||||
|
|
||||||
void IpcReader::read()
|
void IpcReader::read()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_Mutex);
|
QMutexLocker locker(&m_Mutex);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
IpcReader(QTcpSocket* socket);
|
IpcReader(QTcpSocket* socket);
|
||||||
virtual ~IpcReader();
|
virtual ~IpcReader();
|
||||||
void start();
|
void start();
|
||||||
|
void stop();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void readLogLine(const QString& text);
|
void readLogLine(const QString& text);
|
||||||
|
|
|
@ -77,7 +77,13 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
|
||||||
m_versionChecker.setApp(appPath(appConfig.synergycName()));
|
m_versionChecker.setApp(appPath(appConfig.synergycName()));
|
||||||
|
|
||||||
m_SetupWizard = new SetupWizard(*this, false);
|
m_SetupWizard = new SetupWizard(*this, false);
|
||||||
connect(m_SetupWizard, SIGNAL(finished(int)), this, SLOT(refreshStartButton()));
|
connect(m_SetupWizard, SIGNAL(finished(int)), this, SLOT(onModeChanged()));
|
||||||
|
|
||||||
|
// ipc must always be enabled, so that we can disable command when switching to desktop mode.
|
||||||
|
connect(&m_IpcClient, SIGNAL(readLogLine(const QString&)), this, SLOT(appendLogRaw(const QString&)));
|
||||||
|
connect(&m_IpcClient, SIGNAL(errorMessage(const QString&)), this, SLOT(appendLogError(const QString&)));
|
||||||
|
connect(&m_IpcClient, SIGNAL(infoMessage(const QString&)), this, SLOT(appendLogInfo(const QString&)));
|
||||||
|
m_IpcClient.connectToHost();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -89,21 +95,7 @@ MainWindow::~MainWindow()
|
||||||
|
|
||||||
void MainWindow::start(bool firstRun)
|
void MainWindow::start(bool firstRun)
|
||||||
{
|
{
|
||||||
refreshStartButton();
|
onModeChanged(firstRun);
|
||||||
|
|
||||||
if (appConfig().processMode() == Service)
|
|
||||||
{
|
|
||||||
connect(&m_IpcClient, SIGNAL(readLogLine(const QString&)), this, SLOT(appendLogRaw(const QString&)));
|
|
||||||
connect(&m_IpcClient, SIGNAL(errorMessage(const QString&)), this, SLOT(appendLogError(const QString&)));
|
|
||||||
connect(&m_IpcClient, SIGNAL(infoMessage(const QString&)), this, SLOT(appendLogInfo(const QString&)));
|
|
||||||
m_IpcClient.connectToHost();
|
|
||||||
startSynergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appConfig().processMode() == Desktop && !firstRun && appConfig().autoConnect())
|
|
||||||
{
|
|
||||||
startSynergy();
|
|
||||||
}
|
|
||||||
|
|
||||||
createTrayIcon();
|
createTrayIcon();
|
||||||
|
|
||||||
|
@ -113,6 +105,33 @@ void MainWindow::start(bool firstRun)
|
||||||
m_versionChecker.checkLatest();
|
m_versionChecker.checkLatest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onModeChanged()
|
||||||
|
{
|
||||||
|
onModeChanged(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onModeChanged(bool firstRun)
|
||||||
|
{
|
||||||
|
refreshStartButton();
|
||||||
|
|
||||||
|
stopSynergy();
|
||||||
|
|
||||||
|
if (appConfig().processMode() == Service)
|
||||||
|
{
|
||||||
|
startSynergy();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// cause the service to stop creating processes.
|
||||||
|
sendDaemonCommand("", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appConfig().processMode() == Desktop && !firstRun && appConfig().autoConnect())
|
||||||
|
{
|
||||||
|
startSynergy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::refreshStartButton()
|
void MainWindow::refreshStartButton()
|
||||||
{
|
{
|
||||||
if (appConfig().processMode() == Service)
|
if (appConfig().processMode() == Service)
|
||||||
|
@ -322,9 +341,6 @@ void MainWindow::startSynergy()
|
||||||
|
|
||||||
if (desktopMode)
|
if (desktopMode)
|
||||||
{
|
{
|
||||||
// cause the service to stop creating processes.
|
|
||||||
sendDaemonCommand("", false);
|
|
||||||
|
|
||||||
stopSynergy();
|
stopSynergy();
|
||||||
setSynergyState(synergyConnecting);
|
setSynergyState(synergyConnecting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
void logError();
|
void logError();
|
||||||
void updateFound(const QString& version);
|
void updateFound(const QString& version);
|
||||||
void refreshStartButton();
|
void refreshStartButton();
|
||||||
|
void onModeChanged();
|
||||||
|
void onModeChanged(bool firstRun);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSettings& settings() { return m_Settings; }
|
QSettings& settings() { return m_Settings; }
|
||||||
|
|
Loading…
Reference in New Issue