2020-11-08 06:17:12 -06:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
2018-12-24 15:22:49 -06:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
2021-10-15 17:48:50 -05:00
|
|
|
#include <QApplication>
|
2020-11-30 07:31:26 -06:00
|
|
|
#include <QKeyEvent>
|
|
|
|
|
|
|
|
#include <QWebEngineProfile>
|
|
|
|
#include <QWebEngineScript>
|
|
|
|
#include <QWebEngineScriptCollection>
|
|
|
|
#include <QWebEngineSettings>
|
|
|
|
#include <QWebEngineUrlScheme>
|
|
|
|
#endif
|
|
|
|
|
2021-05-25 18:32:56 -05:00
|
|
|
#include "common/fs/path_util.h"
|
2021-09-20 20:19:28 -05:00
|
|
|
#include "common/param_package.h"
|
2020-11-30 07:31:26 -06:00
|
|
|
#include "core/core.h"
|
2021-10-24 01:02:56 -05:00
|
|
|
#include "core/hid/hid_types.h"
|
2021-09-20 15:02:01 -05:00
|
|
|
#include "core/hid/input_interpreter.h"
|
2021-09-20 20:19:28 -05:00
|
|
|
#include "input_common/drivers/keyboard.h"
|
2020-11-30 21:25:01 -06:00
|
|
|
#include "input_common/main.h"
|
2021-07-13 23:29:12 -05:00
|
|
|
#include "yuzu/applets/qt_web_browser.h"
|
|
|
|
#include "yuzu/applets/qt_web_browser_scripts.h"
|
2018-12-24 15:22:49 -06:00
|
|
|
#include "yuzu/main.h"
|
2020-11-30 07:31:26 -06:00
|
|
|
#include "yuzu/util/url_request_interceptor.h"
|
|
|
|
|
|
|
|
#ifdef YUZU_USE_QT_WEB_ENGINE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-10-24 01:02:56 -05:00
|
|
|
constexpr int HIDButtonToKey(Core::HID::NpadButton button) {
|
2020-11-30 07:31:26 -06:00
|
|
|
switch (button) {
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::Left:
|
|
|
|
case Core::HID::NpadButton::StickLLeft:
|
2020-11-30 07:31:26 -06:00
|
|
|
return Qt::Key_Left;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::Up:
|
|
|
|
case Core::HID::NpadButton::StickLUp:
|
2020-11-30 07:31:26 -06:00
|
|
|
return Qt::Key_Up;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::Right:
|
|
|
|
case Core::HID::NpadButton::StickLRight:
|
2020-11-30 07:31:26 -06:00
|
|
|
return Qt::Key_Right;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::Down:
|
|
|
|
case Core::HID::NpadButton::StickLDown:
|
2020-11-30 07:31:26 -06:00
|
|
|
return Qt::Key_Down;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2020-11-30 21:25:01 -06:00
|
|
|
QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system,
|
|
|
|
InputCommon::InputSubsystem* input_subsystem_)
|
|
|
|
: QWebEngineView(parent), input_subsystem{input_subsystem_},
|
|
|
|
url_interceptor(std::make_unique<UrlRequestInterceptor>()),
|
2020-12-08 05:20:45 -06:00
|
|
|
input_interpreter(std::make_unique<InputInterpreter>(system)),
|
|
|
|
default_profile{QWebEngineProfile::defaultProfile()},
|
|
|
|
global_settings{QWebEngineSettings::globalSettings()} {
|
2021-09-23 16:21:00 -05:00
|
|
|
default_profile->setPersistentStoragePath(QString::fromStdString(Common::FS::PathToUTF8String(
|
|
|
|
Common::FS::GetYuzuPath(Common::FS::YuzuPath::YuzuDir) / "qtwebengine")));
|
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
QWebEngineScript gamepad;
|
|
|
|
QWebEngineScript window_nx;
|
|
|
|
|
|
|
|
gamepad.setName(QStringLiteral("gamepad_script.js"));
|
|
|
|
window_nx.setName(QStringLiteral("window_nx_script.js"));
|
|
|
|
|
|
|
|
gamepad.setSourceCode(QString::fromStdString(GAMEPAD_SCRIPT));
|
|
|
|
window_nx.setSourceCode(QString::fromStdString(WINDOW_NX_SCRIPT));
|
|
|
|
|
|
|
|
gamepad.setInjectionPoint(QWebEngineScript::DocumentCreation);
|
|
|
|
window_nx.setInjectionPoint(QWebEngineScript::DocumentCreation);
|
|
|
|
|
|
|
|
gamepad.setWorldId(QWebEngineScript::MainWorld);
|
|
|
|
window_nx.setWorldId(QWebEngineScript::MainWorld);
|
|
|
|
|
|
|
|
gamepad.setRunsOnSubFrames(true);
|
|
|
|
window_nx.setRunsOnSubFrames(true);
|
|
|
|
|
|
|
|
default_profile->scripts()->insert(gamepad);
|
|
|
|
default_profile->scripts()->insert(window_nx);
|
|
|
|
|
|
|
|
default_profile->setRequestInterceptor(url_interceptor.get());
|
|
|
|
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true);
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, true);
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::AllowWindowActivationFromJavaScript, true);
|
|
|
|
global_settings->setAttribute(QWebEngineSettings::ShowScrollBars, false);
|
|
|
|
|
2020-12-08 05:20:45 -06:00
|
|
|
global_settings->setFontFamily(QWebEngineSettings::StandardFont, QStringLiteral("Roboto"));
|
2020-11-30 07:31:26 -06:00
|
|
|
|
|
|
|
connect(
|
|
|
|
page(), &QWebEnginePage::windowCloseRequested, page(),
|
|
|
|
[this] {
|
|
|
|
if (page()->url() == url_interceptor->GetRequestedURL()) {
|
|
|
|
SetFinished(true);
|
2020-11-30 09:15:00 -06:00
|
|
|
SetExitReason(Service::AM::Applets::WebExitReason::WindowClosed);
|
2020-11-30 07:31:26 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
QtNXWebEngineView::~QtNXWebEngineView() {
|
|
|
|
SetFinished(true);
|
|
|
|
StopInputThread();
|
|
|
|
}
|
|
|
|
|
2021-04-28 10:32:44 -05:00
|
|
|
void QtNXWebEngineView::LoadLocalWebPage(const std::string& main_url,
|
|
|
|
const std::string& additional_args) {
|
2020-12-08 05:20:45 -06:00
|
|
|
is_local = true;
|
|
|
|
|
|
|
|
LoadExtractedFonts();
|
2021-07-17 18:10:15 -05:00
|
|
|
FocusFirstLinkElement();
|
2020-11-30 07:31:26 -06:00
|
|
|
SetUserAgent(UserAgent::WebApplet);
|
|
|
|
SetFinished(false);
|
2020-11-30 09:15:00 -06:00
|
|
|
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
|
2020-11-30 07:31:26 -06:00
|
|
|
SetLastURL("http://localhost/");
|
|
|
|
StartInputThread();
|
|
|
|
|
2021-04-28 10:32:44 -05:00
|
|
|
load(QUrl(QUrl::fromLocalFile(QString::fromStdString(main_url)).toString() +
|
|
|
|
QString::fromStdString(additional_args)));
|
2020-11-30 07:31:26 -06:00
|
|
|
}
|
|
|
|
|
2021-04-28 10:32:44 -05:00
|
|
|
void QtNXWebEngineView::LoadExternalWebPage(const std::string& main_url,
|
|
|
|
const std::string& additional_args) {
|
2020-12-08 05:20:45 -06:00
|
|
|
is_local = false;
|
|
|
|
|
2021-07-17 18:10:15 -05:00
|
|
|
FocusFirstLinkElement();
|
2020-12-08 05:20:45 -06:00
|
|
|
SetUserAgent(UserAgent::WebApplet);
|
|
|
|
SetFinished(false);
|
|
|
|
SetExitReason(Service::AM::Applets::WebExitReason::EndButtonPressed);
|
|
|
|
SetLastURL("http://localhost/");
|
|
|
|
StartInputThread();
|
|
|
|
|
2021-04-28 10:32:44 -05:00
|
|
|
load(QUrl(QString::fromStdString(main_url) + QString::fromStdString(additional_args)));
|
2020-12-08 05:20:45 -06:00
|
|
|
}
|
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
void QtNXWebEngineView::SetUserAgent(UserAgent user_agent) {
|
|
|
|
const QString user_agent_str = [user_agent] {
|
|
|
|
switch (user_agent) {
|
|
|
|
case UserAgent::WebApplet:
|
|
|
|
default:
|
|
|
|
return QStringLiteral("WebApplet");
|
|
|
|
case UserAgent::ShopN:
|
|
|
|
return QStringLiteral("ShopN");
|
|
|
|
case UserAgent::LoginApplet:
|
|
|
|
return QStringLiteral("LoginApplet");
|
|
|
|
case UserAgent::ShareApplet:
|
|
|
|
return QStringLiteral("ShareApplet");
|
|
|
|
case UserAgent::LobbyApplet:
|
|
|
|
return QStringLiteral("LobbyApplet");
|
|
|
|
case UserAgent::WifiWebAuthApplet:
|
|
|
|
return QStringLiteral("WifiWebAuthApplet");
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
QWebEngineProfile::defaultProfile()->setHttpUserAgent(
|
|
|
|
QStringLiteral("Mozilla/5.0 (Nintendo Switch; %1) AppleWebKit/606.4 "
|
|
|
|
"(KHTML, like Gecko) NF/6.0.1.15.4 NintendoBrowser/5.1.0.20389")
|
|
|
|
.arg(user_agent_str));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QtNXWebEngineView::IsFinished() const {
|
|
|
|
return finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::SetFinished(bool finished_) {
|
|
|
|
finished = finished_;
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:15:00 -06:00
|
|
|
Service::AM::Applets::WebExitReason QtNXWebEngineView::GetExitReason() const {
|
2020-11-30 07:31:26 -06:00
|
|
|
return exit_reason;
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:15:00 -06:00
|
|
|
void QtNXWebEngineView::SetExitReason(Service::AM::Applets::WebExitReason exit_reason_) {
|
2020-11-30 07:31:26 -06:00
|
|
|
exit_reason = exit_reason_;
|
|
|
|
}
|
2018-12-24 15:22:49 -06:00
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
const std::string& QtNXWebEngineView::GetLastURL() const {
|
|
|
|
return last_url;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::SetLastURL(std::string last_url_) {
|
|
|
|
last_url = std::move(last_url_);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QtNXWebEngineView::GetCurrentURL() const {
|
|
|
|
return url_interceptor->GetRequestedURL().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::hide() {
|
|
|
|
SetFinished(true);
|
|
|
|
StopInputThread();
|
|
|
|
|
|
|
|
QWidget::hide();
|
|
|
|
}
|
|
|
|
|
2020-11-30 21:25:01 -06:00
|
|
|
void QtNXWebEngineView::keyPressEvent(QKeyEvent* event) {
|
2020-12-08 05:20:45 -06:00
|
|
|
if (is_local) {
|
|
|
|
input_subsystem->GetKeyboard()->PressKey(event->key());
|
|
|
|
}
|
2020-11-30 21:25:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::keyReleaseEvent(QKeyEvent* event) {
|
2020-12-08 05:20:45 -06:00
|
|
|
if (is_local) {
|
|
|
|
input_subsystem->GetKeyboard()->ReleaseKey(event->key());
|
|
|
|
}
|
2020-11-30 21:25:01 -06:00
|
|
|
}
|
|
|
|
|
2021-10-24 01:02:56 -05:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 07:31:26 -06:00
|
|
|
void QtNXWebEngineView::HandleWindowFooterButtonPressedOnce() {
|
2021-10-24 01:02:56 -05:00
|
|
|
const auto f = [this](Core::HID::NpadButton button) {
|
2020-11-30 07:31:26 -06:00
|
|
|
if (input_interpreter->IsButtonPressedOnce(button)) {
|
|
|
|
page()->runJavaScript(
|
|
|
|
QStringLiteral("yuzu_key_callbacks[%1] == null;").arg(static_cast<u8>(button)),
|
2021-07-17 19:44:20 -05:00
|
|
|
[this, button](const QVariant& variant) {
|
2020-11-30 07:31:26 -06:00
|
|
|
if (variant.toBool()) {
|
|
|
|
switch (button) {
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::A:
|
2020-11-30 07:31:26 -06:00
|
|
|
SendMultipleKeyPressEvents<Qt::Key_A, Qt::Key_Space, Qt::Key_Return>();
|
|
|
|
break;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::B:
|
2020-11-30 07:31:26 -06:00
|
|
|
SendKeyPressEvent(Qt::Key_B);
|
|
|
|
break;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::X:
|
2020-11-30 07:31:26 -06:00
|
|
|
SendKeyPressEvent(Qt::Key_X);
|
|
|
|
break;
|
2021-10-24 01:02:56 -05:00
|
|
|
case Core::HID::NpadButton::Y:
|
2020-11-30 07:31:26 -06:00
|
|
|
SendKeyPressEvent(Qt::Key_Y);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
page()->runJavaScript(
|
|
|
|
QStringLiteral("if (yuzu_key_callbacks[%1] != null) { yuzu_key_callbacks[%1](); }")
|
|
|
|
.arg(static_cast<u8>(button)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(f(T), ...);
|
|
|
|
}
|
|
|
|
|
2021-10-24 01:02:56 -05:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 07:31:26 -06:00
|
|
|
void QtNXWebEngineView::HandleWindowKeyButtonPressedOnce() {
|
2021-10-24 01:02:56 -05:00
|
|
|
const auto f = [this](Core::HID::NpadButton button) {
|
2020-11-30 07:31:26 -06:00
|
|
|
if (input_interpreter->IsButtonPressedOnce(button)) {
|
|
|
|
SendKeyPressEvent(HIDButtonToKey(button));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(f(T), ...);
|
|
|
|
}
|
|
|
|
|
2021-10-24 01:02:56 -05:00
|
|
|
template <Core::HID::NpadButton... T>
|
2020-11-30 07:31:26 -06:00
|
|
|
void QtNXWebEngineView::HandleWindowKeyButtonHold() {
|
2021-10-24 01:02:56 -05:00
|
|
|
const auto f = [this](Core::HID::NpadButton button) {
|
2020-11-30 07:31:26 -06:00
|
|
|
if (input_interpreter->IsButtonHeld(button)) {
|
|
|
|
SendKeyPressEvent(HIDButtonToKey(button));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
(f(T), ...);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::SendKeyPressEvent(int key) {
|
|
|
|
if (key == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCoreApplication::postEvent(focusProxy(),
|
|
|
|
new QKeyEvent(QKeyEvent::KeyPress, key, Qt::NoModifier));
|
|
|
|
QCoreApplication::postEvent(focusProxy(),
|
|
|
|
new QKeyEvent(QKeyEvent::KeyRelease, key, Qt::NoModifier));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::StartInputThread() {
|
|
|
|
if (input_thread_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_thread_running = true;
|
|
|
|
input_thread = std::thread(&QtNXWebEngineView::InputThread, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::StopInputThread() {
|
2020-12-08 05:20:45 -06:00
|
|
|
if (is_local) {
|
|
|
|
QWidget::releaseKeyboard();
|
|
|
|
}
|
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
input_thread_running = false;
|
|
|
|
if (input_thread.joinable()) {
|
|
|
|
input_thread.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtNXWebEngineView::InputThread() {
|
|
|
|
// Wait for 1 second before allowing any inputs to be processed.
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
2020-12-08 05:20:45 -06:00
|
|
|
if (is_local) {
|
|
|
|
QWidget::grabKeyboard();
|
|
|
|
}
|
2020-11-30 21:25:01 -06:00
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
while (input_thread_running) {
|
|
|
|
input_interpreter->PollInput();
|
|
|
|
|
2021-10-24 01:02:56 -05:00
|
|
|
HandleWindowFooterButtonPressedOnce<Core::HID::NpadButton::A, Core::HID::NpadButton::B,
|
|
|
|
Core::HID::NpadButton::X, Core::HID::NpadButton::Y,
|
|
|
|
Core::HID::NpadButton::L, Core::HID::NpadButton::R>();
|
|
|
|
|
|
|
|
HandleWindowKeyButtonPressedOnce<
|
|
|
|
Core::HID::NpadButton::Left, Core::HID::NpadButton::Up, Core::HID::NpadButton::Right,
|
|
|
|
Core::HID::NpadButton::Down, Core::HID::NpadButton::StickLLeft,
|
|
|
|
Core::HID::NpadButton::StickLUp, Core::HID::NpadButton::StickLRight,
|
|
|
|
Core::HID::NpadButton::StickLDown>();
|
|
|
|
|
|
|
|
HandleWindowKeyButtonHold<
|
|
|
|
Core::HID::NpadButton::Left, Core::HID::NpadButton::Up, Core::HID::NpadButton::Right,
|
|
|
|
Core::HID::NpadButton::Down, Core::HID::NpadButton::StickLLeft,
|
|
|
|
Core::HID::NpadButton::StickLUp, Core::HID::NpadButton::StickLRight,
|
|
|
|
Core::HID::NpadButton::StickLDown>();
|
2020-11-30 07:31:26 -06:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 05:20:45 -06:00
|
|
|
void QtNXWebEngineView::LoadExtractedFonts() {
|
|
|
|
QWebEngineScript nx_font_css;
|
|
|
|
QWebEngineScript load_nx_font;
|
|
|
|
|
2021-05-25 18:32:56 -05:00
|
|
|
auto fonts_dir_str = Common::FS::PathToUTF8String(
|
|
|
|
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "fonts/");
|
|
|
|
|
|
|
|
std::replace(fonts_dir_str.begin(), fonts_dir_str.end(), '\\', '/');
|
|
|
|
|
|
|
|
const auto fonts_dir = QString::fromStdString(fonts_dir_str);
|
2020-12-08 05:20:45 -06:00
|
|
|
|
|
|
|
nx_font_css.setName(QStringLiteral("nx_font_css.js"));
|
|
|
|
load_nx_font.setName(QStringLiteral("load_nx_font.js"));
|
|
|
|
|
|
|
|
nx_font_css.setSourceCode(
|
|
|
|
QString::fromStdString(NX_FONT_CSS)
|
2021-05-25 18:32:56 -05:00
|
|
|
.arg(fonts_dir + QStringLiteral("FontStandard.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontChineseSimplified.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontExtendedChineseSimplified.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontChineseTraditional.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontKorean.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontNintendoExtended.ttf"))
|
|
|
|
.arg(fonts_dir + QStringLiteral("FontNintendoExtended2.ttf")));
|
2020-12-08 05:20:45 -06:00
|
|
|
load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT));
|
|
|
|
|
|
|
|
nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady);
|
|
|
|
load_nx_font.setInjectionPoint(QWebEngineScript::Deferred);
|
|
|
|
|
|
|
|
nx_font_css.setWorldId(QWebEngineScript::MainWorld);
|
|
|
|
load_nx_font.setWorldId(QWebEngineScript::MainWorld);
|
|
|
|
|
|
|
|
nx_font_css.setRunsOnSubFrames(true);
|
|
|
|
load_nx_font.setRunsOnSubFrames(true);
|
|
|
|
|
|
|
|
default_profile->scripts()->insert(nx_font_css);
|
|
|
|
default_profile->scripts()->insert(load_nx_font);
|
|
|
|
|
|
|
|
connect(
|
|
|
|
url_interceptor.get(), &UrlRequestInterceptor::FrameChanged, url_interceptor.get(),
|
|
|
|
[this] {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
|
|
page()->runJavaScript(QString::fromStdString(LOAD_NX_FONT));
|
|
|
|
},
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2021-07-17 18:10:15 -05:00
|
|
|
void QtNXWebEngineView::FocusFirstLinkElement() {
|
|
|
|
QWebEngineScript focus_link_element;
|
|
|
|
|
|
|
|
focus_link_element.setName(QStringLiteral("focus_link_element.js"));
|
|
|
|
focus_link_element.setSourceCode(QString::fromStdString(FOCUS_LINK_ELEMENT_SCRIPT));
|
|
|
|
focus_link_element.setWorldId(QWebEngineScript::MainWorld);
|
|
|
|
focus_link_element.setInjectionPoint(QWebEngineScript::Deferred);
|
|
|
|
focus_link_element.setRunsOnSubFrames(true);
|
|
|
|
default_profile->scripts()->insert(focus_link_element);
|
|
|
|
}
|
|
|
|
|
2020-11-30 07:31:26 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
QtWebBrowser::QtWebBrowser(GMainWindow& main_window) {
|
2020-12-08 05:20:45 -06:00
|
|
|
connect(this, &QtWebBrowser::MainWindowOpenWebPage, &main_window,
|
|
|
|
&GMainWindow::WebBrowserOpenWebPage, Qt::QueuedConnection);
|
2020-11-30 09:15:00 -06:00
|
|
|
connect(&main_window, &GMainWindow::WebBrowserExtractOfflineRomFS, this,
|
|
|
|
&QtWebBrowser::MainWindowExtractOfflineRomFS, Qt::QueuedConnection);
|
2020-11-30 07:31:26 -06:00
|
|
|
connect(&main_window, &GMainWindow::WebBrowserClosed, this,
|
|
|
|
&QtWebBrowser::MainWindowWebBrowserClosed, Qt::QueuedConnection);
|
|
|
|
}
|
2018-12-24 15:22:49 -06:00
|
|
|
|
|
|
|
QtWebBrowser::~QtWebBrowser() = default;
|
2020-11-30 07:31:26 -06:00
|
|
|
|
|
|
|
void QtWebBrowser::OpenLocalWebPage(
|
2021-04-28 10:32:44 -05:00
|
|
|
const std::string& local_url, std::function<void()> extract_romfs_callback_,
|
2020-12-08 05:20:45 -06:00
|
|
|
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback_) const {
|
|
|
|
extract_romfs_callback = std::move(extract_romfs_callback_);
|
|
|
|
callback = std::move(callback_);
|
2020-11-30 07:31:26 -06:00
|
|
|
|
|
|
|
const auto index = local_url.find('?');
|
|
|
|
|
|
|
|
if (index == std::string::npos) {
|
2020-12-08 05:20:45 -06:00
|
|
|
emit MainWindowOpenWebPage(local_url, "", true);
|
|
|
|
} else {
|
|
|
|
emit MainWindowOpenWebPage(local_url.substr(0, index), local_url.substr(index), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtWebBrowser::OpenExternalWebPage(
|
2021-04-28 10:32:44 -05:00
|
|
|
const std::string& external_url,
|
2020-12-08 05:20:45 -06:00
|
|
|
std::function<void(Service::AM::Applets::WebExitReason, std::string)> callback_) const {
|
|
|
|
callback = std::move(callback_);
|
|
|
|
|
|
|
|
const auto index = external_url.find('?');
|
|
|
|
|
|
|
|
if (index == std::string::npos) {
|
|
|
|
emit MainWindowOpenWebPage(external_url, "", false);
|
2020-11-30 07:31:26 -06:00
|
|
|
} else {
|
2020-12-08 05:20:45 -06:00
|
|
|
emit MainWindowOpenWebPage(external_url.substr(0, index), external_url.substr(index),
|
|
|
|
false);
|
2020-11-30 07:31:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 09:15:00 -06:00
|
|
|
void QtWebBrowser::MainWindowExtractOfflineRomFS() {
|
|
|
|
extract_romfs_callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtWebBrowser::MainWindowWebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason,
|
|
|
|
std::string last_url) {
|
2020-11-30 07:31:26 -06:00
|
|
|
callback(exit_reason, last_url);
|
|
|
|
}
|