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

View file

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

View file

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