Fixed display of confirmation box for proxy links in correspond window.

This commit is contained in:
23rd 2024-05-03 20:17:43 +03:00
parent 5c83858a50
commit 233e80d22d
3 changed files with 65 additions and 48 deletions

View file

@ -37,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "boxes/abstract_box.h" // Ui::show(). #include "boxes/abstract_box.h" // Ui::show().
#include "window/window_session_controller.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
@ -1186,10 +1187,22 @@ ProxiesBoxController::ProxiesBoxController(not_null<Main::Account*> account)
} }
void ProxiesBoxController::ShowApplyConfirmation( void ProxiesBoxController::ShowApplyConfirmation(
Window::SessionController *controller,
Type type, Type type,
const QMap<QString, QString> &fields) { const QMap<QString, QString> &fields) {
const auto proxy = ProxyDataFromFields(type, fields); const auto proxy = ProxyDataFromFields(type, fields);
if (proxy) { if (!proxy) {
auto box = Ui::MakeInformBox(
(proxy.status() == ProxyData::Status::Unsupported
? tr::lng_proxy_unsupported(tr::now)
: tr::lng_proxy_invalid(tr::now)));
if (controller) {
controller->uiShow()->showBox(std::move(box));
} else {
Ui::show(std::move(box));
}
return;
}
static const auto UrlStartRegExp = QRegularExpression( static const auto UrlStartRegExp = QRegularExpression(
"^https://", "^https://",
QRegularExpression::CaseInsensitiveOption); QRegularExpression::CaseInsensitiveOption);
@ -1227,18 +1240,15 @@ void ProxiesBoxController::ShowApplyConfirmation(
Local::writeSettings(); Local::writeSettings();
close(); close();
}; };
Ui::show( auto box = Ui::MakeConfirmBox({
Ui::MakeConfirmBox({
.text = text, .text = text,
.confirmed = std::move(callback), .confirmed = std::move(callback),
.confirmText = tr::lng_sure_enable(), .confirmText = tr::lng_sure_enable(),
}), });
Ui::LayerOption::KeepOther); if (controller) {
controller->uiShow()->showBox(std::move(box));
} else { } else {
Ui::show(Ui::MakeInformBox( Ui::show(std::move(box));
(proxy.status() == ProxyData::Status::Unsupported
? tr::lng_proxy_unsupported(tr::now)
: tr::lng_proxy_invalid(tr::now))));
} }
} }

View file

@ -30,6 +30,10 @@ namespace Main {
class Account; class Account;
} // namespace Main } // namespace Main
namespace Window {
class SessionController;
} // namespace Window
class ProxiesBoxController { class ProxiesBoxController {
public: public:
using ProxyData = MTP::ProxyData; using ProxyData = MTP::ProxyData;
@ -38,6 +42,7 @@ public:
explicit ProxiesBoxController(not_null<Main::Account*> account); explicit ProxiesBoxController(not_null<Main::Account*> account);
static void ShowApplyConfirmation( static void ShowApplyConfirmation(
Window::SessionController *controller,
Type type, Type type,
const QMap<QString, QString> &fields); const QMap<QString, QString> &fields);

View file

@ -350,6 +350,7 @@ bool ApplySocksProxy(
match->captured(1), match->captured(1),
qthelp::UrlParamNameTransform::ToLower); qthelp::UrlParamNameTransform::ToLower);
ProxiesBoxController::ShowApplyConfirmation( ProxiesBoxController::ShowApplyConfirmation(
controller,
MTP::ProxyData::Type::Socks5, MTP::ProxyData::Type::Socks5,
params); params);
if (controller) { if (controller) {
@ -366,6 +367,7 @@ bool ApplyMtprotoProxy(
match->captured(1), match->captured(1),
qthelp::UrlParamNameTransform::ToLower); qthelp::UrlParamNameTransform::ToLower);
ProxiesBoxController::ShowApplyConfirmation( ProxiesBoxController::ShowApplyConfirmation(
controller,
MTP::ProxyData::Type::Mtproto, MTP::ProxyData::Type::Mtproto,
params); params);
if (controller) { if (controller) {