From d2bfc032f8ed2fb680d293e2c6ea28ccc025a0aa Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 19 May 2019 15:15:00 -0400 Subject: [PATCH] Added support for the additional web [8.0.0+] functionality: webConfigSetMediaPlayerUi and webReplyGetMediaPlayerAutoClosedByCompletion. Various other changes. --- nx/include/switch/applets/web.h | 37 ++++++++++++++++++++++++++------- nx/source/applets/web.c | 34 ++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/nx/include/switch/applets/web.h b/nx/include/switch/applets/web.h index f099b217..69bf81b8 100644 --- a/nx/include/switch/applets/web.h +++ b/nx/include/switch/applets/web.h @@ -99,6 +99,7 @@ typedef struct { /// Common container struct for applets' reply data, from the output storage. typedef struct { bool type; ///< Type of reply: false = ret, true = storage. + WebShimKind shimKind; ///< ShimKind WebCommonReturnValue ret; ///< Reply data for reply=false. WebCommonTLVStorage storage; ///< Reply data for reply=true. } WebCommonReply; @@ -173,18 +174,22 @@ typedef enum { WebArgType_BootFooterButton = 0x3E, ///< [6.0.0+] Array of \ref WebBootFooterButtonEntry with 0x10 entries. WebArgType_OverrideWebAudioVolume = 0x3F, ///< [6.0.0+] float WebArgType_OverrideMediaAudioVolume = 0x40, ///< [6.0.0+] float + WebArgType_SessionBootMode = 0x41, ///< [7.0.0+] u32 enum WebSessionBootMode + WebArgType_SessionFlag = 0x42, ///< [7.0.0+] u8 bool, enables using WebSession when set. + WebArgType_MediaPlayerUi = 0x43, ///< [8.0.0+] u8 bool } WebArgType; /// Types for \ref WebArgTLV, output storage. typedef enum { - WebReplyType_ExitReason = 0x1, ///< [3.0.0+] u32 ShareExitReason - WebReplyType_LastUrl = 0x2, ///< [3.0.0+] string - WebReplyType_LastUrlSize = 0x3, ///< [3.0.0+] u64 - WebReplyType_SharePostResult = 0x4, ///< [3.0.0+] u32 SharePostResult - WebReplyType_PostServiceName = 0x5, ///< [3.0.0+] string - WebReplyType_PostServiceNameSize = 0x6, ///< [3.0.0+] u64 - WebReplyType_PostId = 0x7, ///< [3.0.0+] string - WebReplyType_PostIdSize = 0x8, ///< [3.0.0+] u64 + WebReplyType_ExitReason = 0x1, ///< [3.0.0+] u32 ExitReason + WebReplyType_LastUrl = 0x2, ///< [3.0.0+] string + WebReplyType_LastUrlSize = 0x3, ///< [3.0.0+] u64 + WebReplyType_SharePostResult = 0x4, ///< [3.0.0+] u32 SharePostResult + WebReplyType_PostServiceName = 0x5, ///< [3.0.0+] string + WebReplyType_PostServiceNameSize = 0x6, ///< [3.0.0+] u64 + WebReplyType_PostId = 0x7, ///< [3.0.0+] string + WebReplyType_PostIdSize = 0x8, ///< [3.0.0+] u64 + WebReplyType_MediaPlayerAutoClosedByCompletion = 0x9, ///< [8.0.0+] u8 bool } WebReplyType; /// This controls the kind of content to mount with Offline-applet. @@ -642,6 +647,14 @@ Result webConfigSetOverrideWebAudioVolume(WebCommonConfig* config, float value); */ Result webConfigSetOverrideMediaAudioVolume(WebCommonConfig* config, float value); +/** + * @brief Sets whether MediaPlayerUi is enabled. + * @note Only available with config created by \ref webOfflineCreate on [8.0.0+]. + * @param config WebCommonConfig object. + * @param flag Flag + */ +Result webConfigSetMediaPlayerUi(WebCommonConfig* config, bool flag); + /** * @brief Launches the {web applet} with the specified config and waits for it to exit. * @param config WebCommonConfig object. @@ -703,3 +716,11 @@ Result webReplyGetPostServiceName(WebCommonReply *reply, char *outstr, size_t ou */ Result webReplyGetPostId(WebCommonReply *reply, char *outstr, size_t outstr_maxsize, size_t *out_size); +/** + * @brief Gets the MediaPlayerAutoClosedByCompletion flag from the specified reply. + * @note Only available with reply data from Web on [8.0.0+]. + * @param reply WebCommonReply object. + * @param flag Output flag + */ +Result webReplyGetMediaPlayerAutoClosedByCompletion(WebCommonReply *reply, bool *flag); + diff --git a/nx/source/applets/web.c b/nx/source/applets/web.c index ee5bdc77..50878008 100644 --- a/nx/source/applets/web.c +++ b/nx/source/applets/web.c @@ -79,7 +79,9 @@ static void _webArgInitialize(WebCommonConfig* config, AppletId appletid, WebShi config->appletid = appletid; u32 hosver = hosversionGet(); - if (hosver >= MAKEHOSVERSION(6,0,0)) + if (hosver >= MAKEHOSVERSION(8,0,0)) + config->version = 0x80000; + else if (hosver >= MAKEHOSVERSION(6,0,0)) config->version = 0x60000; else if (hosver >= MAKEHOSVERSION(5,0,0)) config->version = 0x50000; @@ -685,14 +687,25 @@ Result webConfigSetOverrideMediaAudioVolume(WebCommonConfig* config, float value return _webConfigSetFloat(config, WebArgType_OverrideMediaAudioVolume, value); } +Result webConfigSetMediaPlayerUi(WebCommonConfig* config, bool flag) { + if (_webGetShimKind(config) != WebShimKind_Offline) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (hosversionBefore(8,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _webConfigSetFlag(config, WebArgType_MediaPlayerUi, flag); +} + Result webConfigShow(WebCommonConfig* config, WebCommonReply *out) { void* reply = NULL; size_t size = 0; + WebShimKind shimKind = _webGetShimKind(config); if (out) { // ShareApplet on [3.0.0+] uses TLV storage for the reply, while older versions + everything else uses *ReturnValue. + // Web also uses TLV storage for the reply on [8.0.0+]. memset(out, 0, sizeof(*out)); - if (config->version >= 0x30000 && _webGetShimKind(config) == WebShimKind_Share) out->type = true; + out->shimKind = shimKind; + + if (config->version >= 0x30000 && shimKind == WebShimKind_Share) out->type = true; + if (config->version >= 0x80000 && shimKind == WebShimKind_Web) out->type = true; if (!out->type) { reply = &out->ret; @@ -758,6 +771,8 @@ Result webReplyGetLastUrl(WebCommonReply *reply, char *outstr, size_t outstr_max } Result webReplyGetSharePostResult(WebCommonReply *reply, u32 *sharePostResult) { + if (reply->shimKind != WebShimKind_Share) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + if (reply->type) { return _webTLVRead(&reply->storage, WebReplyType_SharePostResult, sharePostResult, sizeof(*sharePostResult)); } @@ -765,10 +780,25 @@ Result webReplyGetSharePostResult(WebCommonReply *reply, u32 *sharePostResult) { } Result webReplyGetPostServiceName(WebCommonReply *reply, char *outstr, size_t outstr_maxsize, size_t *out_size) { + if (reply->shimKind != WebShimKind_Share) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + return _webReplyGetString(reply, WebReplyType_PostServiceName, WebReplyType_PostServiceNameSize, outstr, outstr_maxsize, out_size); } Result webReplyGetPostId(WebCommonReply *reply, char *outstr, size_t outstr_maxsize, size_t *out_size) { + if (reply->shimKind != WebShimKind_Share) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + return _webReplyGetString(reply, WebReplyType_PostId, WebReplyType_PostIdSize, outstr, outstr_maxsize, out_size); } +Result webReplyGetMediaPlayerAutoClosedByCompletion(WebCommonReply *reply, bool *flag) { + Result rc=0; + u8 tmpflag=0; + if (!reply->type) return MAKERESULT(Module_Libnx, LibnxError_BadInput); + if (reply->shimKind != WebShimKind_Web) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + rc = _webTLVRead(&reply->storage, WebReplyType_MediaPlayerAutoClosedByCompletion, &tmpflag, sizeof(tmpflag)); + if (R_SUCCEEDED(rc) && flag) *flag = tmpflag!=0; + return rc; +} +