mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
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:
parent
c722f085d0
commit
991892ee76
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
## Unversioned
|
## Unversioned
|
||||||
|
|
||||||
|
- Minor: Added `/openurl` command. Usage: `/openurl <URL>`. Opens the provided URL in the browser. (#2461, #2926)
|
||||||
|
|
||||||
## 2.3.3
|
## 2.3.3
|
||||||
|
|
||||||
- Major: Added username autocompletion popup menu when typing usernames with an @ prefix. (#1979, #2866)
|
- Major: Added username autocompletion popup menu when typing usernames with an @ prefix. (#1979, #2866)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "util/CombinePath.hpp"
|
#include "util/CombinePath.hpp"
|
||||||
#include "util/FormatTime.hpp"
|
#include "util/FormatTime.hpp"
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
|
#include "util/IncognitoBrowser.hpp"
|
||||||
#include "util/StreamLink.hpp"
|
#include "util/StreamLink.hpp"
|
||||||
#include "util/Twitch.hpp"
|
#include "util/Twitch.hpp"
|
||||||
#include "widgets/Window.hpp"
|
#include "widgets/Window.hpp"
|
||||||
|
@ -786,6 +787,39 @@ void CommandController::initialize(Settings &, Paths &paths)
|
||||||
}
|
}
|
||||||
return "";
|
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()
|
void CommandController::save()
|
||||||
|
|
|
@ -84,12 +84,14 @@ bool supportsIncognitoLinks()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void openLinkIncognito(const QString &link)
|
bool openLinkIncognito(const QString &link)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
auto command = getCommand(link);
|
auto command = getCommand(link);
|
||||||
|
|
||||||
QProcess::startDetached(command);
|
return QProcess::startDetached(command);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
bool supportsIncognitoLinks();
|
bool supportsIncognitoLinks();
|
||||||
void openLinkIncognito(const QString &link);
|
bool openLinkIncognito(const QString &link);
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
Loading…
Reference in a new issue