Allow navigation to external links
This commit is contained in:
parent
77300ed178
commit
58ecbbc6f4
2 changed files with 26 additions and 0 deletions
|
@ -26,6 +26,7 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
|
|||
settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
|
||||
settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture,
|
||||
false);
|
||||
settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false);
|
||||
|
||||
setUrl(QUrl("https://discord.com/app"));
|
||||
|
||||
|
@ -85,6 +86,18 @@ bool DiscordPage::acceptNavigationRequest(const QUrl &url,
|
|||
return true;
|
||||
};
|
||||
|
||||
bool ExternalPage::acceptNavigationRequest(const QUrl &url,
|
||||
QWebEnginePage::NavigationType type,
|
||||
bool isMainFrame) {
|
||||
QDesktopServices::openUrl(url);
|
||||
deleteLater();
|
||||
return false;
|
||||
}
|
||||
|
||||
QWebEnginePage *DiscordPage::createWindow(QWebEnginePage::WebWindowType type) {
|
||||
return new ExternalPage;
|
||||
}
|
||||
|
||||
void DiscordPage::stopVirtmic() {
|
||||
if (m_virtmicProcess.state() == QProcess::Running) {
|
||||
qDebug() << "[virtmic] Stopping Virtmic";
|
||||
|
|
|
@ -19,6 +19,7 @@ private:
|
|||
bool acceptNavigationRequest(const QUrl &url,
|
||||
QWebEnginePage::NavigationType type,
|
||||
bool isMainFrame) override;
|
||||
QWebEnginePage *createWindow(QWebEnginePage::WebWindowType type) override;
|
||||
void
|
||||
javaScriptConsoleMessage(QWebEnginePage::JavaScriptConsoleMessageLevel level,
|
||||
const QString &message, int lineNumber,
|
||||
|
@ -32,3 +33,15 @@ private Q_SLOTS:
|
|||
QWebEnginePage::Feature feature);
|
||||
void startStream(QString target, uint width, uint height, uint frameRate);
|
||||
};
|
||||
|
||||
// Will immediately get destroyed again but is needed for navigation to
|
||||
// target="_blank" links, since QWebEnginePage::newWindowRequested is
|
||||
// only available sinec Qt 6.3.
|
||||
class ExternalPage : public QWebEnginePage {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool acceptNavigationRequest(const QUrl &url,
|
||||
QWebEnginePage::NavigationType type,
|
||||
bool isMainFrame) override;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue