Add /openurl command (#2926)

Usage: `/openurl <URL>`. Opens the provided URL in the browser.

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Tal Neoran
2021-06-27 14:40:44 +03:00
committed by GitHub
parent c722f085d0
commit 991892ee76
4 changed files with 41 additions and 3 deletions
@@ -18,6 +18,7 @@
#include "util/CombinePath.hpp"
#include "util/FormatTime.hpp"
#include "util/Helpers.hpp"
#include "util/IncognitoBrowser.hpp"
#include "util/StreamLink.hpp"
#include "util/Twitch.hpp"
#include "widgets/Window.hpp"
@@ -786,6 +787,39 @@ void CommandController::initialize(Settings &, Paths &paths)
}
return "";
});
this->registerCommand("/openurl", [](const QStringList &words,
const ChannelPtr channel) {
if (words.size() < 2)
{
channel->addMessage(makeSystemMessage("Usage: /openurl <URL>."));
return "";
}
QUrl url = QUrl::fromUserInput(words.mid(1).join(" "));
if (!url.isValid())
{
channel->addMessage(makeSystemMessage("Invalid URL specified."));
return "";
}
bool res = false;
if (supportsIncognitoLinks() && getSettings()->openLinksIncognito)
{
res = openLinkIncognito(url.toString(QUrl::FullyEncoded));
}
else
{
res = QDesktopServices::openUrl(url);
}
if (!res)
{
channel->addMessage(makeSystemMessage("Could not open URL."));
}
return "";
});
}
void CommandController::save()