UIL RpcManager: Add AutoUpdateManager

This commit is contained in:
Nodir Temirkhodjaev 2024-04-23 13:24:39 +03:00
parent 30c2e7bfa4
commit 6041c6773e
7 changed files with 54 additions and 13 deletions

View File

@ -17,11 +17,12 @@ const char *const commandString(Command cmd)
CASE_STRING(Rpc_Result_Error) CASE_STRING(Rpc_Result_Error)
CASE_STRING(Rpc_RpcManager_initClient) CASE_STRING(Rpc_RpcManager_initClient)
CASE_STRING(Rpc_RpcManager_restartClient)
CASE_STRING(Rpc_AppInfoManager_lookupAppInfo) CASE_STRING(Rpc_AppInfoManager_lookupAppInfo)
CASE_STRING(Rpc_AppInfoManager_checkLookupInfoFinished) CASE_STRING(Rpc_AppInfoManager_checkLookupInfoFinished)
CASE_STRING(Rpc_AutoUpdateManager_restartClients)
CASE_STRING(Rpc_ConfManager_saveVariant) CASE_STRING(Rpc_ConfManager_saveVariant)
CASE_STRING(Rpc_ConfManager_exportMasterBackup) CASE_STRING(Rpc_ConfManager_exportMasterBackup)
CASE_STRING(Rpc_ConfManager_importMasterBackup) CASE_STRING(Rpc_ConfManager_importMasterBackup)
@ -91,6 +92,7 @@ const char *const rpcManagerString(RpcManager rpcManager)
switch (rpcManager) { switch (rpcManager) {
CASE_STRING(Rpc_NoneManager) CASE_STRING(Rpc_NoneManager)
CASE_STRING(Rpc_AppInfoManager) CASE_STRING(Rpc_AppInfoManager)
CASE_STRING(Rpc_AutoUpdateManager)
CASE_STRING(Rpc_ConfManager) CASE_STRING(Rpc_ConfManager)
CASE_STRING(Rpc_ConfAppManager) CASE_STRING(Rpc_ConfAppManager)
CASE_STRING(Rpc_ConfRuleManager) CASE_STRING(Rpc_ConfRuleManager)
@ -117,11 +119,12 @@ RpcManager managerByCommand(Command cmd)
Rpc_NoneManager, // Rpc_Result_Error, Rpc_NoneManager, // Rpc_Result_Error,
Rpc_NoneManager, // Rpc_RpcManager_initClient, Rpc_NoneManager, // Rpc_RpcManager_initClient,
Rpc_NoneManager, // Rpc_RpcManager_restartClient,
Rpc_AppInfoManager, // Rpc_AppInfoManager_lookupAppInfo, Rpc_AppInfoManager, // Rpc_AppInfoManager_lookupAppInfo,
Rpc_AppInfoManager, // Rpc_AppInfoManager_checkLookupFinished, Rpc_AppInfoManager, // Rpc_AppInfoManager_checkLookupFinished,
Rpc_AutoUpdateManager, // Rpc_AutoUpdateManager_restartClients,
Rpc_ConfManager, // Rpc_ConfManager_saveVariant, Rpc_ConfManager, // Rpc_ConfManager_saveVariant,
Rpc_ConfManager, // Rpc_ConfManager_exportMasterBackup, Rpc_ConfManager, // Rpc_ConfManager_exportMasterBackup,
Rpc_ConfManager, // Rpc_ConfManager_importMasterBackup, Rpc_ConfManager, // Rpc_ConfManager_importMasterBackup,
@ -197,11 +200,12 @@ bool commandRequiresValidation(Command cmd)
0, // Rpc_Result_Error, 0, // Rpc_Result_Error,
0, // Rpc_RpcManager_initClient, 0, // Rpc_RpcManager_initClient,
0, // Rpc_RpcManager_restartClient,
true, // Rpc_AppInfoManager_lookupAppInfo, true, // Rpc_AppInfoManager_lookupAppInfo,
0, // Rpc_AppInfoManager_checkLookupFinished, 0, // Rpc_AppInfoManager_checkLookupFinished,
0, // Rpc_AutoUpdateManager_restartClients,
true, // Rpc_ConfManager_saveVariant, true, // Rpc_ConfManager_saveVariant,
true, // Rpc_ConfManager_exportMasterBackup, true, // Rpc_ConfManager_exportMasterBackup,
true, // Rpc_ConfManager_importMasterBackup, true, // Rpc_ConfManager_importMasterBackup,

View File

@ -17,11 +17,12 @@ enum Command : qint8 {
Rpc_Result_Error, Rpc_Result_Error,
Rpc_RpcManager_initClient, Rpc_RpcManager_initClient,
Rpc_RpcManager_restartClient,
Rpc_AppInfoManager_lookupAppInfo, Rpc_AppInfoManager_lookupAppInfo,
Rpc_AppInfoManager_checkLookupInfoFinished, Rpc_AppInfoManager_checkLookupInfoFinished,
Rpc_AutoUpdateManager_restartClients,
Rpc_ConfManager_saveVariant, Rpc_ConfManager_saveVariant,
Rpc_ConfManager_exportMasterBackup, Rpc_ConfManager_exportMasterBackup,
Rpc_ConfManager_importMasterBackup, Rpc_ConfManager_importMasterBackup,
@ -86,6 +87,7 @@ enum Command : qint8 {
enum RpcManager : qint8 { enum RpcManager : qint8 {
Rpc_NoneManager = 0, Rpc_NoneManager = 0,
Rpc_AppInfoManager, Rpc_AppInfoManager,
Rpc_AutoUpdateManager,
Rpc_ConfManager, Rpc_ConfManager,
Rpc_ConfAppManager, Rpc_ConfAppManager,
Rpc_ConfRuleManager, Rpc_ConfRuleManager,

View File

@ -82,7 +82,7 @@ bool AutoUpdateManager::runInstaller()
return false; return false;
QStringList args; QStringList args;
fillInstallerArgs(args); prepareInstaller(args);
if (!QProcess::startDetached(exePath, args)) if (!QProcess::startDetached(exePath, args))
return false; return false;
@ -90,7 +90,7 @@ bool AutoUpdateManager::runInstaller()
return true; return true;
} }
void AutoUpdateManager::fillInstallerArgs(QStringList &args) const void AutoUpdateManager::prepareInstaller(QStringList &args)
{ {
auto settings = IoC<FortSettings>(); auto settings = IoC<FortSettings>();
@ -101,6 +101,6 @@ void AutoUpdateManager::fillInstallerArgs(QStringList &args) const
if (!settings->hasService()) { if (!settings->hasService()) {
args << "/AUTORUN"; args << "/AUTORUN";
} else if (settings->isService()) { } else if (settings->isService()) {
IoC<RpcManager>()->invokeOnClients(Control::Rpc_RpcManager_restartClient); emit restartClients();
} }
} }

View File

@ -18,6 +18,9 @@ public:
void setUp() override; void setUp() override;
void tearDown() override; void tearDown() override;
signals:
void restartClients();
protected: protected:
void setupDownloader() override; void setupDownloader() override;
@ -29,7 +32,7 @@ protected slots:
void clearUpdateDir(); void clearUpdateDir();
bool runInstaller(); bool runInstaller();
void fillInstallerArgs(QStringList &args) const; void prepareInstaller(QStringList &args);
private: private:
static QString getDownloadUrl(); static QString getDownloadUrl();

View File

@ -1,6 +1,33 @@
#include "autoupdatemanagerrpc.h" #include "autoupdatemanagerrpc.h"
#include <rpc/rpcmanager.h>
#include <util/ioc/ioccontainer.h>
#include <util/osutil.h>
AutoUpdateManagerRpc::AutoUpdateManagerRpc(const QString &cachePath, QObject *parent) : AutoUpdateManagerRpc::AutoUpdateManagerRpc(const QString &cachePath, QObject *parent) :
AutoUpdateManager(cachePath, parent) AutoUpdateManager(cachePath, parent)
{ {
} }
bool AutoUpdateManagerRpc::processServerCommand(const ProcessCommandArgs &p,
QVariantList & /*resArgs*/, bool & /*ok*/, bool & /*isSendResult*/)
{
auto autoUpdateManager = IoC<AutoUpdateManager>();
switch (p.command) {
case Control::Rpc_AutoUpdateManager_restartClients:
QMetaObject::invokeMethod(
autoUpdateManager, [] { OsUtil::restartClient(); }, Qt::QueuedConnection);
return true;
default:
return false;
}
}
void AutoUpdateManagerRpc::setupServerSignals(RpcManager *rpcManager)
{
auto autoUpdateManager = IoC<AutoUpdateManager>();
connect(autoUpdateManager, &AutoUpdateManager::restartClients, rpcManager,
[&] { rpcManager->invokeOnClients(Control::Rpc_AutoUpdateManager_restartClients); });
}

View File

@ -5,12 +5,19 @@
class RpcManager; class RpcManager;
struct ProcessCommandArgs;
class AutoUpdateManagerRpc : public AutoUpdateManager class AutoUpdateManagerRpc : public AutoUpdateManager
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AutoUpdateManagerRpc(const QString &cachePath, QObject *parent = nullptr); explicit AutoUpdateManagerRpc(const QString &cachePath, QObject *parent = nullptr);
static bool processServerCommand(
const ProcessCommandArgs &p, QVariantList &resArgs, bool &ok, bool &isSendResult);
static void setupServerSignals(RpcManager *rpcManager);
}; };
#endif // AUTOUPDATEMANAGERRPC_H #endif // AUTOUPDATEMANAGERRPC_H

View File

@ -10,6 +10,7 @@
#include <fortsettings.h> #include <fortsettings.h>
#include <manager/windowmanager.h> #include <manager/windowmanager.h>
#include <rpc/appinfomanagerrpc.h> #include <rpc/appinfomanagerrpc.h>
#include <rpc/autoupdatemanagerrpc.h>
#include <rpc/confappmanagerrpc.h> #include <rpc/confappmanagerrpc.h>
#include <rpc/confmanagerrpc.h> #include <rpc/confmanagerrpc.h>
#include <rpc/confrulemanagerrpc.h> #include <rpc/confrulemanagerrpc.h>
@ -79,6 +80,7 @@ void RpcManager::tearDown()
void RpcManager::setupServerSignals() void RpcManager::setupServerSignals()
{ {
AppInfoManagerRpc::setupServerSignals(this); AppInfoManagerRpc::setupServerSignals(this);
AutoUpdateManagerRpc::setupServerSignals(this);
ConfManagerRpc::setupServerSignals(this); ConfManagerRpc::setupServerSignals(this);
ConfAppManagerRpc::setupServerSignals(this); ConfAppManagerRpc::setupServerSignals(this);
ConfRuleManagerRpc::setupServerSignals(this); ConfRuleManagerRpc::setupServerSignals(this);
@ -210,11 +212,6 @@ bool RpcManager::processCommandRpc(const ProcessCommandArgs &p)
return true; return true;
} }
case Control::Rpc_RpcManager_restartClient: {
QMetaObject::invokeMethod(this, [] { OsUtil::restartClient(); }, Qt::QueuedConnection);
return true;
}
default: default:
return processManagerRpc(p); return processManagerRpc(p);
} }
@ -222,6 +219,7 @@ bool RpcManager::processCommandRpc(const ProcessCommandArgs &p)
static processManager_func processManager_funcList[] = { static processManager_func processManager_funcList[] = {
&AppInfoManagerRpc::processServerCommand, // Control::Rpc_AppInfoManager, &AppInfoManagerRpc::processServerCommand, // Control::Rpc_AppInfoManager,
&AutoUpdateManagerRpc::processServerCommand, // Control::Rpc_AutoUpdateManager,
&ConfManagerRpc::processServerCommand, // Control::Rpc_ConfManager, &ConfManagerRpc::processServerCommand, // Control::Rpc_ConfManager,
&ConfAppManagerRpc::processServerCommand, // Control::Rpc_ConfAppManager, &ConfAppManagerRpc::processServerCommand, // Control::Rpc_ConfAppManager,
&ConfRuleManagerRpc::processServerCommand, // Control::Rpc_ConfRuleManager, &ConfRuleManagerRpc::processServerCommand, // Control::Rpc_ConfRuleManager,