From 491445a12f5360b5d0724495ba65f748d8bde404 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 28 May 2025 18:46:30 +0100 Subject: [PATCH] Revert "remove Web menu" This reverts commit 2d7763444e919ec15bfbad66f47a68d31a4942ca. --- sphaira/CMakeLists.txt | 1 + sphaira/include/web.hpp | 13 ++++++++++ sphaira/source/app.cpp | 7 ++++++ sphaira/source/web.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 sphaira/include/web.hpp create mode 100644 sphaira/source/web.cpp diff --git a/sphaira/CMakeLists.txt b/sphaira/CMakeLists.txt index f09b3bc..77357c3 100644 --- a/sphaira/CMakeLists.txt +++ b/sphaira/CMakeLists.txt @@ -74,6 +74,7 @@ add_executable(sphaira source/nxlink.cpp source/owo.cpp source/swkbd.cpp + source/web.cpp source/hasher.cpp source/i18n.cpp source/ftpsrv_helper.cpp diff --git a/sphaira/include/web.hpp b/sphaira/include/web.hpp new file mode 100644 index 0000000..6c98834 --- /dev/null +++ b/sphaira/include/web.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace sphaira { + +// if show_error = true, it will display popup error box on +// faliure. set this to false if you want to handle errors +// from the caller. +auto WebShow(const std::string& url, bool show_error = true) -> Result; + +} // namespace sphaira diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index 5d2e1fa..5e571bf 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -19,6 +19,7 @@ #include "defines.hpp" #include "i18n.hpp" #include "ftpsrv_helper.hpp" +#include "web.hpp" #include #include @@ -1624,6 +1625,12 @@ void App::DisplayMiscOptions(bool left_side) { App::Push(e.func(ui::menu::MenuFlag_None)); })); } + + if (App::IsApplication()) { + options->Add(std::make_shared("Web"_i18n, [](){ + WebShow("https://lite.duckduckgo.com/lite"); + })); + } } void App::DisplayAdvancedOptions(bool left_side) { diff --git a/sphaira/source/web.cpp b/sphaira/source/web.cpp new file mode 100644 index 0000000..b9390b7 --- /dev/null +++ b/sphaira/source/web.cpp @@ -0,0 +1,54 @@ +#include "web.hpp" +#include "log.hpp" +#include "defines.hpp" +#include + +namespace sphaira { + +auto WebShow(const std::string& url, bool show_error) -> Result { + // showError("Running in applet mode\nPlease launch hbmenu by holding R on an APP (e.g. a game) NOT an applet (e.g. Gallery)", "", 0); + // showError("Error: Nag active, check more details", "Browser won't launch if supernag is active\n\nUse gagorder or switch-sys-tweak (the latter is bundled with BrowseNX) to disable supernag.", 0); + // log_write("web show with url: %s\n", url.c_str()); + // return 0; + WebCommonConfig config{}; + WebCommonReply reply{}; + WebExitReason reason{}; + AccountUid account_uid{}; + char last_url[FS_MAX_PATH]{}; + size_t last_url_len{}; + + // WebBackgroundKind_Unknown1 = shows background + // WebBackgroundKind_Unknown2 = shows background faded + if (R_FAILED(accountTrySelectUserWithoutInteraction(&account_uid, false))) { log_write("failed: accountTrySelectUserWithoutInteraction\n"); } + if (R_FAILED(webPageCreate(&config, url.c_str()))) { log_write("failed: webPageCreate\n"); } + if (R_FAILED(webConfigSetWhitelist(&config, "^http"))) { log_write("failed: webConfigSetWhitelist\n"); } + if (R_FAILED(webConfigSetEcClientCert(&config, true))) { log_write("failed: webConfigSetEcClientCert\n"); } + if (R_FAILED(webConfigSetScreenShot(&config, true))) { log_write("failed: webConfigSetScreenShot\n"); } + if (R_FAILED(webConfigSetBootDisplayKind(&config, WebBootDisplayKind_Black))) { log_write("failed: webConfigSetBootDisplayKind\n"); } + if (R_FAILED(webConfigSetBackgroundKind(&config, WebBackgroundKind_Default))) { log_write("failed: webConfigSetBackgroundKind\n"); } + if (R_FAILED(webConfigSetPointer(&config, true))) { log_write("failed: webConfigSetPointer\n"); } + if (R_FAILED(webConfigSetLeftStickMode(&config, WebLeftStickMode_Pointer))) { log_write("failed: webConfigSetLeftStickMode\n"); } + // if (R_FAILED(webConfigSetBootAsMediaPlayer(&config, true))) { log_write("failed: webConfigSetBootAsMediaPlayer\n"); } + if (R_FAILED(webConfigSetJsExtension(&config, true))) { log_write("failed: webConfigSetJsExtension\n"); } + if (R_FAILED(webConfigSetMediaPlayerAutoClose(&config, true))) { log_write("failed: webConfigSetMediaPlayerAutoClose\n"); } + if (R_FAILED(webConfigSetPageCache(&config, true))) { log_write("failed: webConfigSetPageCache\n"); } + if (R_FAILED(webConfigSetFooterFixedKind(&config, WebFooterFixedKind_Hidden))) { log_write("failed: webConfigSetFooterFixedKind\n"); } + if (R_FAILED(webConfigSetPageFade(&config, true))) { log_write("failed: webConfigSetPageFade\n"); } + if (R_FAILED(webConfigSetPageScrollIndicator(&config, true))) { log_write("failed: webConfigSetPageScrollIndicator\n"); } + // if (R_FAILED(webConfigSetMediaPlayerSpeedControl(&config, true))) { log_write("failed: webConfigSetMediaPlayerSpeedControl\n"); } + if (R_FAILED(webConfigSetBootMode(&config, WebSessionBootMode_AllForeground))) { log_write("failed: webConfigSetBootMode\n"); } + if (R_FAILED(webConfigSetTransferMemory(&config, true))) { log_write("failed: webConfigSetTransferMemory\n"); } + if (R_FAILED(webConfigSetTouchEnabledOnContents(&config, true))) { log_write("failed: webConfigSetTouchEnabledOnContents\n"); } + // if (R_FAILED(webConfigSetMediaPlayerUi(&config, true))) { log_write("failed: webConfigSetMediaPlayerUi\n"); } + // if (R_FAILED(webConfigSetWebAudio(&config, true))) { log_write("failed: webConfigSetWebAudio\n"); } + if (R_FAILED(webConfigSetPageCache(&config, true))) { log_write("failed: webConfigSetPageCache\n"); } + if (R_FAILED(webConfigSetBootLoadingIcon(&config, true))) { log_write("failed: webConfigSetBootLoadingIcon\n"); } + if (R_FAILED(webConfigSetUid(&config, account_uid))) { log_write("failed: webConfigSetUid\n"); } + if (R_FAILED(webConfigShow(&config, &reply))) { log_write("failed: webConfigShow\n"); } + if (R_FAILED(webReplyGetExitReason(&reply, &reason))) { log_write("failed: webReplyGetExitReason\n"); } + if (R_FAILED(webReplyGetLastUrl(&reply, last_url, sizeof(last_url), &last_url_len))) { log_write("failed: webReplyGetLastUrl\n"); } + log_write("last url: %s\n", last_url); + R_SUCCEED(); +} + +} // namespace sphaira