added display of a notification that the server is busy installing third-party software

- refactoring doInstallAction functions
This commit is contained in:
vladimir.kuznetsov 2023-01-01 21:48:20 +03:00
parent 3f257af7a9
commit 08a8eadb49
22 changed files with 398 additions and 346 deletions

View file

@ -1,7 +1,10 @@
#include "ShadowSocksLogic.h"
#include "core/servercontroller.h"
#include <functional>
#include "../../uilogic.h"
#include "core/servercontroller.h"
#include "ui/pages_logic/ServerConfiguringProgressLogic.h"
#include "ui/uilogic.h"
using namespace amnezia;
using namespace PageEnumNS;
@ -11,12 +14,12 @@ ShadowSocksLogic::ShadowSocksLogic(UiLogic *logic, QObject *parent):
m_comboBoxCipherText{"chacha20-poly1305"},
m_lineEditPortText{},
m_pushButtonSaveVisible{false},
m_progressBaResetVisible{false},
m_progressBarResetVisible{false},
m_lineEditPortEnabled{false},
m_labelInfoVisible{true},
m_labelInfoText{},
m_progressBaResetValue{0},
m_progressBaResetMaximium{100}
m_progressBarResetValue{0},
m_progressBarResetMaximium{100}
{
}
@ -25,7 +28,7 @@ void ShadowSocksLogic::updateProtocolPage(const QJsonObject &ssConfig, DockerCon
{
set_pageEnabled(haveAuthData);
set_pushButtonSaveVisible(haveAuthData);
set_progressBaResetVisible(haveAuthData);
set_progressBarResetVisible(haveAuthData);
set_comboBoxCipherText(ssConfig.value(config_key::cipher).
toString(protocols::shadowsocks::defaultCipher));
@ -51,40 +54,59 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
QJsonObject newContainerConfig = containerConfig;
newContainerConfig.insert(ProtocolProps::protoToString(Proto::ShadowSocks), protocolConfig);
UiLogic::PageFunc page_proto_shadowsocks;
page_proto_shadowsocks.setEnabledFunc = [this] (bool enabled) -> void {
ServerConfiguringProgressLogic::PageFunc pageFunc;
pageFunc.setEnabledFunc = [this] (bool enabled) -> void {
set_pageEnabled(enabled);
};
UiLogic::ButtonFunc pushButton_proto_shadowsocks_save;
pushButton_proto_shadowsocks_save.setVisibleFunc = [this] (bool visible) ->void {
ServerConfiguringProgressLogic::ButtonFunc saveButtonFunc;
saveButtonFunc.setVisibleFunc = [this] (bool visible) -> void {
set_pushButtonSaveVisible(visible);
};
UiLogic::LabelFunc label_proto_shadowsocks_info;
label_proto_shadowsocks_info.setVisibleFunc = [this] (bool visible) ->void {
ServerConfiguringProgressLogic::LabelFunc waitInfoFunc;
waitInfoFunc.setVisibleFunc = [this] (bool visible) -> void {
set_labelInfoVisible(visible);
};
label_proto_shadowsocks_info.setTextFunc = [this] (const QString& text) ->void {
waitInfoFunc.setTextFunc = [this] (const QString& text) -> void {
set_labelInfoText(text);
};
UiLogic::ProgressFunc progressBar_reset;
progressBar_reset.setVisibleFunc = [this] (bool visible) ->void {
set_progressBaResetVisible(visible);
ServerConfiguringProgressLogic::ProgressFunc progressBarFunc;
progressBarFunc.setVisibleFunc = [this] (bool visible) -> void {
set_progressBarResetVisible(visible);
};
progressBar_reset.setValueFunc = [this] (int value) ->void {
set_progressBaResetValue(value);
progressBarFunc.setValueFunc = [this] (int value) -> void {
set_progressBarResetValue(value);
};
progressBar_reset.getValueFunc = [this] (void) -> int {
return progressBaResetValue();
progressBarFunc.getValueFunc = [this] (void) -> int {
return progressBarResetValue();
};
progressBar_reset.getMaximiumFunc = [this] (void) -> int {
return progressBaResetMaximium();
progressBarFunc.getMaximiumFunc = [this] (void) -> int {
return progressBarResetMaximium();
};
progressBarFunc.setTextVisibleFunc = [this] (bool visible) -> void {
set_progressBarTextVisible(visible);
};
progressBarFunc.setTextFunc = [this] (const QString& text) -> void {
set_progressBarText(text);
};
ErrorCode e = uiLogic()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), uiLogic()->selectedDockerContainer, containerConfig, newContainerConfig);
ServerConfiguringProgressLogic::LabelFunc busyInfoFuncy;
busyInfoFuncy.setTextFunc = [this] (const QString& text) -> void {
set_labelServerBusyText(text);
};
busyInfoFuncy.setVisibleFunc = [this] (bool visible) -> void {
set_labelServerBusyVisible(visible);
};
progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
uiLogic()->selectedDockerContainer,
containerConfig,
newContainerConfig);
},
page_proto_shadowsocks, progressBar_reset,
pushButton_proto_shadowsocks_save, label_proto_shadowsocks_info);
pageFunc, progressBarFunc,
saveButtonFunc, waitInfoFunc, busyInfoFuncy);
if (!e) {
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig);