From 6041c6773e664284752dca67d1a7ebd976a89125 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Tue, 23 Apr 2024 13:24:39 +0300 Subject: [PATCH] UIL RpcManager: Add AutoUpdateManager --- src/ui/control/control.cpp | 10 +++++++--- src/ui/control/control_types.h | 4 +++- src/ui/manager/autoupdatemanager.cpp | 6 +++--- src/ui/manager/autoupdatemanager.h | 5 ++++- src/ui/rpc/autoupdatemanagerrpc.cpp | 27 +++++++++++++++++++++++++++ src/ui/rpc/autoupdatemanagerrpc.h | 7 +++++++ src/ui/rpc/rpcmanager.cpp | 8 +++----- 7 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/ui/control/control.cpp b/src/ui/control/control.cpp index 1b67c7a0..9b3efa1a 100644 --- a/src/ui/control/control.cpp +++ b/src/ui/control/control.cpp @@ -17,11 +17,12 @@ const char *const commandString(Command cmd) CASE_STRING(Rpc_Result_Error) CASE_STRING(Rpc_RpcManager_initClient) - CASE_STRING(Rpc_RpcManager_restartClient) CASE_STRING(Rpc_AppInfoManager_lookupAppInfo) CASE_STRING(Rpc_AppInfoManager_checkLookupInfoFinished) + CASE_STRING(Rpc_AutoUpdateManager_restartClients) + CASE_STRING(Rpc_ConfManager_saveVariant) CASE_STRING(Rpc_ConfManager_exportMasterBackup) CASE_STRING(Rpc_ConfManager_importMasterBackup) @@ -91,6 +92,7 @@ const char *const rpcManagerString(RpcManager rpcManager) switch (rpcManager) { CASE_STRING(Rpc_NoneManager) CASE_STRING(Rpc_AppInfoManager) + CASE_STRING(Rpc_AutoUpdateManager) CASE_STRING(Rpc_ConfManager) CASE_STRING(Rpc_ConfAppManager) CASE_STRING(Rpc_ConfRuleManager) @@ -117,11 +119,12 @@ RpcManager managerByCommand(Command cmd) Rpc_NoneManager, // Rpc_Result_Error, Rpc_NoneManager, // Rpc_RpcManager_initClient, - Rpc_NoneManager, // Rpc_RpcManager_restartClient, Rpc_AppInfoManager, // Rpc_AppInfoManager_lookupAppInfo, Rpc_AppInfoManager, // Rpc_AppInfoManager_checkLookupFinished, + Rpc_AutoUpdateManager, // Rpc_AutoUpdateManager_restartClients, + Rpc_ConfManager, // Rpc_ConfManager_saveVariant, Rpc_ConfManager, // Rpc_ConfManager_exportMasterBackup, Rpc_ConfManager, // Rpc_ConfManager_importMasterBackup, @@ -197,11 +200,12 @@ bool commandRequiresValidation(Command cmd) 0, // Rpc_Result_Error, 0, // Rpc_RpcManager_initClient, - 0, // Rpc_RpcManager_restartClient, true, // Rpc_AppInfoManager_lookupAppInfo, 0, // Rpc_AppInfoManager_checkLookupFinished, + 0, // Rpc_AutoUpdateManager_restartClients, + true, // Rpc_ConfManager_saveVariant, true, // Rpc_ConfManager_exportMasterBackup, true, // Rpc_ConfManager_importMasterBackup, diff --git a/src/ui/control/control_types.h b/src/ui/control/control_types.h index db30c519..9807d477 100644 --- a/src/ui/control/control_types.h +++ b/src/ui/control/control_types.h @@ -17,11 +17,12 @@ enum Command : qint8 { Rpc_Result_Error, Rpc_RpcManager_initClient, - Rpc_RpcManager_restartClient, Rpc_AppInfoManager_lookupAppInfo, Rpc_AppInfoManager_checkLookupInfoFinished, + Rpc_AutoUpdateManager_restartClients, + Rpc_ConfManager_saveVariant, Rpc_ConfManager_exportMasterBackup, Rpc_ConfManager_importMasterBackup, @@ -86,6 +87,7 @@ enum Command : qint8 { enum RpcManager : qint8 { Rpc_NoneManager = 0, Rpc_AppInfoManager, + Rpc_AutoUpdateManager, Rpc_ConfManager, Rpc_ConfAppManager, Rpc_ConfRuleManager, diff --git a/src/ui/manager/autoupdatemanager.cpp b/src/ui/manager/autoupdatemanager.cpp index 1fdd2751..cd34630e 100644 --- a/src/ui/manager/autoupdatemanager.cpp +++ b/src/ui/manager/autoupdatemanager.cpp @@ -82,7 +82,7 @@ bool AutoUpdateManager::runInstaller() return false; QStringList args; - fillInstallerArgs(args); + prepareInstaller(args); if (!QProcess::startDetached(exePath, args)) return false; @@ -90,7 +90,7 @@ bool AutoUpdateManager::runInstaller() return true; } -void AutoUpdateManager::fillInstallerArgs(QStringList &args) const +void AutoUpdateManager::prepareInstaller(QStringList &args) { auto settings = IoC(); @@ -101,6 +101,6 @@ void AutoUpdateManager::fillInstallerArgs(QStringList &args) const if (!settings->hasService()) { args << "/AUTORUN"; } else if (settings->isService()) { - IoC()->invokeOnClients(Control::Rpc_RpcManager_restartClient); + emit restartClients(); } } diff --git a/src/ui/manager/autoupdatemanager.h b/src/ui/manager/autoupdatemanager.h index dfe3a501..171b6d56 100644 --- a/src/ui/manager/autoupdatemanager.h +++ b/src/ui/manager/autoupdatemanager.h @@ -18,6 +18,9 @@ public: void setUp() override; void tearDown() override; +signals: + void restartClients(); + protected: void setupDownloader() override; @@ -29,7 +32,7 @@ protected slots: void clearUpdateDir(); bool runInstaller(); - void fillInstallerArgs(QStringList &args) const; + void prepareInstaller(QStringList &args); private: static QString getDownloadUrl(); diff --git a/src/ui/rpc/autoupdatemanagerrpc.cpp b/src/ui/rpc/autoupdatemanagerrpc.cpp index e8b361fb..67f2cb16 100644 --- a/src/ui/rpc/autoupdatemanagerrpc.cpp +++ b/src/ui/rpc/autoupdatemanagerrpc.cpp @@ -1,6 +1,33 @@ #include "autoupdatemanagerrpc.h" +#include +#include +#include + AutoUpdateManagerRpc::AutoUpdateManagerRpc(const QString &cachePath, QObject *parent) : AutoUpdateManager(cachePath, parent) { } + +bool AutoUpdateManagerRpc::processServerCommand(const ProcessCommandArgs &p, + QVariantList & /*resArgs*/, bool & /*ok*/, bool & /*isSendResult*/) +{ + auto autoUpdateManager = IoC(); + + 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(); + + connect(autoUpdateManager, &AutoUpdateManager::restartClients, rpcManager, + [&] { rpcManager->invokeOnClients(Control::Rpc_AutoUpdateManager_restartClients); }); +} diff --git a/src/ui/rpc/autoupdatemanagerrpc.h b/src/ui/rpc/autoupdatemanagerrpc.h index d8e871a6..f031736f 100644 --- a/src/ui/rpc/autoupdatemanagerrpc.h +++ b/src/ui/rpc/autoupdatemanagerrpc.h @@ -5,12 +5,19 @@ class RpcManager; +struct ProcessCommandArgs; + class AutoUpdateManagerRpc : public AutoUpdateManager { Q_OBJECT public: 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 diff --git a/src/ui/rpc/rpcmanager.cpp b/src/ui/rpc/rpcmanager.cpp index 52d55cfa..c34150d9 100644 --- a/src/ui/rpc/rpcmanager.cpp +++ b/src/ui/rpc/rpcmanager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,7 @@ void RpcManager::tearDown() void RpcManager::setupServerSignals() { AppInfoManagerRpc::setupServerSignals(this); + AutoUpdateManagerRpc::setupServerSignals(this); ConfManagerRpc::setupServerSignals(this); ConfAppManagerRpc::setupServerSignals(this); ConfRuleManagerRpc::setupServerSignals(this); @@ -210,11 +212,6 @@ bool RpcManager::processCommandRpc(const ProcessCommandArgs &p) return true; } - case Control::Rpc_RpcManager_restartClient: { - QMetaObject::invokeMethod(this, [] { OsUtil::restartClient(); }, Qt::QueuedConnection); - return true; - } - default: return processManagerRpc(p); } @@ -222,6 +219,7 @@ bool RpcManager::processCommandRpc(const ProcessCommandArgs &p) static processManager_func processManager_funcList[] = { &AppInfoManagerRpc::processServerCommand, // Control::Rpc_AppInfoManager, + &AutoUpdateManagerRpc::processServerCommand, // Control::Rpc_AutoUpdateManager, &ConfManagerRpc::processServerCommand, // Control::Rpc_ConfManager, &ConfAppManagerRpc::processServerCommand, // Control::Rpc_ConfAppManager, &ConfRuleManagerRpc::processServerCommand, // Control::Rpc_ConfRuleManager,