mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-06 20:13:12 +02:00
Fixed possible crash when paste invalid proxy link to proxy box.
This commit is contained in:
parent
8ff6f9af45
commit
52bb189996
1 changed files with 29 additions and 7 deletions
|
@ -111,6 +111,13 @@ void AddProxyFromClipboard(
|
||||||
QGuiApplication::clipboard()->text());
|
QGuiApplication::clipboard()->text());
|
||||||
const auto isSingle = maybeUrls.size() == 1;
|
const auto isSingle = maybeUrls.size() == 1;
|
||||||
|
|
||||||
|
enum class Result {
|
||||||
|
Success,
|
||||||
|
Failed,
|
||||||
|
Unsupported,
|
||||||
|
Invalid,
|
||||||
|
};
|
||||||
|
|
||||||
const auto proceedUrl = [=](const auto &local) {
|
const auto proceedUrl = [=](const auto &local) {
|
||||||
const auto command = base::StringViewMid(
|
const auto command = base::StringViewMid(
|
||||||
local,
|
local,
|
||||||
|
@ -146,6 +153,11 @@ void AddProxyFromClipboard(
|
||||||
match->captured(1),
|
match->captured(1),
|
||||||
qthelp::UrlParamNameTransform::ToLower);
|
qthelp::UrlParamNameTransform::ToLower);
|
||||||
const auto proxy = ProxyDataFromFields(type, fields);
|
const auto proxy = ProxyDataFromFields(type, fields);
|
||||||
|
if (!proxy) {
|
||||||
|
return (proxy.status() == ProxyData::Status::Unsupported)
|
||||||
|
? Result::Unsupported
|
||||||
|
: Result::Invalid;
|
||||||
|
}
|
||||||
const auto contains = controller->contains(proxy);
|
const auto contains = controller->contains(proxy);
|
||||||
const auto toast = (contains
|
const auto toast = (contains
|
||||||
? tr::lng_proxy_add_from_clipboard_existing_toast
|
? tr::lng_proxy_add_from_clipboard_existing_toast
|
||||||
|
@ -158,19 +170,29 @@ void AddProxyFromClipboard(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
return false;
|
return Result::Failed;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto success = false;
|
auto success = Result::Failed;
|
||||||
for (const auto &maybeUrl : maybeUrls) {
|
for (const auto &maybeUrl : maybeUrls) {
|
||||||
success |= proceedUrl(Core::TryConvertUrlToLocal(maybeUrl));
|
const auto result = proceedUrl(Core::TryConvertUrlToLocal(maybeUrl));
|
||||||
|
if (success != Result::Success) {
|
||||||
|
success = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (success != Result::Success) {
|
||||||
|
if (success == Result::Failed) {
|
||||||
show->showToast(
|
show->showToast(
|
||||||
tr::lng_proxy_add_from_clipboard_failed_toast(tr::now));
|
tr::lng_proxy_add_from_clipboard_failed_toast(tr::now));
|
||||||
|
} else {
|
||||||
|
show->showBox(Ui::MakeInformBox(
|
||||||
|
(success == Result::Unsupported
|
||||||
|
? tr::lng_proxy_unsupported(tr::now)
|
||||||
|
: tr::lng_proxy_invalid(tr::now))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue