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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user