UI: Confirm restart on DB error

This commit is contained in:
Nodir Temirkhodjaev 2024-01-11 17:28:36 +03:00
parent 991ff38c10
commit 4878582b61
5 changed files with 27 additions and 17 deletions

View File

@ -422,10 +422,16 @@ void FortManager::show()
void FortManager::processRestartRequired() void FortManager::processRestartRequired()
{ {
auto windowManager = IoC<WindowManager>(); auto settings = IoC<FortSettings>();
windowManager->showConfirmBox( if (settings->isService()) {
[=] { windowManager->restart(); }, tr("Restart Now?"), tr("Restart Required")); IoC<ServiceManager>()->restart();
} else {
auto windowManager = IoC<WindowManager>();
windowManager->showConfirmBox(
[=] { windowManager->restart(); }, tr("Restart Now?"), tr("Restart Required"));
}
} }
void FortManager::loadConf() void FortManager::loadConf()

View File

@ -5,8 +5,8 @@
#include <sqlite/sqlitedb.h> #include <sqlite/sqlitedb.h>
#include <fortmanager.h>
#include <fortsettings.h> #include <fortsettings.h>
#include <manager/windowmanager.h>
#include <util/fileutil.h> #include <util/fileutil.h>
#include <util/ioc/ioccontainer.h> #include <util/ioc/ioccontainer.h>
@ -30,17 +30,14 @@ void sqliteLogHandler(void *context, int errCode, const char *message)
DbErrorManager::DbErrorManager(QObject *parent) : QObject(parent) { } DbErrorManager::DbErrorManager(QObject *parent) : QObject(parent) { }
void DbErrorManager::setUp() void DbErrorManager::setUp()
{
setupDriveMask();
SqliteDb::setErrorLogCallback(sqliteLogHandler, /*context=*/this);
}
void DbErrorManager::setupDriveMask()
{ {
auto settings = IoC<FortSettings>(); auto settings = IoC<FortSettings>();
// Drive Mask
m_driveMask |= FileUtil::driveMaskByPath(settings->confFilePath()); m_driveMask |= FileUtil::driveMaskByPath(settings->confFilePath());
// SQLite Log Callback
SqliteDb::setErrorLogCallback(sqliteLogHandler, /*context=*/this);
} }
void DbErrorManager::onDbIoError() void DbErrorManager::onDbIoError()
@ -59,7 +56,7 @@ void DbErrorManager::checkDriveList()
if (m_driveMask == driveMask) { if (m_driveMask == driveMask) {
// Restart on profile drive mounted // Restart on profile drive mounted
IoC<WindowManager>()->restart(); IoC<FortManager>()->processRestartRequired();
return; return;
} }

View File

@ -21,10 +21,7 @@ private slots:
void checkDriveList(); void checkDriveList();
private: private:
void setupDriveMask(); bool m_polling : 1 = false;
private:
bool m_polling = false;
quint32 m_driveMask = 0; quint32 m_driveMask = 0;
}; };

View File

@ -49,6 +49,8 @@ void ServiceManager::initialize(qintptr hstatus)
ServiceManagerIface::initialize(hstatus); ServiceManagerIface::initialize(hstatus);
registerDeviceNotification(); registerDeviceNotification();
qApp->connect(qApp, &QObject::destroyed, [] { reportStatus(SERVICE_STOPPED); });
} }
void ServiceManager::setupControlManager() void ServiceManager::setupControlManager()
@ -113,7 +115,6 @@ void ServiceManager::processControl(quint32 code, quint32 eventType)
case SERVICE_CONTROL_SHUTDOWN: { case SERVICE_CONTROL_SHUTDOWN: {
qCDebug(LC) << "Quit due service control"; qCDebug(LC) << "Quit due service control";
qApp->connect(qApp, &QObject::destroyed, [] { reportStatus(SERVICE_STOPPED); });
QCoreApplication::quit(); // it's threadsafe QCoreApplication::quit(); // it's threadsafe
state = SERVICE_STOP_PENDING; state = SERVICE_STOP_PENDING;
@ -127,3 +128,10 @@ void ServiceManager::processControl(quint32 code, quint32 eventType)
reportStatus(state); reportStatus(state);
} }
void ServiceManager::restart()
{
qCDebug(LC) << "Quit due required restart";
QCoreApplication::quit();
}

View File

@ -30,6 +30,8 @@ public:
void processControl(quint32 code, quint32 eventType) override; void processControl(quint32 code, quint32 eventType) override;
void restart();
signals: signals:
void pauseRequested(); void pauseRequested();
void continueRequested(); void continueRequested();