mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed display of confirmation box for proxy links in correspond window.
This commit is contained in:
parent
5c83858a50
commit
233e80d22d
3 changed files with 65 additions and 48 deletions
|
@ -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,59 +1187,68 @@ 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) {
|
||||||
static const auto UrlStartRegExp = QRegularExpression(
|
auto box = Ui::MakeInformBox(
|
||||||
"^https://",
|
|
||||||
QRegularExpression::CaseInsensitiveOption);
|
|
||||||
static const auto UrlEndRegExp = QRegularExpression("/$");
|
|
||||||
const auto displayed = "https://" + proxy.host + "/";
|
|
||||||
const auto parsed = QUrl::fromUserInput(displayed);
|
|
||||||
const auto displayUrl = !UrlClickHandler::IsSuspicious(displayed)
|
|
||||||
? displayed
|
|
||||||
: parsed.isValid()
|
|
||||||
? QString::fromUtf8(parsed.toEncoded())
|
|
||||||
: UrlClickHandler::ShowEncoded(displayed);
|
|
||||||
const auto displayServer = QString(
|
|
||||||
displayUrl
|
|
||||||
).replace(
|
|
||||||
UrlStartRegExp,
|
|
||||||
QString()
|
|
||||||
).replace(UrlEndRegExp, QString());
|
|
||||||
const auto text = tr::lng_sure_enable_socks(
|
|
||||||
tr::now,
|
|
||||||
lt_server,
|
|
||||||
displayServer,
|
|
||||||
lt_port,
|
|
||||||
QString::number(proxy.port))
|
|
||||||
+ (proxy.type == Type::Mtproto
|
|
||||||
? "\n\n" + tr::lng_proxy_sponsor_warning(tr::now)
|
|
||||||
: QString());
|
|
||||||
auto callback = [=](Fn<void()> &&close) {
|
|
||||||
auto &proxies = Core::App().settings().proxy().list();
|
|
||||||
if (!ranges::contains(proxies, proxy)) {
|
|
||||||
proxies.push_back(proxy);
|
|
||||||
}
|
|
||||||
Core::App().setCurrentProxy(
|
|
||||||
proxy,
|
|
||||||
ProxyData::Settings::Enabled);
|
|
||||||
Local::writeSettings();
|
|
||||||
close();
|
|
||||||
};
|
|
||||||
Ui::show(
|
|
||||||
Ui::MakeConfirmBox({
|
|
||||||
.text = text,
|
|
||||||
.confirmed = std::move(callback),
|
|
||||||
.confirmText = tr::lng_sure_enable(),
|
|
||||||
}),
|
|
||||||
Ui::LayerOption::KeepOther);
|
|
||||||
} else {
|
|
||||||
Ui::show(Ui::MakeInformBox(
|
|
||||||
(proxy.status() == ProxyData::Status::Unsupported
|
(proxy.status() == ProxyData::Status::Unsupported
|
||||||
? tr::lng_proxy_unsupported(tr::now)
|
? tr::lng_proxy_unsupported(tr::now)
|
||||||
: tr::lng_proxy_invalid(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);
|
||||||
|
static const auto UrlEndRegExp = QRegularExpression("/$");
|
||||||
|
const auto displayed = "https://" + proxy.host + "/";
|
||||||
|
const auto parsed = QUrl::fromUserInput(displayed);
|
||||||
|
const auto displayUrl = !UrlClickHandler::IsSuspicious(displayed)
|
||||||
|
? displayed
|
||||||
|
: parsed.isValid()
|
||||||
|
? QString::fromUtf8(parsed.toEncoded())
|
||||||
|
: UrlClickHandler::ShowEncoded(displayed);
|
||||||
|
const auto displayServer = QString(
|
||||||
|
displayUrl
|
||||||
|
).replace(
|
||||||
|
UrlStartRegExp,
|
||||||
|
QString()
|
||||||
|
).replace(UrlEndRegExp, QString());
|
||||||
|
const auto text = tr::lng_sure_enable_socks(
|
||||||
|
tr::now,
|
||||||
|
lt_server,
|
||||||
|
displayServer,
|
||||||
|
lt_port,
|
||||||
|
QString::number(proxy.port))
|
||||||
|
+ (proxy.type == Type::Mtproto
|
||||||
|
? "\n\n" + tr::lng_proxy_sponsor_warning(tr::now)
|
||||||
|
: QString());
|
||||||
|
auto callback = [=](Fn<void()> &&close) {
|
||||||
|
auto &proxies = Core::App().settings().proxy().list();
|
||||||
|
if (!ranges::contains(proxies, proxy)) {
|
||||||
|
proxies.push_back(proxy);
|
||||||
|
}
|
||||||
|
Core::App().setCurrentProxy(
|
||||||
|
proxy,
|
||||||
|
ProxyData::Settings::Enabled);
|
||||||
|
Local::writeSettings();
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
auto box = Ui::MakeConfirmBox({
|
||||||
|
.text = text,
|
||||||
|
.confirmed = std::move(callback),
|
||||||
|
.confirmText = tr::lng_sure_enable(),
|
||||||
|
});
|
||||||
|
if (controller) {
|
||||||
|
controller->uiShow()->showBox(std::move(box));
|
||||||
|
} else {
|
||||||
|
Ui::show(std::move(box));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue