Skip to content

Commit 901dacf

Browse files
nboltonsithlord48
authored andcommitted
feat(daemon): Friendly message on daemon connection error
1 parent c62b4ec commit 901dacf

8 files changed

Lines changed: 86 additions & 28 deletions

File tree

src/lib/gui/MainWindow.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ void MainWindow::connectSlots()
289289
connect(&m_coreProcess, &CoreProcess::processStateChanged, this, &MainWindow::coreProcessStateChanged);
290290
connect(&m_coreProcess, &CoreProcess::connectionStateChanged, this, &MainWindow::coreConnectionStateChanged);
291291
connect(&m_coreProcess, &CoreProcess::secureSocket, this, &MainWindow::secureSocket);
292+
connect(&m_coreProcess, &CoreProcess::daemonIpcClientConnectFailed, this, &MainWindow::daemonIpcClientConnectFailed);
292293

293294
connect(m_actionAbout, &QAction::triggered, this, &MainWindow::openAboutDialog);
294295
connect(m_actionClearSettings, &QAction::triggered, this, &MainWindow::clearSettings);
@@ -365,6 +366,21 @@ void MainWindow::firstShown()
365366
// hacky and fragile, so maybe there's a better approach.
366367
const auto kCriticalDialogDelay = 100;
367368
QTimer::singleShot(kCriticalDialogDelay, this, &messages::raiseCriticalDialog);
369+
370+
if (!Settings::value(Settings::Gui::AutoUpdateCheck).isValid()) {
371+
showAndActivate();
372+
Settings::setValue(Settings::Gui::AutoUpdateCheck, messages::showUpdateCheckOption(this));
373+
}
374+
375+
if (Settings::value(Settings::Gui::AutoUpdateCheck).toBool()) {
376+
m_versionChecker.checkLatest();
377+
} else {
378+
qDebug() << "update check disabled";
379+
}
380+
381+
if (Settings::value(Settings::Core::StartedBefore).toBool()) {
382+
m_coreProcess.start();
383+
}
368384
}
369385

370386
void MainWindow::settingsChanged(const QString &key)
@@ -603,24 +619,6 @@ void MainWindow::serverConnectionConfigureClient(const QString &clientName)
603619

604620
void MainWindow::open()
605621
{
606-
607-
if (!Settings::value(Settings::Gui::AutoUpdateCheck).isValid()) {
608-
showAndActivate();
609-
Settings::setValue(Settings::Gui::AutoUpdateCheck, messages::showUpdateCheckOption(this));
610-
}
611-
612-
if (Settings::value(Settings::Gui::AutoUpdateCheck).toBool()) {
613-
m_versionChecker.checkLatest();
614-
} else {
615-
qDebug() << "update check disabled";
616-
}
617-
618-
m_coreProcess.applyLogLevel();
619-
620-
if (Settings::value(Settings::Core::StartedBefore).toBool()) {
621-
m_coreProcess.start();
622-
}
623-
624622
Settings::value(Settings::Gui::Autohide).toBool() ? hide() : showAndActivate();
625623
}
626624

@@ -1137,3 +1135,10 @@ bool MainWindow::regenerateLocalFingerprints()
11371135
updateLocalFingerprint();
11381136
return true;
11391137
}
1138+
1139+
void MainWindow::daemonIpcClientConnectFailed()
1140+
{
1141+
if (deskflow::gui::messages::showDaemonOffline(this)) {
1142+
m_coreProcess.retryDaemon();
1143+
}
1144+
}

src/lib/gui/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class MainWindow : public QMainWindow
158158
void showAndActivate();
159159
void showHostNameEditor();
160160
void setHostName();
161+
void daemonIpcClientConnectFailed();
161162

162163
/**
163164
* @brief trustedFingerprintDb get the fingerprintDb for the trusted clients or trusted servers.

src/lib/gui/Messages.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,35 @@ bool showUpdateCheckOption(QWidget *parent)
309309
return message.clickedButton() == checkButton;
310310
}
311311

312+
bool showDaemonOffline(QWidget *parent)
313+
{
314+
QMessageBox message(parent);
315+
message.setIcon(QMessageBox::Warning);
316+
message.setWindowTitle(QObject::tr("Background service offline"));
317+
318+
message.addButton(QObject::tr("Retry"), QMessageBox::AcceptRole);
319+
const auto ignore = message.addButton(QObject::tr("Ignore"), QMessageBox::RejectRole);
320+
const auto disable = message.addButton(QObject::tr("Disable"), QMessageBox::NoRole);
321+
322+
message.setText(QString(
323+
"<p>There was a problem finding the %1 background service (daemon).</p>"
324+
"<p>The background service makes %1 work with UAC prompts and the login screen.</p>"
325+
"<p>If don't want to use the background service and intentionally stopped it, "
326+
"you can prevent it's use by disabling this feature.</p>"
327+
"<p>If you did not stop the background service intentionally, there may be a problem with it. "
328+
"Please retry or try restarting the %1 service from the Windows services program.</p>"
329+
)
330+
.arg(kAppName));
331+
message.exec();
332+
333+
if (message.clickedButton() == ignore) {
334+
return false;
335+
} else if (message.clickedButton() == disable) {
336+
Settings::setValue(Settings::Core::ProcessMode, Settings::ProcessMode::Desktop);
337+
return false;
338+
}
339+
340+
return true;
341+
}
342+
312343
} // namespace deskflow::gui::messages

src/lib/gui/Messages.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ void showWaylandLibraryError(QWidget *parent);
4949

5050
bool showUpdateCheckOption(QWidget *parent);
5151

52+
bool showDaemonOffline(QWidget *parent);
53+
5254
} // namespace deskflow::gui::messages

src/lib/gui/core/CoreProcess.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ CoreProcess::CoreProcess(const IServerConfig &serverConfig, std::shared_ptr<Deps
140140
m_daemonIpcClient{new ipc::DaemonIpcClient(this)}
141141
{
142142
connect(m_daemonIpcClient, &ipc::DaemonIpcClient::connected, this, &CoreProcess::daemonIpcClientConnected);
143+
connect(m_daemonIpcClient, &ipc::DaemonIpcClient::connectFailed, this, &CoreProcess::daemonIpcClientConnectFailed);
143144

144145
connect(&m_pDeps->process(), &QProcessProxy::finished, this, &CoreProcess::onProcessFinished);
145146

@@ -224,7 +225,7 @@ void CoreProcess::applyLogLevel()
224225
if (processMode == ProcessMode::Service) {
225226
qDebug() << "setting daemon log level:" << Settings::logLevelText();
226227
if (!m_daemonIpcClient->sendLogLevel(Settings::logLevelText())) {
227-
qCritical() << "failed to set daemon ipc log level";
228+
qWarning() << "failed to set daemon ipc log level";
228229
}
229230
}
230231
}
@@ -263,7 +264,7 @@ void CoreProcess::startProcessFromDaemon(const QString &app, const QStringList &
263264
qInfo("running command: %s", qPrintable(commandQuoted));
264265

265266
if (!m_daemonIpcClient->sendStartProcess(commandQuoted, Settings::value(Settings::Daemon::Elevate).toBool())) {
266-
qCritical("cannot start process, ipc command failed");
267+
qWarning("cannot start process, ipc command failed");
267268
return;
268269
}
269270

@@ -297,7 +298,7 @@ void CoreProcess::stopProcessFromDaemon()
297298
}
298299

299300
if (!m_daemonIpcClient->sendStopProcess()) {
300-
qCritical("cannot stop process, ipc command failed");
301+
qWarning("cannot stop process, ipc command failed");
301302
return;
302303
}
303304

@@ -736,4 +737,11 @@ void CoreProcess::clearSettings()
736737
m_daemonIpcClient->sendClearSettings();
737738
}
738739

740+
void CoreProcess::retryDaemon()
741+
{
742+
if (m_daemonIpcClient->connectToServer()) {
743+
qInfo("successfully reconnected to daemon");
744+
}
745+
}
746+
739747
} // namespace deskflow::gui

src/lib/gui/core/CoreProcess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class CoreProcess : public QObject
7979
void cleanup();
8080
void applyLogLevel();
8181
void clearSettings();
82+
void retryDaemon();
8283

8384
// getters
8485
Settings::CoreMode mode() const
@@ -119,6 +120,7 @@ class CoreProcess : public QObject
119120
void connectionStateChanged(ConnectionState state);
120121
void processStateChanged(ProcessState state);
121122
void secureSocket(bool enabled);
123+
void daemonIpcClientConnectFailed();
122124

123125
private slots:
124126
void onProcessFinished(int exitCode, QProcess::ExitStatus);

src/lib/gui/ipc/DaemonIpcClient.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,32 @@ DaemonIpcClient::DaemonIpcClient(QObject *parent)
2727

2828
bool DaemonIpcClient::connectToServer()
2929
{
30-
qDebug() << "daemon ipc client connecting to server:" << kDaemonIpcName;
30+
if (m_connecting) {
31+
qDebug() << "daemon ipc client already connecting to server";
32+
return false;
33+
}
3134

35+
qDebug() << "daemon ipc client connecting to server:" << kDaemonIpcName;
36+
m_connecting = true;
3237
m_socket->connectToServer(kDaemonIpcName);
38+
3339
if (!m_socket->waitForConnected(kTimeout)) {
3440
qWarning() << "daemon ipc client failed to connect";
41+
m_connecting = false;
42+
Q_EMIT connectFailed();
3543
return false;
3644
}
3745

3846
if (!sendMessage("hello", "hello", false)) {
3947
qWarning() << "daemon ipc client failed to send hello";
48+
m_connecting = false;
49+
Q_EMIT connectFailed();
4050
return false;
4151
}
4252

53+
m_connecting = false;
4354
m_connected = true;
55+
4456
qDebug() << "daemon ipc client connected";
4557
Q_EMIT connected();
4658

@@ -51,10 +63,7 @@ void DaemonIpcClient::handleDisconnected()
5163
{
5264
qWarning() << "daemon ipc client disconnected from server";
5365
m_connected = false;
54-
55-
if (!connectToServer()) {
56-
qWarning() << "daemon ipc client failed to reconnect to server";
57-
}
66+
Q_EMIT connectFailed();
5867
}
5968

6069
void DaemonIpcClient::handleErrorOccurred()

src/lib/gui/ipc/DaemonIpcClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#include <QObject>
1010

11-
#include "common/Settings.h"
12-
1311
class QLocalSocket;
1412

1513
namespace deskflow::gui::ipc {
@@ -34,6 +32,7 @@ class DaemonIpcClient : public QObject
3432

3533
signals:
3634
void connected();
35+
void connectFailed();
3736

3837
private slots:
3938
void handleDisconnected();
@@ -46,6 +45,7 @@ private slots:
4645
private:
4746
QLocalSocket *m_socket;
4847
bool m_connected{false};
48+
bool m_connecting{false};
4949
};
5050

5151
} // namespace deskflow::gui::ipc

0 commit comments

Comments
 (0)