Skip to content

feat: Add browser applet #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libctru/include/3ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern "C" {

#include <3ds/applets/swkbd.h>
#include <3ds/applets/error.h>

#include <3ds/applets/browser.h>
#include <3ds/applets/miiselector.h>

#include <3ds/archive.h>
Expand Down
12 changes: 12 additions & 0 deletions libctru/include/3ds/applets/browser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @file browser.h
* @brief Browser Applet
*/

#pragma once

/**
* @brief Open the browser at a url
* @param url The url to open at, max-length 1024 characters including the trailing zero. If invalid or null, just opens the browser.
*/
void browserOpenUrl(const char* url);
21 changes: 21 additions & 0 deletions libctru/source/applets/browser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <3ds/types.h>
#include <3ds/services/apt.h>

#include <3ds/applets/browser.h>

#include <stdlib.h>
#include <string.h>

void browserOpenUrl(const char* url)
{
size_t url_len = url ? (strlen(url) + 1) : 0;
// check that we passed a url, it isn't too long and not too short (needs at least "http://")
// if that is not the case, we just claim our buffer was 0 in size
if (url_len > 0x400 || url_len < 8) url_len = 0;
// Something (aptLaunchSystemApplet? webbrowser?) tries to write / trashes the buffer.
// So, we copy the url onto the heap so that all still works out and our original argument remains const
void* buffer = malloc(url_len);
if (buffer) memcpy(buffer, url, url_len);
aptLaunchSystemApplet(APPID_WEB, buffer, url_len, 0);
if (buffer) free(buffer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the browser applet return anything useful in the buffer? Is it worth trying to send that back to the app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find any evidence of that / currently nothing is known, as far as soru is aware

}