Skip to content

Commit 78dcba7

Browse files
committed
feat: Add browser applet
1 parent ff76c84 commit 78dcba7

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

libctru/include/3ds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extern "C" {
9292

9393
#include <3ds/applets/swkbd.h>
9494
#include <3ds/applets/error.h>
95-
95+
#include <3ds/applets/browser.h>
9696
#include <3ds/applets/miiselector.h>
9797

9898
#include <3ds/archive.h>

libctru/include/3ds/applets/browser.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @file browser.h
3+
* @brief Browser Applet
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @brief Open the browser at a url
10+
* @param url The url to open at, max-length 1024 characters including the trailing zero. If invalid or null, just opens the browser.
11+
*/
12+
void browserOpenUrl(const char* url);

libctru/source/applets/browser.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <3ds/types.h>
2+
#include <3ds/services/apt.h>
3+
4+
#include <3ds/applets/browser.h>
5+
6+
#include <stdlib.h>
7+
#include <string.h>
8+
9+
void browserOpenUrl(const char* url)
10+
{
11+
size_t url_len = url ? (strlen(url) + 1) : 0;
12+
// check that we passed a url, it isn't too long and not too short (needs at least "http://")
13+
// if that is not the case, we just claim our buffer was 0 in size
14+
if (url_len > 0x400 || url_len < 8) url_len = 0;
15+
// Something (aptLaunchSystemApplet? webbrowser?) tries to write / trashes the buffer.
16+
// So, we copy the url onto the heap so that all still works out and our original argument remains const
17+
void* buffer = malloc(url_len);
18+
if (buffer) memcpy(buffer, url, url_len);
19+
aptLaunchSystemApplet(APPID_WEB, buffer, url_len, 0);
20+
if (buffer) free(buffer);
21+
}

0 commit comments

Comments
 (0)